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
23 24 25 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 23 def (amount, creditcard, ) create_transaction(amount, creditcard, :auth_only, ()) end |
#cancel(response_code) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 45 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
32 33 34 35 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 32 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.
60 61 62 63 64 65 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 60 def create_profile(payment) if payment.source.gateway_customer_profile_id.nil? profile_hash = create_customer_profile(payment) payment.source.update_attributes(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
37 38 39 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 37 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.
80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 80 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.
68 69 70 71 72 73 74 75 76 77 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 68 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
12 13 14 15 16 17 18 19 20 21 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 12 def # add :test key in the options hash, as that is what the ActiveMerchant::Billing::AuthorizeNetGateway expects if self.preferred_test_mode self.preferences[:test] = true else self.preferences.delete(:test) end super end |
#payment_profiles_supported? ⇒ Boolean
55 56 57 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 55 def payment_profiles_supported? true end |
#provider_class ⇒ Object
8 9 10 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 8 def provider_class self.class end |
#purchase(amount, creditcard, gateway_options) ⇒ Object
27 28 29 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 27 def purchase(amount, creditcard, ) create_transaction(amount, creditcard, :auth_capture, ()) end |
#update_payment_profile(payment) ⇒ Object
Update billing address on the CIM payment profile
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 93 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
41 42 43 |
# File 'app/models/spree/gateway/authorize_net_cim.rb', line 41 def void(response_code, creditcard, = {}) create_transaction(nil, creditcard, :void, ().merge(trans_id: response_code)) end |