Module: Spree::Payment::Processing

Included in:
Spree::Payment
Defined in:
app/models/spree/payment/processing.rb

Instance Method Summary collapse

Instance Method Details

#authorize!Object



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

def authorize!
  started_processing!
  gateway_action(source, :authorize, :pend)
end

#capture!Object



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

def capture!
  return true if completed?
  started_processing!
  protect_from_connection_error do
    check_environment

    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.capture(self, source, gateway_options)
    else
      # Standard ActiveMerchant capture usage
      response = payment_method.capture(money.money.cents,
                                        response_code,
                                        gateway_options)
    end

    handle_response(response, :complete, :failure)
  end
end

#process!Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/spree/payment/processing.rb', line 4

def process!
  if payment_method && payment_method.source_required?
    if source
      if !processing?
        if payment_method.supports?(source)
          if payment_method.auto_capture?
            purchase!
          else
            authorize!
          end
        else
          invalidate!
          raise Core::GatewayError.new(I18n.t(:payment_method_not_supported))
        end
      end
    else
      raise Core::GatewayError.new(Spree.t(:payment_processing_failed))
    end
  end
end

#purchase!Object



30
31
32
33
# File 'app/models/spree/payment/processing.rb', line 30

def purchase!
  started_processing!
  gateway_action(source, :purchase, :complete)
end

#void_transaction!Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/models/spree/payment/processing.rb', line 56

def void_transaction!
  return true if void?
  protect_from_connection_error do
    check_environment

    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(self.response_code, source, gateway_options)
    else
      # Standard ActiveMerchant void usage
      response = payment_method.void(self.response_code, gateway_options)
    end
    record_response(response)

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