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.

How to Get Your API Login ID and Transaction Key

  1. Log into the Merchant Interface
  2. Select Settings from the Main Menu
  3. Click on API Login ID and Transaction Key in the Security section
  4. Type in the answer to the secret question configured on setup
  5. 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, 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

Methods

Constants

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'

Public Class methods

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)
  • :testtrue or false. If true, perform transactions against the test server. Otherwise, perform transactions against the production server.

[Source]

    # File lib/active_merchant/billing/gateways/authorize_net.rb, line 71
71:       def initialize(options = {})
72:         requires!(options, :login, :password)
73:         @options = options
74:         super
75:       end

Public Instance methods

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.

[Source]

    # File lib/active_merchant/billing/gateways/authorize_net.rb, line 85
85:       def authorize(money, creditcard, options = {})
86:         post = {}
87:         add_invoice(post, options)
88:         add_creditcard(post, creditcard)
89:         add_address(post, options)
90:         add_customer_data(post, options)
91:         add_duplicate_window(post)
92: 
93:         commit('AUTH_ONLY', money, post)
94:       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()

Parameters

  • subscription_id — A string containing the subscription_id of the recurring payment already in place for a given credit card. (REQUIRED)

[Source]

     # File lib/active_merchant/billing/gateways/authorize_net.rb, line 224
224:       def cancel_recurring(subscription_id)
225:         request = build_recurring_request(:cancel, :subscription_id => subscription_id)
226:         recurring_commit(:cancel, request)
227:       end

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.

[Source]

     # File lib/active_merchant/billing/gateways/authorize_net.rb, line 120
120:       def capture(money, authorization, options = {})
121:         post = {:trans_id => authorization}
122:         add_customer_data(post, options)
123:         commit('PRIOR_AUTH_CAPTURE', money, post)
124:       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.

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 credit is being issued.
  • options — A hash of parameters.

Options

  • :card_number — The credit card number the credit is being issued to. (REQUIRED)

[Source]

     # File lib/active_merchant/billing/gateways/authorize_net.rb, line 150
150:       def credit(money, identification, options = {})
151:         requires!(options, :card_number)
152: 
153:         post = { :trans_id => identification,
154:                  :card_num => options[:card_number]
155:                }
156:         add_invoice(post, options)
157: 
158:         commit('CREDIT', money, post)
159:       end

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.

[Source]

     # File lib/active_merchant/billing/gateways/authorize_net.rb, line 103
103:       def purchase(money, creditcard, options = {})
104:         post = {}
105:         add_invoice(post, options)
106:         add_creditcard(post, creditcard)
107:         add_address(post, options)
108:         add_customer_data(post, options)
109:         add_duplicate_window(post)
110: 
111:         commit('AUTH_CAPTURE', money, post)
112:       end

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)

[Source]

     # File lib/active_merchant/billing/gateways/authorize_net.rb, line 181
181:       def recurring(money, creditcard, options={})
182:         requires!(options, :interval, :duration, :billing_address)
183:         requires!(options[:interval], :length, [:unit, :days, :months])
184:         requires!(options[:duration], :start_date, :occurrences)
185:         requires!(options[:billing_address], :first_name, :last_name)
186: 
187:         options[:credit_card] = creditcard
188:         options[:amount] = money
189: 
190:         request = build_recurring_request(:create, options)
191:         recurring_commit(:create, request)
192:       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.

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)

[Source]

     # File lib/active_merchant/billing/gateways/authorize_net.rb, line 209
209:       def update_recurring(options={})
210:         requires!(options, :subscription_id)
211:         request = build_recurring_request(:update, options)
212:         recurring_commit(:update, request)
213:       end

Void a previous transaction

Parameters

  • authorization - The authorization returned from the previous authorize request.

[Source]

     # File lib/active_merchant/billing/gateways/authorize_net.rb, line 131
131:       def void(authorization, options = {})
132:         post = {:trans_id => authorization}
133:         commit('VOID', nil, post)
134:       end

[Validate]