| Class | ActiveMerchant::Billing::AuthorizeNetGateway |
| In: |
lib/active_merchant/billing/gateways/authorize_net.rb
|
| Parent: | Gateway |
For more information on the Authorize.Net Gateway please visit their Integration Center
The login and password are not the username and password you use to login to the Authorize.Net Merchant Interface. Instead, you will use the API Login ID as the login and Transaction Key as the password.
Automated Recurring Billing (ARB) is an optional service for submitting and managing recurring, or subscription-based, transactions.
To use recurring, update_recurring, and cancel_recurring ARB must be enabled for your account.
Information about ARB is available on the Authorize.Net website. Information about the ARB API is available at the Authorize.Net Integration Center
| API_VERSION | = | '3.1' |
| FRAUD_REVIEW | = | 1, 2, 3, 4 |
| RESPONSE_REASON_TEXT | = | 0, 2, 3 |
| CARD_CODE_RESPONSE_CODE | = | 5, 6, 38 |
| CARD_CODE_ERRORS | = | %w( N S ) |
| AVS_ERRORS | = | %w( A E N R W Z ) |
| AUTHORIZE_NET_ARB_NAMESPACE | = | 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' |
| RECURRING_ACTIONS | = | { :create => 'ARBCreateSubscription', :update => 'ARBUpdateSubscription', :cancel => 'ARBCancelSubscription' |
Creates a new AuthorizeNetGateway
The gateway requires that a valid login and password be passed in the options hash.
# File lib/active_merchant/billing/gateways/authorize_net.rb, line 69
69: def initialize(options = {})
70: requires!(options, :login, :password)
71: @options = options
72: super
73: end
Performs an authorization, which reserves the funds on the customer‘s credit card, but does not charge the card.
# File lib/active_merchant/billing/gateways/authorize_net.rb, line 83
83: def authorize(money, creditcard, options = {})
84: post = {}
85: add_invoice(post, options)
86: add_creditcard(post, creditcard)
87: add_address(post, options)
88: add_customer_data(post, options)
89:
90: commit('AUTH_ONLY', money, post)
91: end
Cancel a recurring payment.
This transaction cancels an existing Automated Recurring Billing (ARB) subscription. Your account must have ARB enabled and the subscription must have already been created previously by calling recurring()
# File lib/active_merchant/billing/gateways/authorize_net.rb, line 221
221: def cancel_recurring(subscription_id)
222: request = build_recurring_request(:cancel, :subscription_id => subscription_id)
223: recurring_commit(:cancel, request)
224: end
Captures the funds from an authorized transaction.
# File lib/active_merchant/billing/gateways/authorize_net.rb, line 116
116: def capture(money, authorization, options = {})
117: post = {:trans_id => authorization}
118: add_customer_data(post, options)
119: commit('PRIOR_AUTH_CAPTURE', money, post)
120: end
Credit an account.
This transaction is also referred to as a Refund and indicates to the gateway that money should flow from the merchant to the customer.
# File lib/active_merchant/billing/gateways/authorize_net.rb, line 146
146: def credit(money, identification, options = {})
147: requires!(options, :card_number)
148:
149: post = { :trans_id => identification,
150: :card_num => options[:card_number]
151: }
152: add_invoice(post, options)
153:
154: commit('CREDIT', money, post)
155: end
Perform a purchase, which is essentially an authorization and capture in a single operation.
# File lib/active_merchant/billing/gateways/authorize_net.rb, line 100
100: def purchase(money, creditcard, options = {})
101: post = {}
102: add_invoice(post, options)
103: add_creditcard(post, creditcard)
104: add_address(post, options)
105: add_customer_data(post, options)
106:
107: commit('AUTH_CAPTURE', money, post)
108: end
Create a recurring payment.
This transaction creates a new Automated Recurring Billing (ARB) subscription. Your account must have ARB enabled.
# File lib/active_merchant/billing/gateways/authorize_net.rb, line 178
178: def recurring(money, creditcard, options={})
179: requires!(options, :interval, :duration, :billing_address)
180: requires!(options[:interval], :length, [:unit, :days, :months])
181: requires!(options[:duration], :start_date, :occurrences)
182: requires!(options[:billing_address], :first_name, :last_name)
183:
184: options[:credit_card] = creditcard
185: options[:amount] = money
186:
187: request = build_recurring_request(:create, options)
188: recurring_commit(:create, request)
189: end
Update a recurring payment‘s details.
This transaction updates an existing Automated Recurring Billing (ARB) subscription. Your account must have ARB enabled and the subscription must have already been created previously by calling +recurring()+. The ability to change certain details about a recurring payment is dependent on transaction history and cannot be determined until after calling +update_recurring()+. See the ARB XML Guide for such conditions.
# File lib/active_merchant/billing/gateways/authorize_net.rb, line 206
206: def update_recurring(options={})
207: requires!(options, :subscription_id)
208: request = build_recurring_request(:update, options)
209: recurring_commit(:update, request)
210: end
Void a previous transaction
# File lib/active_merchant/billing/gateways/authorize_net.rb, line 127
127: def void(authorization, options = {})
128: post = {:trans_id => authorization}
129: commit('VOID', nil, post)
130: end