Class: VaultedBilling::Gateways::AuthorizeNetCim
- Inherits:
-
Object
- Object
- VaultedBilling::Gateways::AuthorizeNetCim
- Includes:
- VaultedBilling::Gateway
- Defined in:
- lib/vaulted_billing/gateways/authorize_net_cim.rb
Overview
An interface to Authorize.net’s CIM.
Instance Attribute Summary collapse
-
#use_test_uri ⇒ Object
Returns the value of attribute use_test_uri.
Instance Method Summary collapse
- #add_customer(customer) ⇒ Object
- #add_customer_credit_card(customer, credit_card, options = {}) ⇒ Object
- #authorize(customer, credit_card, amount, options = {}) ⇒ Object
- #capture(transaction_id, amount, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ AuthorizeNetCim
constructor
A new instance of AuthorizeNetCim.
- #purchase(customer, credit_card, amount, options = {}) ⇒ Object
- #refund(transaction_id, amount, options = {}) ⇒ Object
- #remove_customer(customer) ⇒ Object
- #remove_customer_credit_card(customer, credit_card) ⇒ Object
- #update_customer(customer) ⇒ Object
- #update_customer_credit_card(customer, credit_card, options = {}) ⇒ Object
- #uri ⇒ Object
- #void(transaction_id, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ AuthorizeNetCim
Returns a new instance of AuthorizeNetCim.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/vaulted_billing/gateways/authorize_net_cim.rb', line 14 def initialize( = {}) @test_uri = 'https://apitest.authorize.net/xml/v1/request.api' @live_uri = 'https://api.authorize.net/xml/v1/request.api' = .symbolize_keys! @login = [:username] || VaultedBilling.config..username @password = [:password] || VaultedBilling.config..password @raw_options = [:raw_options] || VaultedBilling.config.. @use_test_uri = .has_key?(:test) ? [:test] : (VaultedBilling.config..test_mode || VaultedBilling.config.test_mode) end |
Instance Attribute Details
#use_test_uri ⇒ Object
Returns the value of attribute use_test_uri.
12 13 14 |
# File 'lib/vaulted_billing/gateways/authorize_net_cim.rb', line 12 def use_test_uri @use_test_uri end |
Instance Method Details
#add_customer(customer) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vaulted_billing/gateways/authorize_net_cim.rb', line 25 def add_customer(customer) customer = customer.to_vaulted_billing data = build_request('createCustomerProfileRequest') do |xml| xml.tag!('profile') do xml.merchantCustomerId customer.merchant_id if customer.merchant_id xml.email customer.email if customer.email end end result = http.post(data) respond_with(customer, result, :success => result.success?) do |c| c.vault_id = result.body['createCustomerProfileResponse']['customerProfileId'] if c.success? end end |
#add_customer_credit_card(customer, credit_card, options = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/vaulted_billing/gateways/authorize_net_cim.rb', line 61 def add_customer_credit_card(customer, credit_card, = {}) customer = customer.to_vaulted_billing credit_card = credit_card.to_vaulted_billing data = build_request('createCustomerPaymentProfileRequest') { |xml| xml.customerProfileId customer.vault_id xml.paymentProfile do billing_info!(xml, customer, credit_card) credit_card_info!(xml, customer, credit_card) end } result = http.post(data) respond_with(credit_card, result, :success => result.success?) do |c| c.vault_id = result.body['createCustomerPaymentProfileResponse']['customerPaymentProfileId'] if c.success? end end |
#authorize(customer, credit_card, amount, options = {}) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/vaulted_billing/gateways/authorize_net_cim.rb', line 124 def (customer, credit_card, amount, = {}) customer = customer.to_vaulted_billing credit_card = credit_card.to_vaulted_billing data = build_request('createCustomerProfileTransactionRequest') { |xml| xml.transaction do xml.profileTransAuthOnly do xml.amount amount xml.customerProfileId customer.vault_id xml.customerPaymentProfileId credit_card.vault_id end end xml.extraOptions @raw_options.presence } result = http.post(data) respond_with(new_transaction_from_response(result.body), result, :success => result.success?) end |
#capture(transaction_id, amount, options = {}) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/vaulted_billing/gateways/authorize_net_cim.rb', line 142 def capture(transaction_id, amount, = {}) data = build_request('createCustomerProfileTransactionRequest') { |xml| xml.transaction do xml.profileTransPriorAuthCapture do xml.amount amount xml.transId transaction_id end end xml.extraOptions @raw_options.presence } result = http.post(data) respond_with(new_transaction_from_response(result.body), result, :success => result.success?) end |
#purchase(customer, credit_card, amount, options = {}) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/vaulted_billing/gateways/authorize_net_cim.rb', line 106 def purchase(customer, credit_card, amount, = {}) customer = customer.to_vaulted_billing credit_card = credit_card.to_vaulted_billing data = build_request('createCustomerProfileTransactionRequest') { |xml| xml.transaction do xml.profileTransAuthCapture do xml.amount amount xml.customerProfileId customer.vault_id xml.customerPaymentProfileId credit_card.vault_id end end xml.extraOptions @raw_options.presence } result = http.post(data) respond_with(new_transaction_from_response(result.body), result, :success => result.success?) end |
#refund(transaction_id, amount, options = {}) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/vaulted_billing/gateways/authorize_net_cim.rb', line 157 def refund(transaction_id, amount, = {}) data = build_request('createCustomerProfileTransactionRequest') { |xml| xml.transaction do xml.profileTransRefund do xml.amount amount xml.customerProfileId [:customer_vault_id] if [:customer_vault_id] xml.customerPaymentProfileId [:credit_card_vault_id] if [:credit_card_vault_id] xml.creditCardNumberMasked mask_card_number([:masked_card_number]) if [:masked_card_number] xml.transId transaction_id end end xml.extraOptions @raw_options.presence } result = http.post(data) respond_with(new_transaction_from_response(result.body), result, :success => result.success?) end |
#remove_customer(customer) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/vaulted_billing/gateways/authorize_net_cim.rb', line 51 def remove_customer(customer) customer = customer.to_vaulted_billing data = build_request('deleteCustomerProfileRequest') { |xml| xml.customerProfileId customer.vault_id } result = http.post(data) respond_with(customer, result, :success => result.success?) end |
#remove_customer_credit_card(customer, credit_card) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/vaulted_billing/gateways/authorize_net_cim.rb', line 94 def remove_customer_credit_card(customer, credit_card) customer = customer.to_vaulted_billing credit_card = credit_card.to_vaulted_billing data = build_request('deleteCustomerPaymentProfileRequest') { |xml| xml.customerProfileId customer.vault_id xml.customerPaymentProfileId credit_card.vault_id } result = http.post(data) respond_with(credit_card, result, :success => result.success?) end |
#update_customer(customer) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/vaulted_billing/gateways/authorize_net_cim.rb', line 39 def update_customer(customer) customer = customer.to_vaulted_billing data = build_request('updateCustomerProfileRequest') { |xml| xml.tag!('profile') { xml.email customer.email xml.customerProfileId customer.vault_id } } result = http.post(data) respond_with(customer, result, :success => result.success?) end |
#update_customer_credit_card(customer, credit_card, options = {}) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/vaulted_billing/gateways/authorize_net_cim.rb', line 78 def update_customer_credit_card(customer, credit_card, = {}) customer = customer.to_vaulted_billing credit_card = credit_card.to_vaulted_billing data = build_request('updateCustomerPaymentProfileRequest') { |xml| xml.customerProfileId customer.vault_id xml.paymentProfile do billing_info!(xml, customer, credit_card) credit_card_info!(xml, customer, credit_card) xml.customerPaymentProfileId credit_card.vault_id end } result = http.post(data) respond_with(credit_card, result, :success => result.success?) end |
#uri ⇒ Object
189 190 191 |
# File 'lib/vaulted_billing/gateways/authorize_net_cim.rb', line 189 def uri @use_test_uri ? @test_uri : @live_uri end |
#void(transaction_id, options = {}) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/vaulted_billing/gateways/authorize_net_cim.rb', line 175 def void(transaction_id, = {}) data = build_request('createCustomerProfileTransactionRequest') { |xml| xml.transaction do xml.profileTransVoid do xml.transId transaction_id end end xml.extraOptions @raw_options.presence } result = http.post(data) respond_with(new_transaction_from_response(result.body), result, :success => result.success?) end |