Sha256: d76bea482defdf0e2c70387cd83cf67d546ea7429fb4c6cd01bc8b02d1d72104

Contents?: true

Size: 1.11 KB

Versions: 6

Compression:

Stored size: 1.11 KB

Contents

module Workarea
  class Payment
    module Authorize
      class GiftCard
        include OperationImplementation

        def complete!
          Payment::GiftCard.purchase(tender.number, transaction.amount.cents)

          transaction.response = ActiveMerchant::Billing::Response.new(
            true,
            I18n.t(
              'workarea.gift_cards.debit',
              amount: transaction.amount,
              number: tender.number
            )
          )

        rescue Payment::InsufficientFunds
          transaction.response = ActiveMerchant::Billing::Response.new(
            false,
            I18n.t('workarea.gift_cards.insufficient_funds')
          )
        end

        def cancel!
          return unless transaction.success?

          Payment::GiftCard.refund(tender.number, transaction.amount.cents)

          transaction.cancellation = ActiveMerchant::Billing::Response.new(
            true,
            I18n.t(
              'workarea.gift_cards.credit',
              amount: transaction.amount,
              number: tender.number
            )
          )
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
workarea-gift_cards-3.4.11 app/models/workarea/payment/authorize/gift_card.rb
workarea-gift_cards-3.4.10 app/models/workarea/payment/authorize/gift_card.rb
workarea-gift_cards-3.4.9 app/models/workarea/payment/authorize/gift_card.rb
workarea-gift_cards-3.4.8 app/models/workarea/payment/authorize/gift_card.rb
workarea-gift_cards-3.4.7 app/models/workarea/payment/authorize/gift_card.rb
workarea-gift_cards-3.4.6 app/models/workarea/payment/authorize/gift_card.rb