Class: ActiveMerchant::Billing::AuthorizeNetGateway
- Defined in:
- lib/active_merchant/billing/gateways/authorize_net.rb
Overview
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.
How to Get Your API Login ID and Transaction Key
-
Log into the Merchant Interface
-
Select Settings from the Main Menu
-
Click on API Login ID and Transaction Key in the Security section
-
Type in the answer to the secret question configured on setup
-
Click Submit
Automated Recurring Billing (ARB)
Automated Recurring Billing (ARB) is an optional service for submitting and managing recurring, or subscription-based, transactions.
To use recurring, update_recurring, cancel_recurring and status_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
Direct Known Subclasses
Constant Summary collapse
- API_VERSION =
'3.1'
- CARD_CODE_ERRORS =
%w( N S )
- AVS_ERRORS =
%w( A E N R W Z )
- AVS_REASON_CODES =
%w(27 45)
- AUTHORIZE_NET_ARB_NAMESPACE =
'AnetApi/xml/v1/schema/AnetApiSchema.xsd'
- RECURRING_ACTIONS =
{ :create => 'ARBCreateSubscription', :update => 'ARBUpdateSubscription', :cancel => 'ARBCancelSubscription', :status => 'ARBGetSubscriptionStatus' }
Constants inherited from Gateway
Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS
Instance Attribute Summary
Attributes inherited from Gateway
Instance Method Summary collapse
-
#authorize(money, creditcard, options = {}) ⇒ Object
Performs an authorization, which reserves the funds on the customer’s credit card, but does not charge the card.
-
#cancel_recurring(subscription_id) ⇒ Object
Cancel a recurring payment.
-
#capture(money, authorization, options = {}) ⇒ Object
Captures the funds from an authorized transaction.
- #credit(money, identification, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ AuthorizeNetGateway
constructor
Creates a new AuthorizeNetGateway.
-
#purchase(money, creditcard, options = {}) ⇒ Object
Perform a purchase, which is essentially an authorization and capture in a single operation.
-
#recurring(money, creditcard, options = {}) ⇒ Object
Create a recurring payment.
-
#refund(money, identification, options = {}) ⇒ Object
Refund a transaction.
-
#status_recurring(subscription_id) ⇒ Object
Get Subscription Status of a recurring payment.
-
#update_recurring(options = {}) ⇒ Object
Update a recurring payment’s details.
-
#void(authorization, options = {}) ⇒ Object
Void a previous transaction.
Methods inherited from Gateway
#card_brand, card_brand, inherited, supports?, #test?
Methods included from CreditCardFormatting
Constructor Details
#initialize(options = {}) ⇒ AuthorizeNetGateway
Creates a new AuthorizeNetGateway
The gateway requires that a valid login and password be passed in the options
hash.
Options
-
:login
– The Authorize.Net API Login ID (REQUIRED) -
:password
– The Authorize.Net Transaction Key. (REQUIRED) -
:test
–true
orfalse
. If true, perform transactions against the test server. Otherwise, perform transactions against the production server.
73 74 75 76 77 |
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 73 def initialize( = {}) requires!(, :login, :password) @options = super end |
Instance Method Details
#authorize(money, creditcard, options = {}) ⇒ Object
Performs an authorization, which reserves the funds on the customer’s credit card, but does not charge the card.
Parameters
-
money
– The amount to be authorized as an Integer value in cents. -
creditcard
– The CreditCard details for the transaction. -
options
– A hash of optional parameters.
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 87 def (money, creditcard, = {}) post = {} add_invoice(post, ) add_creditcard(post, creditcard) add_address(post, ) add_customer_data(post, ) add_duplicate_window(post) commit('AUTH_ONLY', money, post) end |
#cancel_recurring(subscription_id) ⇒ Object
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()
Parameters
-
subscription_id
– A string containing thesubscription_id
of the recurring payment already in place for a given credit card. (REQUIRED)
241 242 243 244 |
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 241 def cancel_recurring(subscription_id) request = build_recurring_request(:cancel, :subscription_id => subscription_id) recurring_commit(:cancel, request) end |
#capture(money, authorization, options = {}) ⇒ Object
Captures the funds from an authorized transaction.
Parameters
-
money
– The amount to be captured as an Integer value in cents. -
authorization
– The authorization returned from the previous authorize request.
122 123 124 125 126 |
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 122 def capture(money, , = {}) post = {:trans_id => } add_customer_data(post, ) commit('PRIOR_AUTH_CAPTURE', money, post) end |
#credit(money, identification, options = {}) ⇒ Object
173 174 175 176 |
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 173 def credit(money, identification, = {}) deprecated CREDIT_DEPRECATION_MESSAGE refund(money, identification, ) end |
#purchase(money, creditcard, options = {}) ⇒ Object
Perform a purchase, which is essentially an authorization and capture in a single operation.
Parameters
-
money
– The amount to be purchased as an Integer value in cents. -
creditcard
– The CreditCard details for the transaction. -
options
– A hash of optional parameters.
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 105 def purchase(money, creditcard, = {}) post = {} add_invoice(post, ) add_creditcard(post, creditcard) add_address(post, ) add_customer_data(post, ) add_duplicate_window(post) commit('AUTH_CAPTURE', money, post) end |
#recurring(money, creditcard, options = {}) ⇒ Object
Create a recurring payment.
This transaction creates a new Automated Recurring Billing (ARB) subscription. Your account must have ARB enabled.
Parameters
-
money
– The amount to be charged to the customer at each interval as an Integer value in cents. -
creditcard
– The CreditCard details for the transaction. -
options
– A hash of parameters.
Options
-
:interval
– A hash containing information about the interval of time between payments. Must contain the keys:length
and:unit
.:unit
can be either:months
or:days
. If:unit
is:months
then:length
must be an integer between 1 and 12 inclusive. If:unit
is:days
then:length
must be an integer between 7 and 365 inclusive. For example, to charge the customer once every three months the hash would be :interval => { :unit => :months, :length => 3 } (REQUIRED) -
:duration
– A hash containing keys for the:start_date
the subscription begins (also the date the initial billing occurs) and the total number of billing:occurences
or payments for the subscription. (REQUIRED)
198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 198 def recurring(money, creditcard, ={}) requires!(, :interval, :duration, :billing_address) requires!([:interval], :length, [:unit, :days, :months]) requires!([:duration], :start_date, :occurrences) requires!([:billing_address], :first_name, :last_name) [:credit_card] = creditcard [:amount] = money request = build_recurring_request(:create, ) recurring_commit(:create, request) end |
#refund(money, identification, options = {}) ⇒ Object
Refund a transaction.
This transaction indicates to the gateway that money should flow from the merchant to the customer.
Parameters
-
money
– The amount to be credited to the customer as an Integer value in cents. -
identification
– The ID of the original transaction against which the refund is being issued. -
options
– A hash of parameters.
Options
-
:card_number
– The credit card number the refund is being issued to. (REQUIRED) -
:first_name
– The first name of the account being refunded. -
:last_name
– The last name of the account being refunded. -
:zip
– The postal code of the account being refunded.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 156 def refund(money, identification, = {}) requires!(, :card_number) post = { :trans_id => identification, :card_num => [:card_number] } post[:first_name] = [:first_name] if [:first_name] post[:last_name] = [:last_name] if [:last_name] post[:zip] = [:zip] if [:zip] add_invoice(post, ) add_duplicate_window(post) commit('CREDIT', money, post) end |
#status_recurring(subscription_id) ⇒ Object
Get Subscription Status of a recurring payment.
This transaction gets the status of an existing Automated Recurring Billing (ARB) subscription. Your account must have ARB enabled.
Parameters
-
subscription_id
– A string containing thesubscription_id
of the recurring payment already in place for a given credit card. (REQUIRED)
254 255 256 257 |
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 254 def status_recurring(subscription_id) request = build_recurring_request(:status, :subscription_id => subscription_id) recurring_commit(:status, request) end |
#update_recurring(options = {}) ⇒ Object
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.
Parameters
-
options
– A hash of parameters.
Options
-
:subscription_id
– A string containing the:subscription_id
of the recurring payment already in place for a given credit card. (REQUIRED)
226 227 228 229 230 |
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 226 def update_recurring(={}) requires!(, :subscription_id) request = build_recurring_request(:update, ) recurring_commit(:update, request) end |
#void(authorization, options = {}) ⇒ Object
Void a previous transaction
Parameters
-
authorization
- The authorization returned from the previous authorize request.
133 134 135 136 137 |
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 133 def void(, = {}) post = {:trans_id => } add_duplicate_window(post) commit('VOID', nil, post) end |