Class: AbtainBilling::Billing::AuthorizeNetGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/abtain_billing/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

  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

Constant Summary collapse

API_VERSION =
'3.1'
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'
}

Constants inherited from Gateway

Gateway::DEBIT_CARDS

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, inherited, supports?, #test?

Methods included from Utils

generate_unique_id

Methods included from CreditCardFormatting

#format

Methods included from RequiresParameters

#requires!

Methods included from PostsData

included, #ssl_get, #ssl_post

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)

  • :testtrue or false. If true, perform transactions against the test server. Otherwise, perform transactions against the production server.



73
74
75
76
77
# File 'lib/abtain_billing/billing/gateways/authorize_net.rb', line 73

def initialize(options = {})
  requires!(options, :login, :password)
  @options = 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. Either an Integer value in cents or a Money object.

  • 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/abtain_billing/billing/gateways/authorize_net.rb', line 87

def authorize(money, creditcard, options = {})
  post = {}
  add_invoice(post, options)
  add_creditcard(post, creditcard)
  add_address(post, options)
  add_customer_data(post, options)
  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 the subscription_id of the recurring payment already in place for a given credit card. (REQUIRED)



227
228
229
230
# File 'lib/abtain_billing/billing/gateways/authorize_net.rb', line 227

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. Either an Integer value in cents or a Money object.

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



122
123
124
125
126
# File 'lib/abtain_billing/billing/gateways/authorize_net.rb', line 122

def capture(money, authorization, options = {})
  post = {:trans_id => authorization}
  add_customer_data(post, options)
  commit('PRIOR_AUTH_CAPTURE', money, post)
end

#credit(money, identification, options = {}) ⇒ Object

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. Either an Integer value in cents or a Money object.

  • 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)



152
153
154
155
156
157
158
159
160
161
# File 'lib/abtain_billing/billing/gateways/authorize_net.rb', line 152

def credit(money, identification, options = {})
  requires!(options, :card_number)

  post = { :trans_id => identification,
           :card_num => options[:card_number]
         }
  add_invoice(post, options)

  commit('CREDIT', money, post)
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. Either an Integer value in cents or a Money object.

  • 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/abtain_billing/billing/gateways/authorize_net.rb', line 105

def purchase(money, creditcard, options = {})
  post = {}
  add_invoice(post, options)
  add_creditcard(post, creditcard)
  add_address(post, options)
  add_customer_data(post, options)
  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. Either an Integer value in cents or a Money object.

  • 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)



184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/abtain_billing/billing/gateways/authorize_net.rb', line 184

def recurring(money, creditcard, options={})
  requires!(options, :interval, :duration, :billing_address)
  requires!(options[:interval], :length, [:unit, :days, :months])
  requires!(options[:duration], :start_date, :occurrences)
  requires!(options[:billing_address], :first_name, :last_name)

  options[:credit_card] = creditcard
  options[:amount] = money

  request = build_recurring_request(:create, options)
  recurring_commit(:create, 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)



212
213
214
215
216
# File 'lib/abtain_billing/billing/gateways/authorize_net.rb', line 212

def update_recurring(options={})
  requires!(options, :subscription_id)
  request = build_recurring_request(:update, options)
  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
# File 'lib/abtain_billing/billing/gateways/authorize_net.rb', line 133

def void(authorization, options = {})
  post = {:trans_id => authorization}
  commit('VOID', nil, post)
end