Module: Spree::Payment::Processing

Extended by:
ActiveSupport::Concern
Included in:
Spree::Payment
Defined in:
app/models/spree/payment/processing.rb

Instance Method Summary collapse

Instance Method Details

#authorize!Object



20
21
22
# File 'app/models/spree/payment/processing.rb', line 20

def authorize!
  handle_payment_preconditions { process_authorization }
end

#cancel!Object



87
88
89
90
# File 'app/models/spree/payment/processing.rb', line 87

def cancel!
  response = payment_method.cancel(response_code, self)
  handle_response(response, :void, :failure)
end

#capture!(amount = nil) ⇒ Object

Takes the amount in cents to capture. Can be used to capture partial amounts of a payment, and will create a new pending payment record for the remaining amount to capture later.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/spree/payment/processing.rb', line 45

def capture!(amount = nil)
  return true if completed?

  amount ||= money.amount_in_cents
  started_processing!
  protect_from_connection_error do
    # Standard ActiveMerchant capture usage
    response = payment_method.capture(
      amount,
      response_code,
      gateway_options
    )
    money = ::Money.new(amount, currency)
    capture_events.create!(amount: money.to_f)
    split_uncaptured_amount
    handle_response(response, :complete, :failure)
  end
end

#confirm!Object

Confirms a payment by completing it or pending it depending on the payment method’s auto_capture setting Useful for payments that are authorized/captured with SDK/Drop-in elements



31
32
33
34
35
36
37
38
39
40
# File 'app/models/spree/payment/processing.rb', line 31

def confirm!
  started_processing! if checkout?

  if payment_method&.auto_capture? && can_complete?
    complete!
    capture_events.create!(amount: amount)
  elsif can_pend?
    pend!
  end
end

#gateway_optionsObject



92
93
94
95
# File 'app/models/spree/payment/processing.rb', line 92

def gateway_options
  order.reload
  gateway_options_class.new(self).to_hash
end

#process!Object



12
13
14
15
16
17
18
# File 'app/models/spree/payment/processing.rb', line 12

def process!
  if payment_method&.auto_capture?
    purchase!
  else
    authorize!
  end
end

#purchase!Object

Captures the entire amount of a payment.



25
26
27
# File 'app/models/spree/payment/processing.rb', line 25

def purchase!
  handle_payment_preconditions { process_purchase }
end

#void_transaction!Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/models/spree/payment/processing.rb', line 64

def void_transaction!
  return true if void?

  protect_from_connection_error do
    if payment_method.payment_profiles_supported?
      # Gateways supporting payment profiles will need access to credit card object because this stores the payment profile information
      # so supply the authorization itself as well as the credit card, rather than just the authorization code
      response = payment_method.void(response_code, source, gateway_options)
    else
      # Standard ActiveMerchant void usage
      response = payment_method.void(response_code, gateway_options)
    end
    record_response(response)

    if response.success?
      self.response_code = response.authorization
      void
    else
      gateway_error(response)
    end
  end
end