Module: Spree::Payment::Processing
- Included in:
- Spree::Payment
- Defined in:
- app/models/spree/payment/processing.rb
Instance Method Summary collapse
- #authorize! ⇒ Object
- #cancel! ⇒ Object
- #capture! ⇒ Object
- #credit!(credit_amount = nil) ⇒ Object
- #gateway_options ⇒ Object
- #partial_credit(amount) ⇒ Object
- #process! ⇒ Object
- #purchase! ⇒ Object
- #void_transaction! ⇒ Object
Instance Method Details
#authorize! ⇒ Object
25 26 27 28 |
# File 'app/models/spree/payment/processing.rb', line 25 def started_processing! gateway_action(source, :authorize, :pend) end |
#cancel! ⇒ Object
109 110 111 112 113 114 115 |
# File 'app/models/spree/payment/processing.rb', line 109 def cancel! if payment_method.respond_to?(:cancel) payment_method.cancel(response_code) else credit! end 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, ) else # Standard ActiveMerchant capture usage response = payment_method.capture(money.money.cents, response_code, ) end handle_response(response, :complete, :failure) end end |
#credit!(credit_amount = nil) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/models/spree/payment/processing.rb', line 80 def credit!(credit_amount=nil) protect_from_connection_error do check_environment credit_amount ||= credit_allowed >= order.outstanding_balance.abs ? order.outstanding_balance.abs : credit_allowed.abs credit_amount = credit_amount.to_f credit_cents = Spree::Money.new(credit_amount, currency: currency).money.cents if payment_method.payment_profiles_supported? response = payment_method.credit(credit_cents, source, response_code, ) else response = payment_method.credit(credit_cents, response_code, ) end record_response(response) if response.success? self.class.create({ :order => order, :source => self, :payment_method => payment_method, :amount => credit_amount.abs * -1, :response_code => response., :state => 'completed' }, :without_protection => true) else gateway_error(response) end end end |
#gateway_options ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'app/models/spree/payment/processing.rb', line 123 def = { :email => order.email, :customer => order.email, :ip => order.last_ip_address, # Need to pass in a unique identifier here to make some # payment gateways happy. # # For more information, please see Spree::Payment#set_unique_identifier :order_id => gateway_order_id } .merge!({ :shipping => order.ship_total * 100, :tax => order.tax_total * 100, :subtotal => order.item_total * 100, :discount => order.promo_total * 100, :currency => currency }) .merge!({ :billing_address => order.bill_address.try(:active_merchant_hash), :shipping_address => order.ship_address.try(:active_merchant_hash) }) end |
#partial_credit(amount) ⇒ Object
117 118 119 120 121 |
# File 'app/models/spree/payment/processing.rb', line 117 def partial_credit(amount) return if amount > credit_allowed started_processing! credit!(amount) 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 end else invalidate! raise Core::GatewayError.new(Spree.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, ) else # Standard ActiveMerchant void usage response = payment_method.void(self.response_code, ) end record_response(response) if response.success? self.response_code = response. self.void else gateway_error(response) end end end |