Class: ActiveMerchant::Billing::AuthorizeNetGateway
- Inherits:
-
Gateway
- Object
- Gateway
- ActiveMerchant::Billing::AuthorizeNetGateway
show all
- Includes:
- Empty
- Defined in:
- lib/active_merchant/billing/gateways/authorize_net.rb
Constant Summary
collapse
- STANDARD_AVS_CODE_MAPPING =
Authorize.net has slightly different definitions for returned AVS codes that have been mapped to the closest equivalent AM standard AVSResult codes Authorize.net’s descriptions noted below
{
'A' => 'A', 'B' => 'I', 'E' => 'E', 'G' => 'G', 'N' => 'N', 'P' => 'I', 'R' => 'R', 'S' => 'S', 'U' => 'U', 'W' => 'W', 'X' => 'X', 'Y' => 'Y', 'Z' => 'Z' }
- STANDARD_ERROR_CODE_MAPPING =
{
'2127' => STANDARD_ERROR_CODE[:incorrect_address],
'22' => STANDARD_ERROR_CODE[:card_declined],
'227' => STANDARD_ERROR_CODE[:incorrect_address],
'23' => STANDARD_ERROR_CODE[:card_declined],
'2315' => STANDARD_ERROR_CODE[:invalid_number],
'2316' => STANDARD_ERROR_CODE[:invalid_expiry_date],
'2317' => STANDARD_ERROR_CODE[:expired_card],
'235' => STANDARD_ERROR_CODE[:processing_error],
'237' => STANDARD_ERROR_CODE[:invalid_number],
'24' => STANDARD_ERROR_CODE[:pickup_card],
'244' => STANDARD_ERROR_CODE[:incorrect_cvc],
'300' => STANDARD_ERROR_CODE[:config_error],
'3153' => STANDARD_ERROR_CODE[:processing_error],
'3155' => STANDARD_ERROR_CODE[:unsupported_feature],
'36' => STANDARD_ERROR_CODE[:incorrect_number],
'37' => STANDARD_ERROR_CODE[:invalid_expiry_date],
'378' => STANDARD_ERROR_CODE[:invalid_cvc],
'38' => STANDARD_ERROR_CODE[:expired_card],
'384' => STANDARD_ERROR_CODE[:config_error]
}
- MARKET_TYPE =
{
moto: '1',
retail: '2'
}
- DEVICE_TYPE =
{
unknown: '1',
unattended_terminal: '2',
self_service_terminal: '3',
electronic_cash_register: '4',
personal_computer_terminal: '5',
airpay: '6',
wireless_pos: '7',
website: '8',
dial_terminal: '9',
virtual_terminal: '10'
}
- TRANSACTION_ALREADY_ACTIONED =
%w(310 311)
- CARD_CODE_ERRORS =
%w(N S)
- AVS_ERRORS =
%w(A E I N R W Z)
- AVS_REASON_CODES =
%w(27 45)
- TRACKS =
{
1 => /^%(?<format_code>.)(?<pan>\d{1,19}+)\^(?<name>.{2,26})\^(?<expiration>\d{0,4}|\^)(?<service_code>\d{0,3}|\^)(?<discretionary_data>.*)\?\Z/,
2 => /\A;(?<pan>\d{1,19}+)=(?<expiration>\d{0,4}|=)(?<service_code>\d{0,3}|=)(?<discretionary_data>.*)\?\Z/
}.freeze
- PAYMENT_METHOD_NOT_SUPPORTED_ERROR =
'155'
- INELIGIBLE_FOR_ISSUING_CREDIT_ERROR =
'54'
Constants inherited
from Gateway
Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE
Instance Attribute Summary
Attributes inherited from Gateway
#options
Instance Method Summary
collapse
-
#amount_for_verify(options) ⇒ Object
-
#authorize(amount, payment, options = {}) ⇒ Object
-
#capture(amount, authorization, options = {}) ⇒ Object
-
#credit(amount, payment, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ AuthorizeNetGateway
constructor
A new instance of AuthorizeNetGateway.
-
#purchase(amount, payment, options = {}) ⇒ Object
-
#refund(amount, authorization, options = {}) ⇒ Object
-
#scrub(transcript) ⇒ Object
-
#store(credit_card, options = {}) ⇒ Object
-
#supports_network_tokenization? ⇒ Boolean
-
#supports_scrubbing? ⇒ Boolean
-
#unstore(authorization) ⇒ Object
-
#validate_billing_address_values?(options) ⇒ Boolean
-
#verify(payment_method, options = {}) ⇒ Object
-
#verify_credentials ⇒ Object
-
#void(authorization, options = {}) ⇒ Object
Methods inherited from Gateway
#add_field_to_post_if_present, #add_fields_to_post_if_present, #card_brand, card_brand, #generate_unique_id, inherited, #supported_countries, supported_countries, supported_countries=, supports?, #test?
#expdate, #format, #strftime_yyyymm
Methods included from PostsData
included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request
Constructor Details
Returns a new instance of AuthorizeNetGateway.
95
96
97
98
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 95
def initialize(options = {})
requires!(options, :login, :password)
super
end
|
Instance Method Details
#amount_for_verify(options) ⇒ Object
188
189
190
191
192
193
194
195
196
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 188
def amount_for_verify(options)
return 100 unless options[:verify_amount].present?
amount = options[:verify_amount]
raise ArgumentError.new 'verify_amount value must be an integer' unless amount.is_a?(Integer) && !amount.negative? || amount.is_a?(String) && amount.match?(/^\d+$/) && !amount.to_i.negative?
raise ArgumentError.new 'Billing address including zip code is required for a 0 amount verify' if amount.to_i.zero? && !validate_billing_address_values?(options)
amount.to_i
end
|
#authorize(amount, payment, options = {}) ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 112
def authorize(amount, payment, options = {})
if payment.is_a?(String)
commit(:cim_authorize, options) do |xml|
add_cim_auth_purchase(xml, 'profileTransAuthOnly', amount, payment, options)
end
else
commit(:authorize) do |xml|
add_auth_purchase(xml, 'authOnlyTransaction', amount, payment, options)
end
end
end
|
#capture(amount, authorization, options = {}) ⇒ Object
124
125
126
127
128
129
130
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 124
def capture(amount, authorization, options = {})
if auth_was_for_cim?(authorization)
cim_capture(amount, authorization, options)
else
normal_capture(amount, authorization, options)
end
end
|
#credit(amount, payment, options = {}) ⇒ Object
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 158
def credit(amount, payment, options = {})
raise ArgumentError, 'Reference credits are not supported. Please supply the original credit card or use the #refund method.' if payment.is_a?(String)
commit(:credit) do |xml|
add_order_id(xml, options)
xml.transactionRequest do
xml.transactionType('refundTransaction')
xml.amount(amount(amount))
add_payment_method(xml, payment, options, :credit)
xml.refTransId(transaction_id_from(options[:transaction_id])) if options[:transaction_id]
add_invoice(xml, 'refundTransaction', options)
add_customer_data(xml, payment, options)
add_settings(xml, payment, options)
add_user_fields(xml, amount, options)
end
end
end
|
#purchase(amount, payment, options = {}) ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 100
def purchase(amount, payment, options = {})
if payment.is_a?(String)
commit(:cim_purchase, options) do |xml|
add_cim_auth_purchase(xml, 'profileTransAuthCapture', amount, payment, options)
end
else
commit(:purchase) do |xml|
add_auth_purchase(xml, 'authCaptureTransaction', amount, payment, options)
end
end
end
|
#refund(amount, authorization, options = {}) ⇒ Object
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 132
def refund(amount, authorization, options = {})
response =
if auth_was_for_cim?(authorization)
cim_refund(amount, authorization, options)
else
normal_refund(amount, authorization, options)
end
return response if response.success?
return response unless options[:force_full_refund_if_unsettled]
if response.params['response_reason_code'] == INELIGIBLE_FOR_ISSUING_CREDIT_ERROR
void(authorization, options)
else
response
end
end
|
#scrub(transcript) ⇒ Object
225
226
227
228
229
230
231
232
233
234
235
236
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 225
def scrub(transcript)
transcript.
gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
gsub(%r((<transactionKey>).+(</transactionKey>)), '\1[FILTERED]\2').
gsub(%r((<cardNumber>).+(</cardNumber>)), '\1[FILTERED]\2').
gsub(%r((<cardCode>).+(</cardCode>)), '\1[FILTERED]\2').
gsub(%r((<track1>).+(</track1>)), '\1[FILTERED]\2').
gsub(%r((<track2>).+(</track2>)), '\1[FILTERED]\2').
gsub(/(<routingNumber>).+(<\/routingNumber>)/, '\1[FILTERED]\2').
gsub(/(<accountNumber>).+(<\/accountNumber>)/, '\1[FILTERED]\2').
gsub(%r((<cryptogram>).+(</cryptogram>)), '\1[FILTERED]\2')
end
|
#store(credit_card, options = {}) ⇒ Object
202
203
204
205
206
207
208
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 202
def store(credit_card, options = {})
if options[:customer_profile_id]
create_customer_payment_profile(credit_card, options)
else
create_customer_profile(credit_card, options)
end
end
|
#supports_network_tokenization? ⇒ Boolean
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 238
def supports_network_tokenization?
card = Billing::NetworkTokenizationCreditCard.new({
number: '4111111111111111',
month: 12,
year: 20,
first_name: 'John',
last_name: 'Smith',
brand: 'visa',
payment_cryptogram: 'EHuWW9PiBkWvqE5juRwDzAUFBAk='
})
request = post_data(:authorize) do |xml|
add_auth_purchase(xml, 'authOnlyTransaction', 1, card, {})
end
raw_response = ssl_post(url, request, )
response = parse(:authorize, raw_response)
response[:response_reason_code].to_s != PAYMENT_METHOD_NOT_SUPPORTED_ERROR
end
|
#supports_scrubbing? ⇒ Boolean
221
222
223
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 221
def supports_scrubbing?
true
end
|
#unstore(authorization) ⇒ Object
210
211
212
213
214
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 210
def unstore(authorization)
customer_profile_id, = split_authorization(authorization)
delete_customer_profile(customer_profile_id)
end
|
#validate_billing_address_values?(options) ⇒ Boolean
198
199
200
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 198
def validate_billing_address_values?(options)
options.dig(:billing_address, :zip).present? && options.dig(:billing_address, :address1).present?
end
|
#verify(payment_method, options = {}) ⇒ Object
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 177
def verify(payment_method, options = {})
amount = amount_for_verify(options)
MultiResponse.run(:use_first_response) do |r|
r.process { authorize(amount, payment_method, options) }
r.process(:ignore_result) { void(r.authorization, options) } unless amount == 0
end
rescue ArgumentError => e
Response.new(false, e.message)
end
|
#verify_credentials ⇒ Object
216
217
218
219
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 216
def verify_credentials
response = commit(:verify_credentials) {}
response.success?
end
|
#void(authorization, options = {}) ⇒ Object
150
151
152
153
154
155
156
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 150
def void(authorization, options = {})
if auth_was_for_cim?(authorization)
cim_void(authorization, options)
else
normal_void(authorization, options)
end
end
|