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
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)
- TRANSACTION_ALREADY_ACTIONED =
%w(310 311)
Constants inherited from Gateway
Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS, Gateway::RECURRING_DEPRECATION_MESSAGE
Instance Attribute Summary
Attributes inherited from Gateway
Instance Method Summary collapse
-
#authorize(money, paysource, options = {}) ⇒ Object
Performs an authorization, which reserves the funds on the customer’s credit card, but does not charge the card.
-
#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, paysource, options = {}) ⇒ Object
Perform a purchase, which is essentially an authorization and capture in a single operation.
-
#refund(money, identification, options = {}) ⇒ Object
Refund a transaction.
- #verify(credit_card, options = {}) ⇒ Object
-
#void(authorization, options = {}) ⇒ Object
Void a previous transaction.
Methods inherited from Gateway
#card_brand, card_brand, #generate_unique_id, inherited, supported_countries, #supported_countries, supported_countries=, 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.
54 55 56 57 |
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 54 def initialize( = {}) requires!(, :login, :password) super end |
Instance Method Details
#authorize(money, paysource, 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. -
paysource
– The CreditCard or Check details for the transaction. -
options
– A hash of optional parameters.
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 67 def (money, paysource, = {}) post = {} add_currency_code(post, money, ) add_invoice(post, ) add_payment_source(post, paysource, ) add_address(post, ) add_customer_data(post, ) add_duplicate_window(post) commit('AUTH_ONLY', money, post) 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.
104 105 106 107 108 109 |
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 104 def capture(money, , = {}) post = {:trans_id => } add_customer_data(post, ) add_invoice(post, ) commit('PRIOR_AUTH_CAPTURE', money, post) end |
#credit(money, identification, options = {}) ⇒ Object
157 158 159 160 |
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 157 def credit(money, identification, = {}) ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE refund(money, identification, ) end |
#purchase(money, paysource, 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. -
paysource
– The CreditCard or Check details for the transaction. -
options
– A hash of optional parameters.
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 86 def purchase(money, paysource, = {}) post = {} add_currency_code(post, money, ) add_invoice(post, ) add_payment_source(post, paysource, ) add_address(post, ) add_customer_data(post, ) add_duplicate_window(post) commit('AUTH_CAPTURE', money, post) 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) You can either pass the last four digits of the card number or the full card number. -
: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.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 140 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 |
#verify(credit_card, options = {}) ⇒ Object
162 163 164 165 166 167 |
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 162 def verify(credit_card, = {}) MultiResponse.run(:use_first_response) do |r| r.process { (100, credit_card, ) } r.process(:ignore_result) { void(r., ) } end end |
#void(authorization, options = {}) ⇒ Object
Void a previous transaction
Parameters
-
authorization
- The authorization returned from the previous authorize request.
116 117 118 119 120 |
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 116 def void(, = {}) post = {:trans_id => } add_duplicate_window(post) commit('VOID', nil, post) end |