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_ERROR_CODE_MAPPING =
{
'36' => STANDARD_ERROR_CODE[:incorrect_number],
'237' => STANDARD_ERROR_CODE[:invalid_number],
'2315' => STANDARD_ERROR_CODE[:invalid_number],
'37' => STANDARD_ERROR_CODE[:invalid_expiry_date],
'2316' => STANDARD_ERROR_CODE[:invalid_expiry_date],
'378' => STANDARD_ERROR_CODE[:invalid_cvc],
'38' => STANDARD_ERROR_CODE[:expired_card],
'2317' => STANDARD_ERROR_CODE[:expired_card],
'244' => STANDARD_ERROR_CODE[:incorrect_cvc],
'227' => STANDARD_ERROR_CODE[:incorrect_address],
'2127' => STANDARD_ERROR_CODE[:incorrect_address],
'22' => STANDARD_ERROR_CODE[:card_declined],
'23' => STANDARD_ERROR_CODE[:card_declined],
'3153' => STANDARD_ERROR_CODE[:processing_error],
'235' => STANDARD_ERROR_CODE[:processing_error],
'24' => STANDARD_ERROR_CODE[:pickup_card]
}
- MARKET_TYPE =
{
:moto => '1',
:retail => '2'
}
- TRANSACTION_ALREADY_ACTIONED =
%w(310 311)
- CARD_CODE_ERRORS =
%w(N S)
- AVS_ERRORS =
%w(A E 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
- APPLE_PAY_DATA_DESCRIPTOR =
"COMMON.APPLE.INAPP.PAYMENT"
- PAYMENT_METHOD_NOT_SUPPORTED_ERROR =
"155"
Constants inherited
from Gateway
Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE
Instance Attribute Summary
Attributes inherited from Gateway
#options
Instance Method Summary
collapse
-
#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
-
#verify(credit_card, options = {}) ⇒ Object
-
#void(authorization, options = {}) ⇒ Object
Methods inherited from Gateway
#card_brand, card_brand, #generate_unique_id, inherited, non_fractional_currency?, #supported_countries, supported_countries, supported_countries=, supports?, #test?
#expdate, #format
Methods included from PostsData
included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request
Constructor Details
Returns a new instance of AuthorizeNetGateway.
61
62
63
64
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 61
def initialize(options={})
requires!(options, :login, :password)
super
end
|
Instance Method Details
#authorize(amount, payment, options = {}) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 78
def authorize(amount, payment, options={})
if payment.is_a?(String)
commit(:cim_authorize) 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
90
91
92
93
94
95
96
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 90
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 114
def credit(amount, payment, options={})
if payment.is_a?(String)
raise ArgumentError, "Reference credits are not supported. Please supply the original credit card or use the #refund method."
end
commit(:credit) do |xml|
add_order_id(xml, options)
xml.transactionRequest do
xml.transactionType('refundTransaction')
xml.amount(amount(amount))
add_payment_source(xml, payment)
add_invoice(xml, 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
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 66
def purchase(amount, payment, options = {})
if payment.is_a?(String)
commit(:cim_purchase) 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
98
99
100
101
102
103
104
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 98
def refund(amount, authorization, options={})
if auth_was_for_cim?(authorization)
cim_refund(amount, authorization, options)
else
normal_refund(amount, authorization, options)
end
end
|
#scrub(transcript) ⇒ Object
168
169
170
171
172
173
174
175
176
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 168
def scrub(transcript)
transcript.
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(%r((<cryptogram>).+(</cryptogram>)), '\1[FILTERED]\2')
end
|
#store(credit_card, options = {}) ⇒ Object
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 141
def store(credit_card, options = {})
commit(:cim_store) do |xml|
xml.profile do
xml.merchantCustomerId(truncate(options[:merchant_customer_id], 20) || SecureRandom.hex(10))
xml.description(truncate(options[:description], 255)) unless empty?(options[:description])
xml.email(options[:email]) unless empty?(options[:email])
xml.paymentProfiles do
xml.customerType("individual")
add_billing_address(xml, credit_card, options)
add_shipping_address(xml, options, "shipToList")
xml.payment do
xml.creditCard do
xml.cardNumber(truncate(credit_card.number, 16))
xml.expirationDate(format(credit_card.year, :four_digits) + '-' + format(credit_card.month, :two_digits))
xml.cardCode(credit_card.verification_value) if credit_card.verification_value
end
end
end
end
end
end
|
#supports_network_tokenization? ⇒ Boolean
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 178
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
164
165
166
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 164
def supports_scrubbing?
true
end
|
#verify(credit_card, options = {}) ⇒ Object
134
135
136
137
138
139
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 134
def verify(credit_card, options = {})
MultiResponse.run(:use_first_response) do |r|
r.process { authorize(100, credit_card, options) }
r.process(:ignore_result) { void(r.authorization, options) }
end
end
|
#void(authorization, options = {}) ⇒ Object
106
107
108
109
110
111
112
|
# File 'lib/active_merchant/billing/gateways/authorize_net.rb', line 106
def void(authorization, options={})
if auth_was_for_cim?(authorization)
cim_void(authorization, options)
else
normal_void(authorization, options)
end
end
|