Class: Workarea::Payment::Authorize::StoreCredit

Inherits:
Object
  • Object
show all
Includes:
OperationImplementation
Defined in:
app/models/workarea/payment/authorize/store_credit.rb

Instance Method Summary collapse

Methods included from OperationImplementation

#initialize, #validate_reference!

Instance Method Details

#cancel!Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/workarea/payment/authorize/store_credit.rb', line 27

def cancel!
  return unless transaction.success?

  profile.reload_store_credit(transaction.amount.cents)
  transaction.cancellation = ActiveMerchant::Billing::Response.new(
    true,
    I18n.t(
      'workarea.payment.store_credit_credit',
      amount: transaction.amount,
      email: profile.email
    )
  )
end

#complete!Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/workarea/payment/authorize/store_credit.rb', line 7

def complete!
  profile.purchase_on_store_credit(transaction.amount.cents)

  transaction.action = 'purchase'
  transaction.response = ActiveMerchant::Billing::Response.new(
    true,
    I18n.t(
      'workarea.payment.store_credit_debit',
      amount: transaction.amount,
      email: profile.email
    )
  )

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