activemerchant 1.45.0 → 1.126.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG +2167 -2
- data/CONTRIBUTORS +57 -0
- data/README.md +62 -41
- data/lib/active_merchant/billing/avs_result.rb +25 -28
- data/lib/active_merchant/billing/base.rb +11 -35
- data/lib/active_merchant/billing/check.rb +28 -24
- data/lib/active_merchant/billing/compatibility.rb +10 -12
- data/lib/active_merchant/billing/credit_card.rb +141 -69
- data/lib/active_merchant/billing/credit_card_formatting.rb +4 -4
- data/lib/active_merchant/billing/credit_card_methods.rb +348 -52
- data/lib/active_merchant/billing/cvv_result.rb +0 -1
- data/lib/active_merchant/billing/gateway.rb +125 -61
- data/lib/active_merchant/billing/gateways/adyen.rb +633 -127
- data/lib/active_merchant/billing/gateways/airwallex.rb +341 -0
- data/lib/active_merchant/billing/gateways/allied_wallet.rb +205 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +883 -195
- data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +31 -24
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +104 -103
- data/lib/active_merchant/billing/gateways/axcessms.rb +179 -0
- data/lib/active_merchant/billing/gateways/balanced.rb +72 -65
- data/lib/active_merchant/billing/gateways/bambora_apac.rb +222 -0
- data/lib/active_merchant/billing/gateways/bank_frick.rb +16 -16
- data/lib/active_merchant/billing/gateways/banwire.rb +24 -13
- data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +397 -0
- data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +7 -7
- data/lib/active_merchant/billing/gateways/be2bill.rb +7 -7
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +143 -62
- data/lib/active_merchant/billing/gateways/beanstream.rb +45 -13
- data/lib/active_merchant/billing/gateways/beanstream_interac.rb +13 -10
- data/lib/active_merchant/billing/gateways/blue_pay.rb +549 -506
- data/lib/active_merchant/billing/gateways/blue_snap.rb +623 -0
- data/lib/active_merchant/billing/gateways/bogus.rb +82 -36
- data/lib/active_merchant/billing/gateways/borgun.rb +61 -40
- data/lib/active_merchant/billing/gateways/bpoint.rb +277 -0
- data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +21 -2
- data/lib/active_merchant/billing/gateways/braintree/token_nonce.rb +113 -0
- data/lib/active_merchant/billing/gateways/braintree.rb +3 -3
- data/lib/active_merchant/billing/gateways/braintree_blue.rb +592 -203
- data/lib/active_merchant/billing/gateways/braintree_orange.rb +3 -4
- data/lib/active_merchant/billing/gateways/bridge_pay.rb +116 -61
- data/lib/active_merchant/billing/gateways/cams.rb +230 -0
- data/lib/active_merchant/billing/gateways/card_connect.rb +320 -0
- data/lib/active_merchant/billing/gateways/card_save.rb +7 -9
- data/lib/active_merchant/billing/gateways/card_stream.rb +248 -97
- data/lib/active_merchant/billing/gateways/cardknox.rb +327 -0
- data/lib/active_merchant/billing/gateways/cardprocess.rb +256 -0
- data/lib/active_merchant/billing/gateways/cashnet.rb +70 -26
- data/lib/active_merchant/billing/gateways/cc5.rb +14 -17
- data/lib/active_merchant/billing/gateways/cecabank.rb +73 -53
- data/lib/active_merchant/billing/gateways/cenpos.rb +328 -0
- data/lib/active_merchant/billing/gateways/checkout.rb +32 -33
- data/lib/active_merchant/billing/gateways/checkout_v2.rb +340 -0
- data/lib/active_merchant/billing/gateways/citrus_pay.rb +21 -0
- data/lib/active_merchant/billing/gateways/clearhaus.rb +219 -0
- data/lib/active_merchant/billing/gateways/commercegate.rb +11 -12
- data/lib/active_merchant/billing/gateways/conekta.rb +55 -34
- data/lib/active_merchant/billing/gateways/creditcall.rb +272 -0
- data/lib/active_merchant/billing/gateways/credorax.rb +506 -0
- data/lib/active_merchant/billing/gateways/ct_payment.rb +269 -0
- data/lib/active_merchant/billing/gateways/culqi.rb +279 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +637 -221
- data/lib/active_merchant/billing/gateways/d_local.rb +303 -0
- data/lib/active_merchant/billing/gateways/data_cash.rb +57 -355
- data/lib/active_merchant/billing/gateways/decidir.rb +347 -0
- data/lib/active_merchant/billing/gateways/decidir_plus.rb +344 -0
- data/lib/active_merchant/billing/gateways/dibs.rb +199 -0
- data/lib/active_merchant/billing/gateways/digitzs.rb +295 -0
- data/lib/active_merchant/billing/gateways/ebanx.rb +334 -0
- data/lib/active_merchant/billing/gateways/efsnet.rb +46 -50
- data/lib/active_merchant/billing/gateways/elavon.rb +377 -250
- data/lib/active_merchant/billing/gateways/element.rb +386 -0
- data/lib/active_merchant/billing/gateways/epay.rb +92 -71
- data/lib/active_merchant/billing/gateways/evo_ca.rb +13 -14
- data/lib/active_merchant/billing/gateways/eway.rb +85 -73
- data/lib/active_merchant/billing/gateways/eway_managed.rb +85 -87
- data/lib/active_merchant/billing/gateways/eway_rapid.rb +134 -80
- data/lib/active_merchant/billing/gateways/exact.rb +37 -36
- data/lib/active_merchant/billing/gateways/ezic.rb +195 -0
- data/lib/active_merchant/billing/gateways/fat_zebra.rb +124 -74
- data/lib/active_merchant/billing/gateways/federated_canada.rb +11 -13
- data/lib/active_merchant/billing/gateways/finansbank.rb +4 -5
- data/lib/active_merchant/billing/gateways/first_giving.rb +23 -23
- data/lib/active_merchant/billing/gateways/first_pay.rb +45 -23
- data/lib/active_merchant/billing/gateways/firstdata_e4.rb +184 -87
- data/lib/active_merchant/billing/gateways/firstdata_e4_v27.rb +505 -0
- data/lib/active_merchant/billing/gateways/flo2cash.rb +215 -0
- data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +20 -0
- data/lib/active_merchant/billing/gateways/forte.rb +286 -0
- data/lib/active_merchant/billing/gateways/garanti.rb +31 -32
- data/lib/active_merchant/billing/gateways/global_collect.rb +507 -0
- data/lib/active_merchant/billing/gateways/global_transport.rb +25 -15
- data/lib/active_merchant/billing/gateways/hdfc.rb +55 -57
- data/lib/active_merchant/billing/gateways/hps.rb +252 -68
- data/lib/active_merchant/billing/gateways/iats_payments.rb +99 -38
- data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +15 -0
- data/lib/active_merchant/billing/gateways/inspire.rb +48 -48
- data/lib/active_merchant/billing/gateways/instapay.rb +10 -14
- data/lib/active_merchant/billing/gateways/ipg.rb +415 -0
- data/lib/active_merchant/billing/gateways/ipp.rb +176 -0
- data/lib/active_merchant/billing/gateways/iridium.rb +254 -244
- data/lib/active_merchant/billing/gateways/itransact.rb +14 -14
- data/lib/active_merchant/billing/gateways/iveri.rb +254 -0
- data/lib/active_merchant/billing/gateways/ixopay.rb +320 -0
- data/lib/active_merchant/billing/gateways/jetpay.rb +200 -80
- data/lib/active_merchant/billing/gateways/jetpay_v2.rb +432 -0
- data/lib/active_merchant/billing/gateways/komoju.rb +115 -0
- data/lib/active_merchant/billing/gateways/kushki.rb +277 -0
- data/lib/active_merchant/billing/gateways/latitude19.rb +412 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +95 -85
- data/lib/active_merchant/billing/gateways/litle.rb +371 -94
- data/lib/active_merchant/billing/gateways/mastercard.rb +293 -0
- data/lib/active_merchant/billing/gateways/maxipago.rb +146 -123
- data/lib/active_merchant/billing/gateways/mercado_pago.rb +331 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +47 -23
- data/lib/active_merchant/billing/gateways/merchant_one.rb +16 -20
- data/lib/active_merchant/billing/gateways/merchant_partners.rb +245 -0
- data/lib/active_merchant/billing/gateways/merchant_ware.rb +54 -60
- data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +60 -44
- data/lib/active_merchant/billing/gateways/merchant_warrior.rb +76 -23
- data/lib/active_merchant/billing/gateways/mercury.rb +73 -54
- data/lib/active_merchant/billing/gateways/metrics_global.rb +33 -43
- data/lib/active_merchant/billing/gateways/micropayment.rb +182 -0
- data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +7 -7
- data/lib/active_merchant/billing/gateways/migs.rb +101 -37
- data/lib/active_merchant/billing/gateways/mit.rb +260 -0
- data/lib/active_merchant/billing/gateways/modern_payments.rb +3 -3
- data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +30 -34
- data/lib/active_merchant/billing/gateways/moka.rb +290 -0
- data/lib/active_merchant/billing/gateways/monei.rb +422 -0
- data/lib/active_merchant/billing/gateways/moneris.rb +236 -72
- data/lib/active_merchant/billing/gateways/money_movers.rb +11 -13
- data/lib/active_merchant/billing/gateways/mundipagg.rb +363 -0
- data/lib/active_merchant/billing/gateways/nab_transact.rb +87 -68
- data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +163 -0
- data/lib/active_merchant/billing/gateways/net_registry.rb +12 -12
- data/lib/active_merchant/billing/gateways/netaxept.rb +33 -34
- data/lib/active_merchant/billing/gateways/netbanx.rb +376 -0
- data/lib/active_merchant/billing/gateways/netbilling.rb +82 -43
- data/lib/active_merchant/billing/gateways/netpay.rb +10 -10
- data/lib/active_merchant/billing/gateways/network_merchants.rb +7 -11
- data/lib/active_merchant/billing/gateways/nmi.rb +279 -174
- data/lib/active_merchant/billing/gateways/ogone.rb +96 -50
- data/lib/active_merchant/billing/gateways/omise.rb +323 -0
- data/lib/active_merchant/billing/gateways/openpay.rb +58 -23
- data/lib/active_merchant/billing/gateways/opp.rb +394 -0
- data/lib/active_merchant/billing/gateways/optimal_payment.rb +87 -69
- data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +5 -7
- data/lib/active_merchant/billing/gateways/orbital.rb +771 -328
- data/lib/active_merchant/billing/gateways/pac_net_raven.rb +31 -32
- data/lib/active_merchant/billing/gateways/pagarme.rb +239 -0
- data/lib/active_merchant/billing/gateways/pago_facil.rb +12 -14
- data/lib/active_merchant/billing/gateways/pay_arc.rb +392 -0
- data/lib/active_merchant/billing/gateways/pay_conex.rb +245 -0
- data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +84 -68
- data/lib/active_merchant/billing/gateways/pay_hub.rb +213 -0
- data/lib/active_merchant/billing/gateways/pay_junction.rb +37 -37
- data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +206 -0
- data/lib/active_merchant/billing/gateways/pay_secure.rb +15 -17
- data/lib/active_merchant/billing/gateways/pay_trace.rb +404 -0
- data/lib/active_merchant/billing/gateways/paybox_direct.rb +85 -49
- data/lib/active_merchant/billing/gateways/payeezy.rb +458 -0
- data/lib/active_merchant/billing/gateways/payex.rb +39 -42
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +67 -41
- data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +11 -8
- data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +3 -3
- data/lib/active_merchant/billing/gateways/payflow.rb +215 -46
- data/lib/active_merchant/billing/gateways/payflow_express.rb +64 -68
- data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +2 -3
- data/lib/active_merchant/billing/gateways/payflow_uk.rb +5 -6
- data/lib/active_merchant/billing/gateways/payment_express.rb +78 -58
- data/lib/active_merchant/billing/gateways/paymentez.rb +353 -0
- data/lib/active_merchant/billing/gateways/paymill.rb +163 -75
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +55 -7
- data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +1 -1
- data/lib/active_merchant/billing/gateways/paypal.rb +37 -18
- data/lib/active_merchant/billing/gateways/paypal_ca.rb +2 -2
- data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +5 -5
- data/lib/active_merchant/billing/gateways/paypal_express.rb +12 -6
- data/lib/active_merchant/billing/gateways/paypal_express_common.rb +3 -3
- data/lib/active_merchant/billing/gateways/paysafe.rb +412 -0
- data/lib/active_merchant/billing/gateways/payscout.rb +10 -13
- data/lib/active_merchant/billing/gateways/paystation.rb +96 -91
- data/lib/active_merchant/billing/gateways/payu_in.rb +249 -0
- data/lib/active_merchant/billing/gateways/payu_latam.rb +479 -0
- data/lib/active_merchant/billing/gateways/payway.rb +27 -27
- data/lib/active_merchant/billing/gateways/payway_dot_com.rb +253 -0
- data/lib/active_merchant/billing/gateways/pin.rb +113 -37
- data/lib/active_merchant/billing/gateways/plugnpay.rb +82 -82
- data/lib/active_merchant/billing/gateways/priority.rb +369 -0
- data/lib/active_merchant/billing/gateways/pro_pay.rb +325 -0
- data/lib/active_merchant/billing/gateways/psigate.rb +55 -44
- data/lib/active_merchant/billing/gateways/psl_card.rb +32 -40
- data/lib/active_merchant/billing/gateways/qbms.rb +86 -76
- data/lib/active_merchant/billing/gateways/quantum.rb +21 -23
- data/lib/active_merchant/billing/gateways/quickbooks.rb +377 -0
- data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +184 -0
- data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +297 -0
- data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +226 -0
- data/lib/active_merchant/billing/gateways/quickpay.rb +10 -353
- data/lib/active_merchant/billing/gateways/qvalent.rb +305 -0
- data/lib/active_merchant/billing/gateways/rapyd.rb +258 -0
- data/lib/active_merchant/billing/gateways/realex.rb +154 -52
- data/lib/active_merchant/billing/gateways/redsys.rb +488 -161
- data/lib/active_merchant/billing/gateways/s5.rb +247 -0
- data/lib/active_merchant/billing/gateways/safe_charge.rb +298 -0
- data/lib/active_merchant/billing/gateways/sage.rb +404 -133
- data/lib/active_merchant/billing/gateways/sage_pay.rb +145 -109
- data/lib/active_merchant/billing/gateways/sallie_mae.rb +13 -15
- data/lib/active_merchant/billing/gateways/secure_net.rb +62 -54
- data/lib/active_merchant/billing/gateways/secure_pay.rb +32 -42
- data/lib/active_merchant/billing/gateways/secure_pay_au.rb +36 -27
- data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +14 -16
- data/lib/active_merchant/billing/gateways/securion_pay.rb +265 -0
- data/lib/active_merchant/billing/gateways/simetrik.rb +362 -0
- data/lib/active_merchant/billing/gateways/skip_jack.rb +52 -54
- data/lib/active_merchant/billing/gateways/smart_ps.rb +51 -60
- data/lib/active_merchant/billing/gateways/so_easy_pay.rb +29 -29
- data/lib/active_merchant/billing/gateways/spreedly_core.rb +108 -43
- data/lib/active_merchant/billing/gateways/stripe.rb +536 -120
- data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +516 -0
- data/lib/active_merchant/billing/gateways/swipe_checkout.rb +19 -25
- data/lib/active_merchant/billing/gateways/telr.rb +273 -0
- data/lib/active_merchant/billing/gateways/tns.rb +16 -217
- data/lib/active_merchant/billing/gateways/trans_first.rb +148 -34
- data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +612 -0
- data/lib/active_merchant/billing/gateways/transact_pro.rb +222 -0
- data/lib/active_merchant/billing/gateways/transax.rb +6 -8
- data/lib/active_merchant/billing/gateways/transnational.rb +1 -2
- data/lib/active_merchant/billing/gateways/trexle.rb +221 -0
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +162 -89
- data/lib/active_merchant/billing/gateways/usa_epay.rb +5 -6
- data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +332 -236
- data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +185 -72
- data/lib/active_merchant/billing/gateways/vanco.rb +294 -0
- data/lib/active_merchant/billing/gateways/verifi.rb +52 -53
- data/lib/active_merchant/billing/gateways/viaklix.rb +19 -31
- data/lib/active_merchant/billing/gateways/visanet_peru.rb +250 -0
- data/lib/active_merchant/billing/gateways/vpos.rb +220 -0
- data/lib/active_merchant/billing/gateways/webpay.rb +9 -9
- data/lib/active_merchant/billing/gateways/wepay.rb +108 -62
- data/lib/active_merchant/billing/gateways/wirecard.rb +52 -43
- data/lib/active_merchant/billing/gateways/wompi.rb +193 -0
- data/lib/active_merchant/billing/gateways/world_net.rb +345 -0
- data/lib/active_merchant/billing/gateways/worldpay.rb +725 -121
- data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +208 -0
- data/lib/active_merchant/billing/gateways/worldpay_us.rb +79 -39
- data/lib/active_merchant/billing/gateways.rb +8 -11
- data/lib/active_merchant/billing/model.rb +2 -2
- data/lib/active_merchant/billing/network_tokenization_credit_card.rb +39 -0
- data/lib/active_merchant/billing/payment_token.rb +1 -1
- data/lib/active_merchant/billing/rails.rb +1 -1
- data/lib/active_merchant/billing/response.rb +19 -13
- data/lib/active_merchant/billing/three_d_secure_eci_mapper.rb +27 -0
- data/lib/active_merchant/billing.rb +3 -0
- data/lib/active_merchant/connection.rb +196 -0
- data/lib/active_merchant/country.rb +13 -8
- data/lib/active_merchant/errors.rb +6 -0
- data/lib/active_merchant/net_http_ssl_connection.rb +11 -0
- data/lib/active_merchant/network_connection_retries.rb +78 -0
- data/lib/active_merchant/post_data.rb +26 -0
- data/lib/active_merchant/posts_data.rb +92 -0
- data/lib/active_merchant/version.rb +1 -1
- data/lib/active_merchant.rb +14 -59
- data/lib/activemerchant.rb +1 -1
- data/lib/certs/cacert.pem +3214 -0
- data/lib/support/gateway_support.rb +8 -10
- data/lib/support/outbound_hosts.rb +13 -10
- data/lib/support/ssl_verify.rb +9 -14
- data/lib/support/ssl_version.rb +86 -0
- metadata +136 -94
- checksums.yaml.gz.sig +0 -1
- data/lib/active_merchant/billing/gateways/app55.rb +0 -176
- data/lib/active_merchant/billing/gateways/barclays_epdq.rb +0 -314
- data/lib/active_merchant/billing/gateways/certo_direct.rb +0 -278
- data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +0 -246
- data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +0 -13
- data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +0 -29
- data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +0 -66
- data/lib/active_merchant/billing/gateways/moneris_us.rb +0 -291
- data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +0 -87
- data/lib/active_merchant/billing/gateways/sage/sage_core.rb +0 -114
- data/lib/active_merchant/billing/gateways/sage/sage_vault.rb +0 -149
- data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +0 -102
- data/lib/active_merchant/billing/gateways/vindicia.rb +0 -385
- data/lib/active_merchant/offsite_payments_shim.rb +0 -19
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -0
@@ -1,181 +1,488 @@
|
|
1
1
|
require 'nokogiri'
|
2
2
|
|
3
|
-
module ActiveMerchant
|
4
|
-
module Billing
|
3
|
+
module ActiveMerchant
|
4
|
+
module Billing
|
5
5
|
class AuthorizeNetGateway < Gateway
|
6
6
|
include Empty
|
7
7
|
|
8
8
|
self.test_url = 'https://apitest.authorize.net/xml/v1/request.api'
|
9
|
-
self.live_url = 'https://
|
9
|
+
self.live_url = 'https://api2.authorize.net/xml/v1/request.api'
|
10
10
|
|
11
|
-
self.supported_countries = %w(
|
11
|
+
self.supported_countries = %w(AU CA US)
|
12
12
|
self.default_currency = 'USD'
|
13
13
|
self.money_format = :dollars
|
14
|
-
self.supported_cardtypes = [
|
14
|
+
self.supported_cardtypes = %i[visa master american_express discover diners_club jcb maestro]
|
15
15
|
|
16
16
|
self.homepage_url = 'http://www.authorize.net/'
|
17
17
|
self.display_name = 'Authorize.Net'
|
18
18
|
|
19
|
+
# Authorize.net has slightly different definitions for returned AVS codes
|
20
|
+
# that have been mapped to the closest equivalent AM standard AVSResult codes
|
21
|
+
# Authorize.net's descriptions noted below
|
22
|
+
STANDARD_AVS_CODE_MAPPING = {
|
23
|
+
'A' => 'A', # Street Address: Match -- First 5 Digits of ZIP: No Match
|
24
|
+
'B' => 'I', # Address not provided for AVS check or street address match, postal code could not be verified
|
25
|
+
'E' => 'E', # AVS Error
|
26
|
+
'G' => 'G', # Non U.S. Card Issuing Bank
|
27
|
+
'N' => 'N', # Street Address: No Match -- First 5 Digits of ZIP: No Match
|
28
|
+
'P' => 'I', # AVS not applicable for this transaction
|
29
|
+
'R' => 'R', # Retry, System Is Unavailable
|
30
|
+
'S' => 'S', # AVS Not Supported by Card Issuing Bank
|
31
|
+
'U' => 'U', # Address Information For This Cardholder Is Unavailable
|
32
|
+
'W' => 'W', # Street Address: No Match -- All 9 Digits of ZIP: Match
|
33
|
+
'X' => 'X', # Street Address: Match -- All 9 Digits of ZIP: Match
|
34
|
+
'Y' => 'Y', # Street Address: Match - First 5 Digits of ZIP: Match
|
35
|
+
'Z' => 'Z' # Street Address: No Match - First 5 Digits of ZIP: Match
|
36
|
+
}
|
37
|
+
|
38
|
+
STANDARD_ERROR_CODE_MAPPING = {
|
39
|
+
'2127' => STANDARD_ERROR_CODE[:incorrect_address],
|
40
|
+
'22' => STANDARD_ERROR_CODE[:card_declined],
|
41
|
+
'227' => STANDARD_ERROR_CODE[:incorrect_address],
|
42
|
+
'23' => STANDARD_ERROR_CODE[:card_declined],
|
43
|
+
'2315' => STANDARD_ERROR_CODE[:invalid_number],
|
44
|
+
'2316' => STANDARD_ERROR_CODE[:invalid_expiry_date],
|
45
|
+
'2317' => STANDARD_ERROR_CODE[:expired_card],
|
46
|
+
'235' => STANDARD_ERROR_CODE[:processing_error],
|
47
|
+
'237' => STANDARD_ERROR_CODE[:invalid_number],
|
48
|
+
'24' => STANDARD_ERROR_CODE[:pickup_card],
|
49
|
+
'244' => STANDARD_ERROR_CODE[:incorrect_cvc],
|
50
|
+
'300' => STANDARD_ERROR_CODE[:config_error],
|
51
|
+
'3153' => STANDARD_ERROR_CODE[:processing_error],
|
52
|
+
'3155' => STANDARD_ERROR_CODE[:unsupported_feature],
|
53
|
+
'36' => STANDARD_ERROR_CODE[:incorrect_number],
|
54
|
+
'37' => STANDARD_ERROR_CODE[:invalid_expiry_date],
|
55
|
+
'378' => STANDARD_ERROR_CODE[:invalid_cvc],
|
56
|
+
'38' => STANDARD_ERROR_CODE[:expired_card],
|
57
|
+
'384' => STANDARD_ERROR_CODE[:config_error]
|
58
|
+
}
|
59
|
+
|
60
|
+
MARKET_TYPE = {
|
61
|
+
moto: '1',
|
62
|
+
retail: '2'
|
63
|
+
}
|
64
|
+
|
65
|
+
DEVICE_TYPE = {
|
66
|
+
unknown: '1',
|
67
|
+
unattended_terminal: '2',
|
68
|
+
self_service_terminal: '3',
|
69
|
+
electronic_cash_register: '4',
|
70
|
+
personal_computer_terminal: '5',
|
71
|
+
airpay: '6',
|
72
|
+
wireless_pos: '7',
|
73
|
+
website: '8',
|
74
|
+
dial_terminal: '9',
|
75
|
+
virtual_terminal: '10'
|
76
|
+
}
|
77
|
+
|
19
78
|
class_attribute :duplicate_window
|
20
79
|
|
21
80
|
APPROVED, DECLINED, ERROR, FRAUD_REVIEW = 1, 2, 3, 4
|
22
81
|
TRANSACTION_ALREADY_ACTIONED = %w(310 311)
|
23
82
|
|
24
83
|
CARD_CODE_ERRORS = %w(N S)
|
25
|
-
AVS_ERRORS = %w(A E N R W Z)
|
84
|
+
AVS_ERRORS = %w(A E I N R W Z)
|
26
85
|
AVS_REASON_CODES = %w(27 45)
|
27
86
|
|
28
87
|
TRACKS = {
|
29
|
-
|
30
|
-
|
88
|
+
1 => /^%(?<format_code>.)(?<pan>[\d]{1,19}+)\^(?<name>.{2,26})\^(?<expiration>[\d]{0,4}|\^)(?<service_code>[\d]{0,3}|\^)(?<discretionary_data>.*)\?\Z/,
|
89
|
+
2 => /\A;(?<pan>[\d]{1,19}+)=(?<expiration>[\d]{0,4}|=)(?<service_code>[\d]{0,3}|=)(?<discretionary_data>.*)\?\Z/
|
31
90
|
}.freeze
|
32
91
|
|
33
|
-
APPLE_PAY_DATA_DESCRIPTOR =
|
92
|
+
APPLE_PAY_DATA_DESCRIPTOR = 'COMMON.APPLE.INAPP.PAYMENT'
|
93
|
+
|
94
|
+
PAYMENT_METHOD_NOT_SUPPORTED_ERROR = '155'
|
95
|
+
INELIGIBLE_FOR_ISSUING_CREDIT_ERROR = '54'
|
34
96
|
|
35
|
-
def initialize(options={})
|
97
|
+
def initialize(options = {})
|
36
98
|
requires!(options, :login, :password)
|
37
99
|
super
|
38
100
|
end
|
39
101
|
|
40
102
|
def purchase(amount, payment, options = {})
|
41
|
-
|
103
|
+
if payment.is_a?(String)
|
104
|
+
commit(:cim_purchase, options) do |xml|
|
105
|
+
add_cim_auth_purchase(xml, 'profileTransAuthCapture', amount, payment, options)
|
106
|
+
end
|
107
|
+
else
|
108
|
+
commit(:purchase) do |xml|
|
109
|
+
add_auth_purchase(xml, 'authCaptureTransaction', amount, payment, options)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def authorize(amount, payment, options = {})
|
115
|
+
if payment.is_a?(String)
|
116
|
+
commit(:cim_authorize, options) do |xml|
|
117
|
+
add_cim_auth_purchase(xml, 'profileTransAuthOnly', amount, payment, options)
|
118
|
+
end
|
119
|
+
else
|
120
|
+
commit(:authorize) do |xml|
|
121
|
+
add_auth_purchase(xml, 'authOnlyTransaction', amount, payment, options)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def capture(amount, authorization, options = {})
|
127
|
+
if auth_was_for_cim?(authorization)
|
128
|
+
cim_capture(amount, authorization, options)
|
129
|
+
else
|
130
|
+
normal_capture(amount, authorization, options)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def refund(amount, authorization, options = {})
|
135
|
+
response =
|
136
|
+
if auth_was_for_cim?(authorization)
|
137
|
+
cim_refund(amount, authorization, options)
|
138
|
+
else
|
139
|
+
normal_refund(amount, authorization, options)
|
140
|
+
end
|
141
|
+
|
142
|
+
return response if response.success?
|
143
|
+
return response unless options[:force_full_refund_if_unsettled]
|
144
|
+
|
145
|
+
if response.params['response_reason_code'] == INELIGIBLE_FOR_ISSUING_CREDIT_ERROR
|
146
|
+
void(authorization, options)
|
147
|
+
else
|
148
|
+
response
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def void(authorization, options = {})
|
153
|
+
if auth_was_for_cim?(authorization)
|
154
|
+
cim_void(authorization, options)
|
155
|
+
else
|
156
|
+
normal_void(authorization, options)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def credit(amount, payment, options = {})
|
161
|
+
raise ArgumentError, 'Reference credits are not supported. Please supply the original credit card or use the #refund method.' if payment.is_a?(String)
|
162
|
+
|
163
|
+
commit(:credit) do |xml|
|
42
164
|
add_order_id(xml, options)
|
43
165
|
xml.transactionRequest do
|
44
|
-
xml.transactionType
|
45
|
-
xml.amount
|
46
|
-
|
47
|
-
|
166
|
+
xml.transactionType('refundTransaction')
|
167
|
+
xml.amount(amount(amount))
|
168
|
+
|
169
|
+
add_payment_source(xml, payment, options, :credit)
|
170
|
+
xml.refTransId(transaction_id_from(options[:transaction_id])) if options[:transaction_id]
|
171
|
+
add_invoice(xml, 'refundTransaction', options)
|
48
172
|
add_customer_data(xml, payment, options)
|
49
|
-
add_retail_data(xml, payment)
|
50
173
|
add_settings(xml, payment, options)
|
51
174
|
add_user_fields(xml, amount, options)
|
52
175
|
end
|
53
176
|
end
|
54
177
|
end
|
55
178
|
|
56
|
-
def
|
57
|
-
|
179
|
+
def verify(credit_card, options = {})
|
180
|
+
MultiResponse.run(:use_first_response) do |r|
|
181
|
+
r.process { authorize(100, credit_card, options) }
|
182
|
+
r.process(:ignore_result) { void(r.authorization, options) }
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def store(credit_card, options = {})
|
187
|
+
if options[:customer_profile_id]
|
188
|
+
create_customer_payment_profile(credit_card, options)
|
189
|
+
else
|
190
|
+
create_customer_profile(credit_card, options)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def unstore(authorization)
|
195
|
+
customer_profile_id, = split_authorization(authorization)
|
196
|
+
|
197
|
+
delete_customer_profile(customer_profile_id)
|
198
|
+
end
|
199
|
+
|
200
|
+
def verify_credentials
|
201
|
+
response = commit(:verify_credentials) {}
|
202
|
+
response.success?
|
203
|
+
end
|
204
|
+
|
205
|
+
def supports_scrubbing?
|
206
|
+
true
|
207
|
+
end
|
208
|
+
|
209
|
+
def scrub(transcript)
|
210
|
+
transcript.
|
211
|
+
gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
|
212
|
+
gsub(%r((<transactionKey>).+(</transactionKey>)), '\1[FILTERED]\2').
|
213
|
+
gsub(%r((<cardNumber>).+(</cardNumber>)), '\1[FILTERED]\2').
|
214
|
+
gsub(%r((<cardCode>).+(</cardCode>)), '\1[FILTERED]\2').
|
215
|
+
gsub(%r((<track1>).+(</track1>)), '\1[FILTERED]\2').
|
216
|
+
gsub(%r((<track2>).+(</track2>)), '\1[FILTERED]\2').
|
217
|
+
gsub(/(<routingNumber>).+(<\/routingNumber>)/, '\1[FILTERED]\2').
|
218
|
+
gsub(/(<accountNumber>).+(<\/accountNumber>)/, '\1[FILTERED]\2').
|
219
|
+
gsub(%r((<cryptogram>).+(</cryptogram>)), '\1[FILTERED]\2')
|
220
|
+
end
|
221
|
+
|
222
|
+
def supports_network_tokenization?
|
223
|
+
card = Billing::NetworkTokenizationCreditCard.new({
|
224
|
+
number: '4111111111111111',
|
225
|
+
month: 12,
|
226
|
+
year: 20,
|
227
|
+
first_name: 'John',
|
228
|
+
last_name: 'Smith',
|
229
|
+
brand: 'visa',
|
230
|
+
payment_cryptogram: 'EHuWW9PiBkWvqE5juRwDzAUFBAk='
|
231
|
+
})
|
232
|
+
|
233
|
+
request = post_data(:authorize) do |xml|
|
234
|
+
add_auth_purchase(xml, 'authOnlyTransaction', 1, card, {})
|
235
|
+
end
|
236
|
+
raw_response = ssl_post(url, request, headers)
|
237
|
+
response = parse(:authorize, raw_response)
|
238
|
+
response[:response_reason_code].to_s != PAYMENT_METHOD_NOT_SUPPORTED_ERROR
|
239
|
+
end
|
240
|
+
|
241
|
+
private
|
242
|
+
|
243
|
+
def add_auth_purchase(xml, transaction_type, amount, payment, options)
|
244
|
+
add_order_id(xml, options)
|
245
|
+
xml.transactionRequest do
|
246
|
+
xml.transactionType(transaction_type)
|
247
|
+
xml.amount(amount(amount))
|
248
|
+
add_payment_source(xml, payment, options)
|
249
|
+
add_invoice(xml, transaction_type, options)
|
250
|
+
add_tax_fields(xml, options)
|
251
|
+
add_duty_fields(xml, options)
|
252
|
+
add_shipping_fields(xml, options)
|
253
|
+
add_tax_exempt_status(xml, options)
|
254
|
+
add_po_number(xml, options)
|
255
|
+
add_customer_data(xml, payment, options)
|
256
|
+
add_market_type_device_type(xml, payment, options)
|
257
|
+
add_settings(xml, payment, options)
|
258
|
+
add_user_fields(xml, amount, options)
|
259
|
+
add_ship_from_address(xml, options)
|
260
|
+
add_processing_options(xml, options)
|
261
|
+
add_subsequent_auth_information(xml, options)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
def add_cim_auth_purchase(xml, transaction_type, amount, payment, options)
|
266
|
+
add_order_id(xml, options)
|
267
|
+
xml.transaction do
|
268
|
+
xml.send(transaction_type) do
|
269
|
+
xml.amount(amount(amount))
|
270
|
+
add_tax_fields(xml, options)
|
271
|
+
add_shipping_fields(xml, options)
|
272
|
+
add_duty_fields(xml, options)
|
273
|
+
add_payment_source(xml, payment, options)
|
274
|
+
add_invoice(xml, transaction_type, options)
|
275
|
+
add_tax_exempt_status(xml, options)
|
276
|
+
end
|
277
|
+
end
|
278
|
+
add_extra_options_for_cim(xml, options)
|
279
|
+
end
|
280
|
+
|
281
|
+
def cim_capture(amount, authorization, options)
|
282
|
+
commit(:cim_capture, options) do |xml|
|
58
283
|
add_order_id(xml, options)
|
59
|
-
xml.
|
60
|
-
xml.
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
284
|
+
xml.transaction do
|
285
|
+
xml.profileTransPriorAuthCapture do
|
286
|
+
xml.amount(amount(amount))
|
287
|
+
add_tax_fields(xml, options)
|
288
|
+
add_shipping_fields(xml, options)
|
289
|
+
add_duty_fields(xml, options)
|
290
|
+
xml.transId(transaction_id_from(authorization))
|
291
|
+
end
|
67
292
|
end
|
293
|
+
add_extra_options_for_cim(xml, options)
|
68
294
|
end
|
69
295
|
end
|
70
296
|
|
71
|
-
def
|
72
|
-
commit(
|
297
|
+
def normal_capture(amount, authorization, options)
|
298
|
+
commit(:capture) do |xml|
|
73
299
|
add_order_id(xml, options)
|
74
300
|
xml.transactionRequest do
|
75
|
-
xml.transactionType
|
76
|
-
xml.amount
|
77
|
-
xml
|
78
|
-
|
301
|
+
xml.transactionType('priorAuthCaptureTransaction')
|
302
|
+
xml.amount(amount(amount))
|
303
|
+
add_tax_fields(xml, options)
|
304
|
+
add_duty_fields(xml, options)
|
305
|
+
add_shipping_fields(xml, options)
|
306
|
+
add_tax_exempt_status(xml, options)
|
307
|
+
add_po_number(xml, options)
|
308
|
+
xml.refTransId(transaction_id_from(authorization))
|
309
|
+
add_invoice(xml, 'capture', options)
|
79
310
|
add_user_fields(xml, amount, options)
|
80
311
|
end
|
81
312
|
end
|
82
313
|
end
|
83
314
|
|
84
|
-
def
|
85
|
-
transaction_id, card_number = split_authorization(authorization)
|
86
|
-
|
315
|
+
def cim_refund(amount, authorization, options)
|
316
|
+
transaction_id, card_number, = split_authorization(authorization)
|
317
|
+
|
318
|
+
commit(:cim_refund, options) do |xml|
|
319
|
+
add_order_id(xml, options)
|
320
|
+
xml.transaction do
|
321
|
+
xml.profileTransRefund do
|
322
|
+
xml.amount(amount(amount))
|
323
|
+
add_tax_fields(xml, options)
|
324
|
+
add_shipping_fields(xml, options)
|
325
|
+
add_duty_fields(xml, options)
|
326
|
+
xml.creditCardNumberMasked(card_number)
|
327
|
+
add_invoice(xml, 'profileTransRefund', options)
|
328
|
+
xml.transId(transaction_id)
|
329
|
+
end
|
330
|
+
end
|
331
|
+
add_extra_options_for_cim(xml, options)
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
def normal_refund(amount, authorization, options)
|
336
|
+
transaction_id, card_number, = split_authorization(authorization)
|
337
|
+
|
338
|
+
commit(:refund) do |xml|
|
87
339
|
xml.transactionRequest do
|
88
|
-
xml.transactionType
|
89
|
-
xml.amount
|
340
|
+
xml.transactionType('refundTransaction')
|
341
|
+
xml.amount(amount.nil? ? 0 : amount(amount))
|
90
342
|
xml.payment do
|
91
|
-
|
92
|
-
xml.
|
93
|
-
|
343
|
+
if options[:routing_number]
|
344
|
+
xml.bankAccount do
|
345
|
+
xml.accountType(options[:account_type])
|
346
|
+
xml.routingNumber(options[:routing_number])
|
347
|
+
xml.accountNumber(options[:account_number])
|
348
|
+
xml.nameOnAccount("#{options[:first_name]} #{options[:last_name]}")
|
349
|
+
end
|
350
|
+
else
|
351
|
+
xml.creditCard do
|
352
|
+
xml.cardNumber(card_number || options[:card_number])
|
353
|
+
xml.expirationDate('XXXX')
|
354
|
+
end
|
94
355
|
end
|
95
356
|
end
|
96
|
-
xml.refTransId
|
357
|
+
xml.refTransId(transaction_id)
|
358
|
+
|
359
|
+
add_invoice(xml, 'refundTransaction', options)
|
360
|
+
add_tax_fields(xml, options)
|
361
|
+
add_duty_fields(xml, options)
|
362
|
+
add_shipping_fields(xml, options)
|
363
|
+
add_tax_exempt_status(xml, options)
|
364
|
+
add_po_number(xml, options)
|
97
365
|
add_customer_data(xml, nil, options)
|
98
366
|
add_user_fields(xml, amount, options)
|
99
367
|
end
|
100
368
|
end
|
101
369
|
end
|
102
370
|
|
103
|
-
def
|
104
|
-
commit(
|
371
|
+
def cim_void(authorization, options)
|
372
|
+
commit(:cim_void, options) do |xml|
|
105
373
|
add_order_id(xml, options)
|
106
|
-
xml.
|
107
|
-
xml.
|
108
|
-
|
109
|
-
|
374
|
+
xml.transaction do
|
375
|
+
xml.profileTransVoid do
|
376
|
+
xml.transId(transaction_id_from(authorization))
|
377
|
+
end
|
110
378
|
end
|
379
|
+
add_extra_options_for_cim(xml, options)
|
111
380
|
end
|
112
381
|
end
|
113
382
|
|
114
|
-
def
|
115
|
-
|
116
|
-
|
117
|
-
|
383
|
+
def normal_void(authorization, options)
|
384
|
+
commit(:void) do |xml|
|
385
|
+
add_order_id(xml, options)
|
386
|
+
xml.transactionRequest do
|
387
|
+
xml.transactionType('voidTransaction')
|
388
|
+
xml.refTransId(transaction_id_from(authorization))
|
389
|
+
end
|
118
390
|
end
|
119
391
|
end
|
120
392
|
|
121
|
-
|
122
|
-
|
123
|
-
def add_payment_source(xml, source)
|
393
|
+
def add_payment_source(xml, source, options, action = nil)
|
124
394
|
return unless source
|
125
|
-
|
395
|
+
|
396
|
+
if source.is_a?(String)
|
397
|
+
add_token_payment_method(xml, source, options)
|
398
|
+
elsif card_brand(source) == 'check'
|
126
399
|
add_check(xml, source)
|
127
400
|
elsif card_brand(source) == 'apple_pay'
|
128
401
|
add_apple_pay_payment_token(xml, source)
|
129
402
|
else
|
130
|
-
add_credit_card(xml, source)
|
403
|
+
add_credit_card(xml, source, action)
|
131
404
|
end
|
132
405
|
end
|
133
406
|
|
407
|
+
def camel_case_lower(key)
|
408
|
+
String(key).split('_').inject([]) { |buffer, e| buffer.push(buffer.empty? ? e : e.capitalize) }.join
|
409
|
+
end
|
410
|
+
|
134
411
|
def add_settings(xml, source, options)
|
135
412
|
xml.transactionSettings do
|
136
|
-
if
|
413
|
+
if options[:recurring] || subsequent_recurring_transaction?(options)
|
414
|
+
xml.setting do
|
415
|
+
xml.settingName('recurringBilling')
|
416
|
+
xml.settingValue('true')
|
417
|
+
end
|
418
|
+
end
|
419
|
+
if options[:disable_partial_auth]
|
420
|
+
xml.setting do
|
421
|
+
xml.settingName('allowPartialAuth')
|
422
|
+
xml.settingValue('false')
|
423
|
+
end
|
424
|
+
end
|
425
|
+
if options[:duplicate_window]
|
426
|
+
set_duplicate_window(xml, options[:duplicate_window])
|
427
|
+
elsif self.class.duplicate_window
|
428
|
+
ActiveMerchant.deprecated 'Using the duplicate_window class_attribute is deprecated. Use the transaction options hash instead.'
|
429
|
+
set_duplicate_window(xml, self.class.duplicate_window)
|
430
|
+
end
|
431
|
+
if options.key?(:email_customer)
|
137
432
|
xml.setting do
|
138
|
-
xml.settingName
|
139
|
-
xml.settingValue
|
433
|
+
xml.settingName('emailCustomer')
|
434
|
+
xml.settingValue(options[:email_customer] ? 'true' : 'false')
|
140
435
|
end
|
141
436
|
end
|
142
|
-
if
|
437
|
+
if options[:header_email_receipt]
|
143
438
|
xml.setting do
|
144
|
-
xml.settingName
|
145
|
-
xml.settingValue
|
439
|
+
xml.settingName('headerEmailReceipt')
|
440
|
+
xml.settingValue(options[:header_email_receipt])
|
146
441
|
end
|
147
442
|
end
|
443
|
+
if options[:test_request]
|
444
|
+
xml.setting do
|
445
|
+
xml.settingName('testRequest')
|
446
|
+
xml.settingValue('1')
|
447
|
+
end
|
448
|
+
end
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
452
|
+
def set_duplicate_window(xml, value)
|
453
|
+
xml.setting do
|
454
|
+
xml.settingName('duplicateWindow')
|
455
|
+
xml.settingValue(value)
|
148
456
|
end
|
149
457
|
end
|
150
458
|
|
151
459
|
def add_user_fields(xml, amount, options)
|
152
460
|
xml.userFields do
|
153
|
-
if
|
461
|
+
if currency = (options[:currency] || currency(amount))
|
154
462
|
xml.userField do
|
155
|
-
xml.name
|
156
|
-
xml.value
|
463
|
+
xml.name('x_currency_code')
|
464
|
+
xml.value(currency)
|
157
465
|
end
|
158
466
|
end
|
159
|
-
if
|
467
|
+
if application_id.present?
|
160
468
|
xml.userField do
|
161
|
-
xml.name
|
162
|
-
xml.value
|
469
|
+
xml.name('x_solution_id')
|
470
|
+
xml.value(application_id)
|
163
471
|
end
|
164
472
|
end
|
165
473
|
end
|
166
474
|
end
|
167
475
|
|
168
|
-
def add_credit_card(xml, credit_card)
|
476
|
+
def add_credit_card(xml, credit_card, action)
|
169
477
|
if credit_card.track_data
|
170
478
|
add_swipe_data(xml, credit_card)
|
171
479
|
else
|
172
480
|
xml.payment do
|
173
481
|
xml.creditCard do
|
174
|
-
xml.cardNumber
|
175
|
-
xml.expirationDate
|
176
|
-
|
177
|
-
|
178
|
-
end
|
482
|
+
xml.cardNumber(truncate(credit_card.number, 16))
|
483
|
+
xml.expirationDate(format(credit_card.month, :two_digits) + '/' + format(credit_card.year, :four_digits))
|
484
|
+
xml.cardCode(credit_card.verification_value) if credit_card.valid_card_verification_value?(credit_card.verification_value, credit_card.brand)
|
485
|
+
xml.cryptogram(credit_card.payment_cryptogram) if credit_card.is_a?(NetworkTokenizationCreditCard) && action != :credit
|
179
486
|
end
|
180
487
|
end
|
181
488
|
end
|
@@ -183,7 +490,7 @@ module ActiveMerchant #:nodoc:
|
|
183
490
|
|
184
491
|
def add_swipe_data(xml, credit_card)
|
185
492
|
TRACKS.each do |key, regex|
|
186
|
-
if regex.match(credit_card.track_data)
|
493
|
+
if regex.match?(credit_card.track_data)
|
187
494
|
@valid_track_data = true
|
188
495
|
xml.payment do
|
189
496
|
xml.trackData do
|
@@ -194,21 +501,41 @@ module ActiveMerchant #:nodoc:
|
|
194
501
|
end
|
195
502
|
end
|
196
503
|
|
197
|
-
|
504
|
+
def add_token_payment_method(xml, token, options)
|
505
|
+
customer_profile_id, customer_payment_profile_id, = split_authorization(token)
|
506
|
+
customer_profile_id = options[:customer_profile_id] if options[:customer_profile_id]
|
507
|
+
customer_payment_profile_id = options[:customer_payment_profile_id] if options[:customer_payment_profile_id]
|
508
|
+
xml.customerProfileId(customer_profile_id)
|
509
|
+
xml.customerPaymentProfileId(customer_payment_profile_id)
|
510
|
+
end
|
511
|
+
|
198
512
|
def add_apple_pay_payment_token(xml, apple_pay_payment_token)
|
199
513
|
xml.payment do
|
200
514
|
xml.opaqueData do
|
201
|
-
xml.dataDescriptor
|
202
|
-
xml.dataValue
|
515
|
+
xml.dataDescriptor(APPLE_PAY_DATA_DESCRIPTOR)
|
516
|
+
xml.dataValue(Base64.strict_encode64(apple_pay_payment_token.payment_data.to_json))
|
203
517
|
end
|
204
518
|
end
|
205
519
|
end
|
206
520
|
|
207
|
-
def
|
208
|
-
return
|
209
|
-
|
210
|
-
|
211
|
-
xml.
|
521
|
+
def add_market_type_device_type(xml, payment, options)
|
522
|
+
return if payment.is_a?(String) || card_brand(payment) == 'check' || card_brand(payment) == 'apple_pay'
|
523
|
+
|
524
|
+
if valid_track_data
|
525
|
+
xml.retail do
|
526
|
+
xml.marketType(options[:market_type] || MARKET_TYPE[:retail])
|
527
|
+
xml.deviceType(options[:device_type] || DEVICE_TYPE[:wireless_pos])
|
528
|
+
end
|
529
|
+
elsif payment.manual_entry
|
530
|
+
xml.retail do
|
531
|
+
xml.marketType(options[:market_type] || MARKET_TYPE[:moto])
|
532
|
+
end
|
533
|
+
else
|
534
|
+
if options[:market_type]
|
535
|
+
xml.retail do
|
536
|
+
xml.marketType(options[:market_type])
|
537
|
+
end
|
538
|
+
end
|
212
539
|
end
|
213
540
|
end
|
214
541
|
|
@@ -219,201 +546,562 @@ module ActiveMerchant #:nodoc:
|
|
219
546
|
def add_check(xml, check)
|
220
547
|
xml.payment do
|
221
548
|
xml.bankAccount do
|
222
|
-
xml.
|
223
|
-
xml.
|
224
|
-
xml.
|
225
|
-
xml.
|
226
|
-
xml.bankName
|
227
|
-
xml.checkNumber
|
549
|
+
xml.accountType(check.account_type)
|
550
|
+
xml.routingNumber(check.routing_number)
|
551
|
+
xml.accountNumber(check.account_number)
|
552
|
+
xml.nameOnAccount(truncate(check.name, 22))
|
553
|
+
xml.bankName(check.bank_name)
|
554
|
+
xml.checkNumber(check.number)
|
228
555
|
end
|
229
556
|
end
|
230
557
|
end
|
231
558
|
|
232
559
|
def add_customer_data(xml, payment_source, options)
|
233
|
-
billing_address = options[:billing_address] || options[:address] || {}
|
234
|
-
shipping_address = options[:shipping_address] || options[:address] || {}
|
235
|
-
|
236
560
|
xml.customer do
|
237
|
-
xml.id(options[:customer]) unless empty?(options[:customer]) || options[:customer] !~ /^\
|
561
|
+
xml.id(options[:customer]) unless empty?(options[:customer]) || options[:customer] !~ /^\w+$/
|
238
562
|
xml.email(options[:email]) unless empty?(options[:email])
|
239
563
|
end
|
240
564
|
|
565
|
+
add_billing_address(xml, payment_source, options)
|
566
|
+
add_shipping_address(xml, options)
|
567
|
+
|
568
|
+
xml.customerIP(options[:ip]) unless empty?(options[:ip])
|
569
|
+
|
570
|
+
if !empty?(options.fetch(:three_d_secure, {})) || options[:authentication_indicator] || options[:cardholder_authentication_value]
|
571
|
+
xml.cardholderAuthentication do
|
572
|
+
three_d_secure = options.fetch(:three_d_secure, {})
|
573
|
+
xml.authenticationIndicator(
|
574
|
+
options[:authentication_indicator] || three_d_secure[:eci]
|
575
|
+
)
|
576
|
+
xml.cardholderAuthenticationValue(
|
577
|
+
options[:cardholder_authentication_value] || three_d_secure[:cavv]
|
578
|
+
)
|
579
|
+
end
|
580
|
+
end
|
581
|
+
end
|
582
|
+
|
583
|
+
def add_billing_address(xml, payment_source, options)
|
584
|
+
address = options[:billing_address] || options[:address] || {}
|
585
|
+
|
241
586
|
xml.billTo do
|
242
|
-
first_name, last_name = names_from(payment_source,
|
587
|
+
first_name, last_name = names_from(payment_source, address, options)
|
588
|
+
state = state_from(address, options)
|
589
|
+
full_address = "#{address[:address1]} #{address[:address2]}".strip
|
590
|
+
|
243
591
|
xml.firstName(truncate(first_name, 50)) unless empty?(first_name)
|
244
592
|
xml.lastName(truncate(last_name, 50)) unless empty?(last_name)
|
245
|
-
|
246
|
-
xml.
|
247
|
-
xml.
|
248
|
-
xml.
|
249
|
-
xml.
|
250
|
-
xml.
|
251
|
-
xml.
|
252
|
-
xml.
|
253
|
-
xml.faxNumber(truncate(billing_address[:fax], 25)) unless empty?(billing_address[:fax])
|
593
|
+
xml.company(truncate(address[:company], 50)) unless empty?(address[:company])
|
594
|
+
xml.address(truncate(full_address, 60))
|
595
|
+
xml.city(truncate(address[:city], 40))
|
596
|
+
xml.state(truncate(state, 40))
|
597
|
+
xml.zip(truncate((address[:zip] || options[:zip]), 20))
|
598
|
+
xml.country(truncate(address[:country], 60))
|
599
|
+
xml.phoneNumber(truncate(address[:phone], 25)) unless empty?(address[:phone])
|
600
|
+
xml.faxNumber(truncate(address[:fax], 25)) unless empty?(address[:fax])
|
254
601
|
end
|
602
|
+
end
|
255
603
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
xml.firstName(truncate(first_name, 50)) unless empty?(first_name)
|
260
|
-
xml.lastName(truncate(last_name, 50)) unless empty?(last_name)
|
604
|
+
def add_shipping_address(xml, options, root_node = 'shipTo')
|
605
|
+
address = options[:shipping_address] || options[:address]
|
606
|
+
return unless address
|
261
607
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
608
|
+
xml.send(root_node) do
|
609
|
+
first_name, last_name =
|
610
|
+
if address[:name]
|
611
|
+
split_names(address[:name])
|
612
|
+
else
|
613
|
+
[address[:first_name], address[:last_name]]
|
614
|
+
end
|
615
|
+
full_address = "#{address[:address1]} #{address[:address2]}".strip
|
616
|
+
|
617
|
+
xml.firstName(truncate(first_name, 50)) unless empty?(first_name)
|
618
|
+
xml.lastName(truncate(last_name, 50)) unless empty?(last_name)
|
619
|
+
xml.company(truncate(address[:company], 50)) unless empty?(address[:company])
|
620
|
+
xml.address(truncate(full_address, 60))
|
621
|
+
xml.city(truncate(address[:city], 40))
|
622
|
+
xml.state(truncate(address[:state], 40))
|
623
|
+
xml.zip(truncate(address[:zip], 20))
|
624
|
+
xml.country(truncate(address[:country], 60))
|
269
625
|
end
|
626
|
+
end
|
270
627
|
|
271
|
-
|
628
|
+
def add_ship_from_address(xml, options, root_node = 'shipFrom')
|
629
|
+
address = options[:ship_from_address]
|
630
|
+
return unless address
|
272
631
|
|
273
|
-
xml.
|
274
|
-
xml.
|
275
|
-
xml.
|
632
|
+
xml.send(root_node) do
|
633
|
+
xml.zip(truncate(address[:zip], 20)) unless empty?(address[:zip])
|
634
|
+
xml.country(truncate(address[:country], 60)) unless empty?(address[:country])
|
276
635
|
end
|
277
636
|
end
|
278
637
|
|
279
638
|
def add_order_id(xml, options)
|
280
|
-
xml.refId
|
639
|
+
xml.refId(truncate(options[:order_id], 20))
|
281
640
|
end
|
282
641
|
|
283
|
-
def add_invoice(xml, options)
|
642
|
+
def add_invoice(xml, transaction_type, options)
|
284
643
|
xml.order do
|
285
|
-
xml.invoiceNumber
|
286
|
-
xml.description
|
644
|
+
xml.invoiceNumber(truncate(options[:order_id], 20))
|
645
|
+
xml.description(truncate(options[:description], 255))
|
646
|
+
xml.purchaseOrderNumber(options[:po_number]) if options[:po_number] && transaction_type.start_with?('profileTrans')
|
647
|
+
xml.summaryCommodityCode(truncate(options[:summary_commodity_code], 4)) if options[:summary_commodity_code] && !transaction_type.start_with?('profileTrans')
|
648
|
+
end
|
649
|
+
|
650
|
+
# Authorize.net API requires lineItems to be placed directly after order tag
|
651
|
+
if options[:line_items]
|
652
|
+
xml.lineItems do
|
653
|
+
options[:line_items].each do |line_item|
|
654
|
+
xml.lineItem do
|
655
|
+
line_item.each do |key, value|
|
656
|
+
xml.send(camel_case_lower(key), value)
|
657
|
+
end
|
658
|
+
end
|
659
|
+
end
|
660
|
+
end
|
661
|
+
end
|
662
|
+
end
|
663
|
+
|
664
|
+
def add_tax_fields(xml, options)
|
665
|
+
tax = options[:tax]
|
666
|
+
if tax.is_a?(Hash)
|
667
|
+
xml.tax do
|
668
|
+
xml.amount(amount(tax[:amount].to_i))
|
669
|
+
xml.name(tax[:name])
|
670
|
+
xml.description(tax[:description])
|
671
|
+
end
|
672
|
+
end
|
673
|
+
end
|
674
|
+
|
675
|
+
def add_duty_fields(xml, options)
|
676
|
+
duty = options[:duty]
|
677
|
+
if duty.is_a?(Hash)
|
678
|
+
xml.duty do
|
679
|
+
xml.amount(amount(duty[:amount].to_i))
|
680
|
+
xml.name(duty[:name])
|
681
|
+
xml.description(duty[:description])
|
682
|
+
end
|
683
|
+
end
|
684
|
+
end
|
685
|
+
|
686
|
+
def add_shipping_fields(xml, options)
|
687
|
+
shipping = options[:shipping]
|
688
|
+
if shipping.is_a?(Hash)
|
689
|
+
xml.shipping do
|
690
|
+
xml.amount(amount(shipping[:amount].to_i))
|
691
|
+
xml.name(shipping[:name])
|
692
|
+
xml.description(shipping[:description])
|
693
|
+
end
|
694
|
+
end
|
695
|
+
end
|
696
|
+
|
697
|
+
def add_tax_exempt_status(xml, options)
|
698
|
+
xml.taxExempt(options[:tax_exempt]) if options[:tax_exempt]
|
699
|
+
end
|
700
|
+
|
701
|
+
def add_po_number(xml, options)
|
702
|
+
xml.poNumber(options[:po_number]) if options[:po_number]
|
703
|
+
end
|
704
|
+
|
705
|
+
def add_extra_options_for_cim(xml, options)
|
706
|
+
xml.extraOptions("x_delim_char=#{options[:delimiter]}") if options[:delimiter]
|
707
|
+
end
|
708
|
+
|
709
|
+
def add_processing_options(xml, options)
|
710
|
+
return unless options[:stored_credential]
|
711
|
+
|
712
|
+
xml.processingOptions do
|
713
|
+
if options[:stored_credential][:initial_transaction] && options[:stored_credential][:reason_type] == 'recurring'
|
714
|
+
xml.isFirstRecurringPayment 'true'
|
715
|
+
elsif options[:stored_credential][:initial_transaction]
|
716
|
+
xml.isFirstSubsequentAuth 'true'
|
717
|
+
elsif options[:stored_credential][:initiator] == 'cardholder'
|
718
|
+
xml.isStoredCredentials 'true'
|
719
|
+
else
|
720
|
+
xml.isSubsequentAuth 'true'
|
721
|
+
end
|
722
|
+
end
|
723
|
+
end
|
724
|
+
|
725
|
+
def add_subsequent_auth_information(xml, options)
|
726
|
+
return unless options.dig(:stored_credential, :initiator) == 'merchant'
|
727
|
+
|
728
|
+
xml.subsequentAuthInformation do
|
729
|
+
xml.reason options[:stored_credential_reason_type_override] if options[:stored_credential_reason_type_override]
|
730
|
+
xml.originalNetworkTransId options[:stored_credential][:network_transaction_id] if options[:stored_credential][:network_transaction_id]
|
731
|
+
end
|
732
|
+
end
|
733
|
+
|
734
|
+
def create_customer_payment_profile(credit_card, options)
|
735
|
+
commit(:cim_store_update, options) do |xml|
|
736
|
+
xml.customerProfileId options[:customer_profile_id]
|
737
|
+
xml.paymentProfile do
|
738
|
+
add_billing_address(xml, credit_card, options)
|
739
|
+
xml.payment do
|
740
|
+
xml.creditCard do
|
741
|
+
xml.cardNumber(truncate(credit_card.number, 16))
|
742
|
+
xml.expirationDate(format(credit_card.year, :four_digits) + '-' + format(credit_card.month, :two_digits))
|
743
|
+
xml.cardCode(credit_card.verification_value) if credit_card.verification_value
|
744
|
+
end
|
745
|
+
end
|
746
|
+
end
|
747
|
+
end
|
748
|
+
end
|
749
|
+
|
750
|
+
def create_customer_profile(credit_card, options)
|
751
|
+
commit(:cim_store, options) do |xml|
|
752
|
+
xml.profile do
|
753
|
+
xml.merchantCustomerId(truncate(options[:merchant_customer_id], 20) || SecureRandom.hex(10))
|
754
|
+
xml.description(truncate(options[:description], 255)) unless empty?(options[:description])
|
755
|
+
xml.email(options[:email]) unless empty?(options[:email])
|
756
|
+
|
757
|
+
xml.paymentProfiles do
|
758
|
+
xml.customerType('individual')
|
759
|
+
add_billing_address(xml, credit_card, options)
|
760
|
+
add_shipping_address(xml, options, 'shipToList')
|
761
|
+
xml.payment do
|
762
|
+
xml.creditCard do
|
763
|
+
xml.cardNumber(truncate(credit_card.number, 16))
|
764
|
+
xml.expirationDate(format(credit_card.year, :four_digits) + '-' + format(credit_card.month, :two_digits))
|
765
|
+
xml.cardCode(credit_card.verification_value) if credit_card.verification_value
|
766
|
+
end
|
767
|
+
end
|
768
|
+
end
|
769
|
+
end
|
770
|
+
end
|
771
|
+
end
|
772
|
+
|
773
|
+
def delete_customer_profile(customer_profile_id)
|
774
|
+
commit(:cim_store_delete_customer, options) do |xml|
|
775
|
+
xml.customerProfileId(customer_profile_id)
|
287
776
|
end
|
288
777
|
end
|
289
778
|
|
290
779
|
def names_from(payment_source, address, options)
|
291
|
-
if payment_source && !payment_source.is_a?(PaymentToken)
|
292
|
-
first_name, last_name = (address[:name]
|
780
|
+
if payment_source && !payment_source.is_a?(PaymentToken) && !payment_source.is_a?(String)
|
781
|
+
first_name, last_name = split_names(address[:name])
|
293
782
|
[(payment_source.first_name || first_name), (payment_source.last_name || last_name)]
|
294
783
|
else
|
295
784
|
[options[:first_name], options[:last_name]]
|
296
785
|
end
|
297
786
|
end
|
298
787
|
|
299
|
-
def
|
300
|
-
|
301
|
-
|
788
|
+
def state_from(address, options)
|
789
|
+
if %w[US CA].include?(address[:country])
|
790
|
+
address[:state] || 'NC'
|
791
|
+
else
|
792
|
+
address[:state] || 'n/a'
|
793
|
+
end
|
794
|
+
end
|
795
|
+
|
796
|
+
def subsequent_recurring_transaction?(options)
|
797
|
+
options.dig(:stored_credential, :reason_type) == 'recurring' && !options.dig(:stored_credential, :initial_transaction)
|
798
|
+
end
|
799
|
+
|
800
|
+
def headers
|
801
|
+
{ 'Content-Type' => 'text/xml' }
|
802
|
+
end
|
803
|
+
|
804
|
+
def url
|
805
|
+
test? ? test_url : live_url
|
806
|
+
end
|
807
|
+
|
808
|
+
def parse(action, raw_response, options = {})
|
809
|
+
if cim_action?(action) || action == :verify_credentials
|
810
|
+
parse_cim(raw_response, options)
|
811
|
+
else
|
812
|
+
parse_normal(action, raw_response)
|
813
|
+
end
|
814
|
+
end
|
302
815
|
|
303
|
-
|
816
|
+
def commit(action, options = {}, &payload)
|
817
|
+
raw_response = ssl_post(url, post_data(action, &payload), headers)
|
818
|
+
response = parse(action, raw_response, options)
|
819
|
+
|
820
|
+
avs_result_code = response[:avs_result_code].upcase if response[:avs_result_code]
|
821
|
+
avs_result = AVSResult.new(code: STANDARD_AVS_CODE_MAPPING[avs_result_code])
|
304
822
|
cvv_result = CVVResult.new(response[:card_code])
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
823
|
+
if using_live_gateway_in_test_mode?(response)
|
824
|
+
Response.new(false, 'Using a live Authorize.net account in Test Mode is not permitted.')
|
825
|
+
else
|
826
|
+
Response.new(
|
827
|
+
success_from(action, response),
|
828
|
+
message_from(action, response, avs_result, cvv_result),
|
829
|
+
response,
|
830
|
+
authorization: authorization_from(action, response),
|
831
|
+
test: test?,
|
832
|
+
avs_result: avs_result,
|
833
|
+
cvv_result: cvv_result,
|
834
|
+
fraud_review: fraud_review?(response),
|
835
|
+
error_code: map_error_code(response[:response_code], response[:response_reason_code])
|
836
|
+
)
|
837
|
+
end
|
838
|
+
end
|
839
|
+
|
840
|
+
def cim_action?(action)
|
841
|
+
action.to_s.start_with?('cim')
|
842
|
+
end
|
843
|
+
|
844
|
+
def post_data(action)
|
845
|
+
Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
|
846
|
+
xml.send(root_for(action), 'xmlns' => 'AnetApi/xml/v1/schema/AnetApiSchema.xsd') do
|
847
|
+
add_authentication(xml)
|
324
848
|
yield(xml)
|
325
849
|
end
|
326
850
|
end.to_xml(indent: 0)
|
327
851
|
end
|
328
852
|
|
329
|
-
def
|
853
|
+
def root_for(action)
|
854
|
+
if action == :cim_store
|
855
|
+
'createCustomerProfileRequest'
|
856
|
+
elsif action == :cim_store_update
|
857
|
+
'createCustomerPaymentProfileRequest'
|
858
|
+
elsif action == :cim_store_delete_customer
|
859
|
+
'deleteCustomerProfileRequest'
|
860
|
+
elsif action == :verify_credentials
|
861
|
+
'authenticateTestRequest'
|
862
|
+
elsif cim_action?(action)
|
863
|
+
'createCustomerProfileTransactionRequest'
|
864
|
+
else
|
865
|
+
'createTransactionRequest'
|
866
|
+
end
|
867
|
+
end
|
868
|
+
|
869
|
+
def add_authentication(xml)
|
870
|
+
xml.merchantAuthentication do
|
871
|
+
xml.name(@options[:login])
|
872
|
+
xml.transactionKey(@options[:password])
|
873
|
+
end
|
874
|
+
end
|
875
|
+
|
876
|
+
def parse_normal(action, body)
|
330
877
|
doc = Nokogiri::XML(body)
|
331
878
|
doc.remove_namespaces!
|
332
879
|
|
333
|
-
response = {action: action}
|
880
|
+
response = { action: action }
|
334
881
|
|
335
|
-
response[:response_code] = if(element = doc.at_xpath(
|
336
|
-
|
337
|
-
|
882
|
+
response[:response_code] = if (element = doc.at_xpath('//transactionResponse/responseCode'))
|
883
|
+
empty?(element.content) ? nil : element.content.to_i
|
884
|
+
end
|
338
885
|
|
339
|
-
if(element = doc.at_xpath(
|
340
|
-
response[:response_reason_code] = element.at_xpath(
|
341
|
-
response[:response_reason_text] = element.at_xpath(
|
342
|
-
elsif(element = doc.at_xpath(
|
343
|
-
response[:response_reason_code] = element.at_xpath(
|
344
|
-
response[:response_reason_text] = element.at_xpath(
|
345
|
-
elsif(element = doc.at_xpath(
|
346
|
-
response[:response_reason_code] = element.at_xpath(
|
347
|
-
response[:response_reason_text] = element.at_xpath(
|
886
|
+
if (element = doc.at_xpath('//errors/error'))
|
887
|
+
response[:response_reason_code] = element.at_xpath('errorCode').content[/0*(\d+)$/, 1]
|
888
|
+
response[:response_reason_text] = element.at_xpath('errorText').content.chomp('.')
|
889
|
+
elsif (element = doc.at_xpath('//transactionResponse/messages/message'))
|
890
|
+
response[:response_reason_code] = element.at_xpath('code').content[/0*(\d+)$/, 1]
|
891
|
+
response[:response_reason_text] = element.at_xpath('description').content.chomp('.')
|
892
|
+
elsif (element = doc.at_xpath('//messages/message'))
|
893
|
+
response[:response_reason_code] = element.at_xpath('code').content[/0*(\d+)$/, 1]
|
894
|
+
response[:response_reason_text] = element.at_xpath('text').content.chomp('.')
|
348
895
|
else
|
349
896
|
response[:response_reason_code] = nil
|
350
|
-
response[:response_reason_text] =
|
897
|
+
response[:response_reason_text] = ''
|
351
898
|
end
|
352
899
|
|
353
|
-
response[:avs_result_code] =
|
354
|
-
(
|
355
|
-
|
900
|
+
response[:avs_result_code] =
|
901
|
+
if (element = doc.at_xpath('//avsResultCode'))
|
902
|
+
empty?(element.content) ? nil : element.content
|
903
|
+
end
|
356
904
|
|
357
|
-
response[:transaction_id] =
|
358
|
-
|
359
|
-
|
905
|
+
response[:transaction_id] =
|
906
|
+
if element = doc.at_xpath('//transId')
|
907
|
+
empty?(element.content) ? nil : element.content
|
908
|
+
end
|
360
909
|
|
361
|
-
response[:card_code] =
|
362
|
-
|
363
|
-
|
910
|
+
response[:card_code] =
|
911
|
+
if element = doc.at_xpath('//cvvResultCode')
|
912
|
+
empty?(element.content) ? nil : element.content
|
913
|
+
end
|
364
914
|
|
365
|
-
response[:authorization_code] =
|
366
|
-
|
367
|
-
|
915
|
+
response[:authorization_code] =
|
916
|
+
if element = doc.at_xpath('//authCode')
|
917
|
+
empty?(element.content) ? nil : element.content
|
918
|
+
end
|
368
919
|
|
369
|
-
response[:cardholder_authentication_code] =
|
370
|
-
|
371
|
-
|
920
|
+
response[:cardholder_authentication_code] =
|
921
|
+
if element = doc.at_xpath('//cavvResultCode')
|
922
|
+
empty?(element.content) ? nil : element.content
|
923
|
+
end
|
924
|
+
|
925
|
+
response[:account_number] =
|
926
|
+
if element = doc.at_xpath('//accountNumber')
|
927
|
+
empty?(element.content) ? nil : element.content[-4..-1]
|
928
|
+
end
|
929
|
+
|
930
|
+
response[:test_request] =
|
931
|
+
if element = doc.at_xpath('//testRequest')
|
932
|
+
empty?(element.content) ? nil : element.content
|
933
|
+
end
|
934
|
+
|
935
|
+
response[:full_response_code] =
|
936
|
+
if element = doc.at_xpath('//messages/message/code')
|
937
|
+
empty?(element.content) ? nil : element.content
|
938
|
+
end
|
939
|
+
|
940
|
+
response[:network_trans_id] =
|
941
|
+
if element = doc.at_xpath('//networkTransId')
|
942
|
+
empty?(element.content) ? nil : element.content
|
943
|
+
end
|
944
|
+
|
945
|
+
response
|
946
|
+
end
|
947
|
+
|
948
|
+
def parse_cim(body, options)
|
949
|
+
response = {}
|
372
950
|
|
373
|
-
|
374
|
-
|
951
|
+
doc = Nokogiri::XML(body).remove_namespaces!
|
952
|
+
|
953
|
+
if element = doc.at_xpath('//messages/message')
|
954
|
+
response[:message_code] = element.at_xpath('code').content[/0*(\d+)$/, 1]
|
955
|
+
response[:message_text] = element.at_xpath('text').content.chomp('.')
|
375
956
|
end
|
376
957
|
|
958
|
+
response[:result_code] =
|
959
|
+
if element = doc.at_xpath('//messages/resultCode')
|
960
|
+
empty?(element.content) ? nil : element.content
|
961
|
+
end
|
962
|
+
|
963
|
+
response[:test_request] =
|
964
|
+
if element = doc.at_xpath('//testRequest')
|
965
|
+
empty?(element.content) ? nil : element.content
|
966
|
+
end
|
967
|
+
|
968
|
+
response[:customer_profile_id] =
|
969
|
+
if element = doc.at_xpath('//customerProfileId')
|
970
|
+
empty?(element.content) ? nil : element.content
|
971
|
+
end
|
972
|
+
|
973
|
+
response[:customer_payment_profile_id] =
|
974
|
+
if element = doc.at_xpath('//customerPaymentProfileIdList/numericString')
|
975
|
+
empty?(element.content) ? nil : element.content
|
976
|
+
end
|
977
|
+
|
978
|
+
response[:customer_payment_profile_id] =
|
979
|
+
if element = doc.at_xpath('//customerPaymentProfileIdList/numericString') ||
|
980
|
+
doc.at_xpath('//customerPaymentProfileId')
|
981
|
+
empty?(element.content) ? nil : element.content
|
982
|
+
end
|
983
|
+
|
984
|
+
response[:direct_response] =
|
985
|
+
if element = doc.at_xpath('//directResponse')
|
986
|
+
empty?(element.content) ? nil : element.content
|
987
|
+
end
|
988
|
+
|
989
|
+
response.merge!(parse_direct_response_elements(response, options))
|
990
|
+
|
377
991
|
response
|
378
992
|
end
|
379
993
|
|
380
|
-
def success_from(response)
|
381
|
-
(
|
382
|
-
response[:
|
383
|
-
|
384
|
-
|
994
|
+
def success_from(action, response)
|
995
|
+
if cim?(action) || (action == :verify_credentials)
|
996
|
+
response[:result_code] == 'Ok'
|
997
|
+
else
|
998
|
+
[APPROVED, FRAUD_REVIEW].include?(response[:response_code]) && TRANSACTION_ALREADY_ACTIONED.exclude?(response[:response_reason_code])
|
999
|
+
end
|
385
1000
|
end
|
386
1001
|
|
387
|
-
def message_from(response, avs_result, cvv_result)
|
1002
|
+
def message_from(action, response, avs_result, cvv_result)
|
388
1003
|
if response[:response_code] == DECLINED
|
389
1004
|
if CARD_CODE_ERRORS.include?(cvv_result.code)
|
390
1005
|
return cvv_result.message
|
391
|
-
elsif
|
1006
|
+
elsif AVS_REASON_CODES.include?(response[:response_reason_code]) && AVS_ERRORS.include?(avs_result.code)
|
392
1007
|
return avs_result.message
|
393
1008
|
end
|
394
1009
|
end
|
395
1010
|
|
396
|
-
response[:response_reason_text]
|
1011
|
+
response[:response_reason_text] || response[:message_text]
|
397
1012
|
end
|
398
1013
|
|
399
|
-
def authorization_from(response)
|
400
|
-
|
1014
|
+
def authorization_from(action, response)
|
1015
|
+
if cim?(action)
|
1016
|
+
[response[:customer_profile_id], response[:customer_payment_profile_id], action].join('#')
|
1017
|
+
else
|
1018
|
+
[response[:transaction_id], response[:account_number], action].join('#')
|
1019
|
+
end
|
401
1020
|
end
|
402
1021
|
|
403
1022
|
def split_authorization(authorization)
|
404
|
-
|
405
|
-
|
1023
|
+
authorization.split('#')
|
1024
|
+
end
|
1025
|
+
|
1026
|
+
def cim?(action)
|
1027
|
+
(action == :cim_store) || (action == :cim_store_update) || (action == :cim_store_delete_customer)
|
1028
|
+
end
|
1029
|
+
|
1030
|
+
def transaction_id_from(authorization)
|
1031
|
+
transaction_id, = split_authorization(authorization)
|
1032
|
+
transaction_id
|
406
1033
|
end
|
407
1034
|
|
408
1035
|
def fraud_review?(response)
|
409
1036
|
(response[:response_code] == FRAUD_REVIEW)
|
410
1037
|
end
|
411
1038
|
|
412
|
-
def
|
413
|
-
|
414
|
-
|
1039
|
+
def using_live_gateway_in_test_mode?(response)
|
1040
|
+
!test? && response[:test_request] == '1'
|
1041
|
+
end
|
1042
|
+
|
1043
|
+
def map_error_code(response_code, response_reason_code)
|
1044
|
+
STANDARD_ERROR_CODE_MAPPING["#{response_code}#{response_reason_code}"]
|
415
1045
|
end
|
416
1046
|
|
1047
|
+
def auth_was_for_cim?(authorization)
|
1048
|
+
_, _, action = split_authorization(authorization)
|
1049
|
+
action && cim_action?(action)
|
1050
|
+
end
|
1051
|
+
|
1052
|
+
def parse_direct_response_elements(response, options)
|
1053
|
+
params = response[:direct_response]&.tr('"', '')
|
1054
|
+
return {} unless params
|
1055
|
+
|
1056
|
+
parts = params.split(options[:delimiter] || ',')
|
1057
|
+
{
|
1058
|
+
response_code: parts[0].to_i,
|
1059
|
+
response_subcode: parts[1],
|
1060
|
+
response_reason_code: parts[2],
|
1061
|
+
response_reason_text: parts[3],
|
1062
|
+
approval_code: parts[4],
|
1063
|
+
avs_result_code: parts[5],
|
1064
|
+
transaction_id: parts[6],
|
1065
|
+
invoice_number: parts[7],
|
1066
|
+
order_description: parts[8],
|
1067
|
+
amount: parts[9],
|
1068
|
+
method: parts[10],
|
1069
|
+
transaction_type: parts[11],
|
1070
|
+
customer_id: parts[12],
|
1071
|
+
first_name: parts[13],
|
1072
|
+
last_name: parts[14],
|
1073
|
+
company: parts[15],
|
1074
|
+
address: parts[16],
|
1075
|
+
city: parts[17],
|
1076
|
+
state: parts[18],
|
1077
|
+
zip_code: parts[19],
|
1078
|
+
country: parts[20],
|
1079
|
+
phone: parts[21],
|
1080
|
+
fax: parts[22],
|
1081
|
+
email_address: parts[23],
|
1082
|
+
ship_to_first_name: parts[24],
|
1083
|
+
ship_to_last_name: parts[25],
|
1084
|
+
ship_to_company: parts[26],
|
1085
|
+
ship_to_address: parts[27],
|
1086
|
+
ship_to_city: parts[28],
|
1087
|
+
ship_to_state: parts[29],
|
1088
|
+
ship_to_zip_code: parts[30],
|
1089
|
+
ship_to_country: parts[31],
|
1090
|
+
tax: parts[32],
|
1091
|
+
duty: parts[33],
|
1092
|
+
freight: parts[34],
|
1093
|
+
tax_exempt: parts[35],
|
1094
|
+
purchase_order_number: parts[36],
|
1095
|
+
md5_hash: parts[37],
|
1096
|
+
card_code: parts[38],
|
1097
|
+
cardholder_authentication_verification_response: parts[39],
|
1098
|
+
account_number: parts[50] || '',
|
1099
|
+
card_type: parts[51] || '',
|
1100
|
+
split_tender_id: parts[52] || '',
|
1101
|
+
requested_amount: parts[53] || '',
|
1102
|
+
balance_on_card: parts[54] || ''
|
1103
|
+
}
|
1104
|
+
end
|
417
1105
|
end
|
418
1106
|
end
|
419
1107
|
end
|