Class: Gateway::Affirm

Inherits:
Gateway
  • Object
show all
Defined in:
app/models/spree/gateway/affirm.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.versionObject



32
33
34
# File 'app/models/spree/gateway/affirm.rb', line 32

def self.version
  Gem::Specification.find_by_name('spree_affirm').version.to_s
end

Instance Method Details

#actionsObject



24
25
26
# File 'app/models/spree/gateway/affirm.rb', line 24

def actions
  %w{capture void credit}
end

#cancel(charge_ari) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/spree/gateway/affirm.rb', line 36

def cancel(charge_ari)
  _payment = Spree::Payment.valid.where(
    response_code: charge_ari,
    source_type:   "#{payment_source_class}"
  ).first

  return if _payment.nil?

  if _payment.pending?
    _payment.void_transaction!

  elsif _payment.completed? and _payment.can_credit?

    # create adjustment
    _payment.order.adjustments.create label: "Refund - Canceled Order", amount: -_payment.credit_allowed.to_f
    _payment.order.update!

    _payment.credit!

  end
end

#method_typeObject



20
21
22
# File 'app/models/spree/gateway/affirm.rb', line 20

def method_type
  'affirm'
end

#payment_source_classObject



12
13
14
# File 'app/models/spree/gateway/affirm.rb', line 12

def payment_source_class
  Spree::AffirmCheckout
end

#provider_classObject



8
9
10
# File 'app/models/spree/gateway/affirm.rb', line 8

def provider_class
  ActiveMerchant::Billing::Affirm
end

#source_required?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'app/models/spree/gateway/affirm.rb', line 16

def source_required?
  true
end

#supports?(source) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/models/spree/gateway/affirm.rb', line 28

def supports?(source)
  source.is_a? payment_source_class
end