lib/active_merchant/billing/gateways/authorize_net.rb in activemerchant-1.133.0 vs lib/active_merchant/billing/gateways/authorize_net.rb in activemerchant-1.137.0
- old
+ new
@@ -83,15 +83,14 @@
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/
+ 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'
INELIGIBLE_FOR_ISSUING_CREDIT_ERROR = '54'
def initialize(options = {})
requires!(options, :login, :password)
@@ -163,11 +162,11 @@
add_order_id(xml, options)
xml.transactionRequest do
xml.transactionType('refundTransaction')
xml.amount(amount(amount))
- add_payment_source(xml, payment, options, :credit)
+ 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)
@@ -260,21 +259,22 @@
def add_auth_purchase(xml, transaction_type, amount, payment, options)
add_order_id(xml, options)
xml.transactionRequest do
xml.transactionType(transaction_type)
xml.amount(amount(amount))
- add_payment_source(xml, payment, options)
+ add_payment_method(xml, payment, options)
add_invoice(xml, transaction_type, options)
add_tax_fields(xml, options)
add_duty_fields(xml, options)
add_shipping_fields(xml, options)
add_tax_exempt_status(xml, options)
add_po_number(xml, options)
add_customer_data(xml, payment, options)
add_market_type_device_type(xml, payment, options)
add_settings(xml, payment, options)
add_user_fields(xml, amount, options)
+ add_surcharge_fields(xml, options)
add_ship_from_address(xml, options)
add_processing_options(xml, options)
add_subsequent_auth_information(xml, options)
end
end
@@ -285,12 +285,13 @@
xml.send(transaction_type) do
xml.amount(amount(amount))
add_tax_fields(xml, options)
add_shipping_fields(xml, options)
add_duty_fields(xml, options)
- add_payment_source(xml, payment, options)
+ add_payment_method(xml, payment, options)
add_invoice(xml, transaction_type, options)
+ add_surcharge_fields(xml, options)
add_tax_exempt_status(xml, options)
end
end
add_extra_options_for_cim(xml, options)
end
@@ -405,24 +406,31 @@
xml.refTransId(transaction_id_from(authorization))
end
end
end
- def add_payment_source(xml, source, options, action = nil)
- return unless source
+ def add_payment_method(xml, payment_method, options, action = nil)
+ return unless payment_method
- if source.is_a?(String)
- add_token_payment_method(xml, source, options)
- elsif card_brand(source) == 'check'
- add_check(xml, source)
- elsif card_brand(source) == 'apple_pay'
- add_apple_pay_payment_token(xml, source)
+ case payment_method
+ when String
+ add_token_payment_method(xml, payment_method, options)
+ when Check
+ add_check(xml, payment_method)
else
- add_credit_card(xml, source, action)
+ if network_token?(payment_method, options, action)
+ add_network_token(xml, payment_method)
+ else
+ add_credit_card(xml, payment_method, action)
+ end
end
end
+ def network_token?(payment_method, options, action)
+ payment_method.instance_of?(NetworkTokenizationCreditCard) && action != :credit
+ end
+
def camel_case_lower(key)
String(key).split('_').inject([]) { |buffer, e| buffer.push(buffer.empty? ? e : e.capitalize) }.join
end
def add_settings(xml, source, options)
@@ -497,11 +505,10 @@
xml.payment do
xml.creditCard do
xml.cardNumber(truncate(credit_card.number, 16))
xml.expirationDate(format(credit_card.month, :two_digits) + '/' + format(credit_card.year, :four_digits))
xml.cardCode(credit_card.verification_value) if credit_card.valid_card_verification_value?(credit_card.verification_value, credit_card.brand)
- xml.cryptogram(credit_card.payment_cryptogram) if credit_card.is_a?(NetworkTokenizationCreditCard) && action != :credit
end
end
end
end
@@ -524,21 +531,24 @@
customer_payment_profile_id = options[:customer_payment_profile_id] if options[:customer_payment_profile_id]
xml.customerProfileId(customer_profile_id)
xml.customerPaymentProfileId(customer_payment_profile_id)
end
- def add_apple_pay_payment_token(xml, apple_pay_payment_token)
+ def add_network_token(xml, payment_method)
xml.payment do
- xml.opaqueData do
- xml.dataDescriptor(APPLE_PAY_DATA_DESCRIPTOR)
- xml.dataValue(Base64.strict_encode64(apple_pay_payment_token.payment_data.to_json))
+ xml.creditCard do
+ xml.cardNumber(truncate(payment_method.number, 16))
+ xml.expirationDate(format(payment_method.month, :two_digits) + '/' + format(payment_method.year, :four_digits))
+ xml.isPaymentToken(true)
+ xml.cryptogram(payment_method.payment_cryptogram)
end
end
end
def add_market_type_device_type(xml, payment, options)
- return if payment.is_a?(String) || card_brand(payment) == 'check' || card_brand(payment) == 'apple_pay'
+ return unless payment.is_a?(CreditCard)
+ return if payment.is_a?(NetworkTokenizationCreditCard)
if valid_track_data
xml.retail do
xml.marketType(options[:market_type] || MARKET_TYPE[:retail])
xml.deviceType(options[:device_type] || DEVICE_TYPE[:wireless_pos])
@@ -699,10 +709,20 @@
xml.description(duty[:description])
end
end
end
+ def add_surcharge_fields(xml, options)
+ surcharge = options[:surcharge] if options[:surcharge]
+ if surcharge.is_a?(Hash)
+ xml.surcharge do
+ xml.amount(amount(surcharge[:amount].to_i)) if surcharge[:amount]
+ xml.description(surcharge[:description]) if surcharge[:description]
+ end
+ end
+ end
+
def add_shipping_fields(xml, options)
shipping = options[:shipping]
if shipping.is_a?(Hash)
xml.shipping do
xml.amount(amount(shipping[:amount].to_i))
@@ -752,17 +772,11 @@
def create_customer_payment_profile(credit_card, options)
commit(:cim_store_update, options) do |xml|
xml.customerProfileId options[:customer_profile_id]
xml.paymentProfile do
add_billing_address(xml, credit_card, options)
- 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
+ add_credit_card(xml, credit_card, :cim_store_update)
end
end
end
def create_customer_profile(credit_card, options)
@@ -774,16 +788,10 @@
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
+ add_credit_card(xml, credit_card, :cim_store)
end
end
end
end