Class: Gateway::AuthorizeNetCim
- Inherits:
-
Gateway
- Object
- Gateway
- Gateway::AuthorizeNetCim
- Defined in:
- app/models/spree/gateway/authorize_net_cim.rb
Instance Method Summary collapse
- #authorize(amount, creditcard, gateway_options) ⇒ Object
- #cancel(response_code) ⇒ Object
-
#capture(amount, response_code, gateway_options) ⇒ Object
capture is only one where source is not passed in for payment profile.
-
#create_profile(payment) ⇒ Object
Create a new CIM customer profile ready to accept a payment.
- #credit(amount, creditcard, response_code, gateway_options = {}) ⇒ Object
-
#get_payment_profile(payment) ⇒ Object
Get the CIM payment profile; Needed for updates.
-
#get_profile(payment) ⇒ Object
Get the CIM payment profile; Needed for updates.
- #options ⇒ Object
- #payment_profiles_supported? ⇒ Boolean
- #provider_class ⇒ Object
- #purchase(amount, creditcard, gateway_options) ⇒ Object
-
#update_payment_profile(payment) ⇒ Object
Update billing address on the CIM payment profile.
- #void(response_code, creditcard, gateway_options = {}) ⇒ Object
Instance Method Details
#authorize(amount, creditcard, gateway_options) ⇒ Object
33 34 35 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 33 def (amount, creditcard, ) create_transaction(amount, creditcard, :auth_only, ()) end |
#cancel(response_code) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 55 def cancel(response_code) # From: http://community.developer.authorize.net/t5/The-Authorize-Net-Developer-Blog/Refunds-in-Retail-A-user-friendly-approach-using-AIM/ba-p/9848 # DD: if unsettled, void needed response = void(response_code, nil) # DD: if settled, credit/refund needed response = credit(nil, nil, response_code) unless response.success? response end |
#capture(amount, response_code, gateway_options) ⇒ Object
capture is only one where source is not passed in for payment profile
42 43 44 45 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 42 def capture(amount, response_code, ) # no credit card needed create_transaction(amount, nil, :prior_auth_capture, trans_id: response_code) end |
#create_profile(payment) ⇒ Object
Create a new CIM customer profile ready to accept a payment. Called by Spree::Payment on after_save.
70 71 72 73 74 75 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 70 def create_profile(payment) if payment.source.gateway_customer_profile_id.nil? profile_hash = create_customer_profile(payment) payment.source.update(gateway_customer_profile_id: profile_hash[:customer_profile_id], gateway_payment_profile_id: profile_hash[:customer_payment_profile_id]) end end |
#credit(amount, creditcard, response_code, gateway_options = {}) ⇒ Object
47 48 49 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 47 def credit(amount, creditcard, response_code, = {}) create_transaction(amount, creditcard, :refund, ().merge(trans_id: response_code)) end |
#get_payment_profile(payment) ⇒ Object
Get the CIM payment profile; Needed for updates.
90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 90 def get_payment_profile(payment) if payment.source.has_payment_profile? profile = cim_gateway.get_customer_payment_profile({ customer_profile_id: payment.source.gateway_customer_profile_id, customer_payment_profile_id: payment.source.gateway_payment_profile_id }) if profile profile.params['payment_profile'].deep_symbolize_keys! end end end |
#get_profile(payment) ⇒ Object
Get the CIM payment profile; Needed for updates.
78 79 80 81 82 83 84 85 86 87 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 78 def get_profile(payment) if payment.source.has_payment_profile? profile = cim_gateway.get_customer_profile({ customer_profile_id: payment.source.gateway_customer_profile_id }) if profile profile.params['profile'].deep_symbolize_keys! end end end |
#options ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 17 def if !['live','test'].include?(self.preferred_server) raise "You must set the 'server' preference in your payment method (Gateway::AuthorizeNetCim) to either 'live' or 'test'" end # add :test key in the options hash, as that is what the # ActiveMerchant::Billing::AuthorizeNetGateway expects if self.preferred_server != "live" self.preferences[:test] = true else self.preferences.delete(:test) end super end |
#payment_profiles_supported? ⇒ Boolean
65 66 67 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 65 def payment_profiles_supported? true end |
#provider_class ⇒ Object
13 14 15 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 13 def provider_class self.class end |
#purchase(amount, creditcard, gateway_options) ⇒ Object
37 38 39 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 37 def purchase(amount, creditcard, ) create_transaction(amount, creditcard, :auth_capture, ()) end |
#update_payment_profile(payment) ⇒ Object
Update billing address on the CIM payment profile
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 103 def update_payment_profile(payment) if payment.source.has_payment_profile? if hash = get_payment_profile(payment) hash[:bill_to] = generate_address_hash(payment.order.bill_address) if hash[:payment][:credit_card] # activemerchant expects a credit card object with 'number', 'year', 'month', and 'verification_value?' defined payment.source.define_singleton_method(:number) { "XXXXXXXXX#{payment.source.last_digits}" } hash[:payment][:credit_card] = payment.source end cim_gateway.update_customer_payment_profile({ customer_profile_id: payment.source.gateway_customer_profile_id, payment_profile: hash }) end end end |
#void(response_code, creditcard, gateway_options = {}) ⇒ Object
51 52 53 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 51 def void(response_code, creditcard, = {}) create_transaction(nil, creditcard, :void, ().merge(trans_id: response_code)) end |