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
@@ -0,0 +1,623 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module ActiveMerchant
|
4
|
+
module Billing
|
5
|
+
class BlueSnapGateway < Gateway
|
6
|
+
self.test_url = 'https://sandbox.bluesnap.com/services/2'
|
7
|
+
self.live_url = 'https://ws.bluesnap.com/services/2'
|
8
|
+
self.supported_countries = %w(US CA GB AT BE BG HR CY CZ DK EE FI FR DE GR HU IE IT LV LT LU MT NL PL PT RO SK SI ES SE AR BO BR BZ CL CO CR DO EC GF GP GT HN HT MF MQ MX NI PA PE PR PY SV UY VE)
|
9
|
+
|
10
|
+
self.default_currency = 'USD'
|
11
|
+
self.supported_cardtypes = %i[visa master american_express discover jcb diners_club maestro naranja cabal]
|
12
|
+
self.currencies_without_fractions = %w(BYR CLP ILS JPY KRW VND XOF)
|
13
|
+
self.currencies_with_three_decimal_places = %w(BHD JOD KWD OMR TND)
|
14
|
+
|
15
|
+
self.homepage_url = 'https://home.bluesnap.com/'
|
16
|
+
self.display_name = 'BlueSnap'
|
17
|
+
|
18
|
+
TRANSACTIONS = {
|
19
|
+
purchase: 'AUTH_CAPTURE',
|
20
|
+
authorize: 'AUTH_ONLY',
|
21
|
+
capture: 'CAPTURE',
|
22
|
+
void: 'AUTH_REVERSAL',
|
23
|
+
refund: 'REFUND'
|
24
|
+
}
|
25
|
+
|
26
|
+
CVC_CODE_TRANSLATOR = {
|
27
|
+
'MA' => 'M',
|
28
|
+
'NC' => 'U',
|
29
|
+
'ND' => 'P',
|
30
|
+
'NM' => 'N',
|
31
|
+
'NP' => 'S'
|
32
|
+
}
|
33
|
+
|
34
|
+
AVS_CODE_TRANSLATOR = {
|
35
|
+
'line1: U, zip: U, name: U' => 'I',
|
36
|
+
'line1: U, zip: U, name: M' => 'I',
|
37
|
+
'line1: U, zip: U, name: N' => 'I',
|
38
|
+
'line1: U, zip: M, name: U' => 'P',
|
39
|
+
'line1: U, zip: M, name: M' => 'P',
|
40
|
+
'line1: U, zip: M, name: N' => 'F',
|
41
|
+
'line1: U, zip: N, name: U' => 'O',
|
42
|
+
'line1: U, zip: N, name: M' => 'O',
|
43
|
+
'line1: U, zip: N, name: N' => 'O',
|
44
|
+
'line1: M, zip: U, name: U' => 'B',
|
45
|
+
'line1: M, zip: U, name: M' => 'B',
|
46
|
+
'line1: M, zip: U, name: N' => 'T',
|
47
|
+
'line1: M, zip: M, name: U' => 'M',
|
48
|
+
'line1: M, zip: M, name: M' => 'V',
|
49
|
+
'line1: M, zip: M, name: N' => 'H',
|
50
|
+
'line1: M, zip: N, name: U' => 'A',
|
51
|
+
'line1: M, zip: N, name: M' => 'O',
|
52
|
+
'line1: M, zip: N, name: N' => 'A',
|
53
|
+
'line1: N, zip: U, name: U' => 'C',
|
54
|
+
'line1: N, zip: U, name: M' => 'C',
|
55
|
+
'line1: N, zip: U, name: N' => 'C',
|
56
|
+
'line1: N, zip: M, name: U' => 'W',
|
57
|
+
'line1: N, zip: M, name: M' => 'L',
|
58
|
+
'line1: N, zip: M, name: N' => 'W',
|
59
|
+
'line1: N, zip: N, name: U' => 'N',
|
60
|
+
'line1: N, zip: N, name: M' => 'K',
|
61
|
+
'line1: N, zip: N, name: N' => 'N'
|
62
|
+
}
|
63
|
+
|
64
|
+
BANK_ACCOUNT_TYPE_MAPPING = {
|
65
|
+
'personal_checking' => 'CONSUMER_CHECKING',
|
66
|
+
'personal_savings' => 'CONSUMER_SAVINGS',
|
67
|
+
'business_checking' => 'CORPORATE_CHECKING',
|
68
|
+
'business_savings' => 'CORPORATE_SAVINGS'
|
69
|
+
}
|
70
|
+
|
71
|
+
STATE_CODE_COUNTRIES = %w(US CA)
|
72
|
+
|
73
|
+
def initialize(options = {})
|
74
|
+
requires!(options, :api_username, :api_password)
|
75
|
+
super
|
76
|
+
end
|
77
|
+
|
78
|
+
def purchase(money, payment_method, options = {})
|
79
|
+
payment_method_details = PaymentMethodDetails.new(payment_method)
|
80
|
+
|
81
|
+
commit(:purchase, options, :post, payment_method_details) do |doc|
|
82
|
+
if payment_method_details.alt_transaction?
|
83
|
+
add_alt_transaction_purchase(doc, money, payment_method_details, options)
|
84
|
+
else
|
85
|
+
add_auth_purchase(doc, money, payment_method, options)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def authorize(money, payment_method, options = {})
|
91
|
+
commit(:authorize, options) do |doc|
|
92
|
+
add_auth_purchase(doc, money, payment_method, options)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def capture(money, authorization, options = {})
|
97
|
+
commit(:capture, options, :put) do |doc|
|
98
|
+
add_authorization(doc, authorization)
|
99
|
+
add_order(doc, options)
|
100
|
+
add_amount(doc, money, options) if options[:include_capture_amount] == true
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def refund(money, authorization, options = {})
|
105
|
+
options[:endpoint] = options[:merchant_transaction_id] ? "/refund/merchant/#{options[:merchant_transaction_id]}" : "/refund/#{authorization}"
|
106
|
+
commit(:refund, options, :post) do |doc|
|
107
|
+
add_amount(doc, money, options) if money
|
108
|
+
%i[reason cancel_subscription tax_amount].each { |field| send_when_present(doc, field, options) }
|
109
|
+
add_metadata(doc, options)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def void(authorization, options = {})
|
114
|
+
commit(:void, options, :put) do |doc|
|
115
|
+
add_authorization(doc, authorization)
|
116
|
+
add_order(doc, options)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def verify(payment_method, options = {})
|
121
|
+
authorize(0, payment_method, options)
|
122
|
+
end
|
123
|
+
|
124
|
+
def store(payment_method, options = {})
|
125
|
+
payment_method_details = PaymentMethodDetails.new(payment_method)
|
126
|
+
|
127
|
+
commit(:store, options, :post, payment_method_details) do |doc|
|
128
|
+
add_personal_info(doc, payment_method, options)
|
129
|
+
add_echeck_company(doc, payment_method) if payment_method_details.check?
|
130
|
+
doc.send('payment-sources') do
|
131
|
+
payment_method_details.check? ? store_echeck(doc, payment_method) : store_credit_card(doc, payment_method)
|
132
|
+
end
|
133
|
+
add_order(doc, options)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def store_credit_card(doc, payment_method)
|
138
|
+
doc.send('credit-card-info') do
|
139
|
+
add_credit_card(doc, payment_method)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def store_echeck(doc, payment_method)
|
144
|
+
doc.send('ecp-info') do
|
145
|
+
doc.send('ecp') do
|
146
|
+
add_echeck(doc, payment_method)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def verify_credentials
|
152
|
+
begin
|
153
|
+
ssl_get(url.to_s, headers(options))
|
154
|
+
rescue ResponseError => e
|
155
|
+
return false if e.response.code.to_i == 401
|
156
|
+
end
|
157
|
+
|
158
|
+
true
|
159
|
+
end
|
160
|
+
|
161
|
+
def supports_scrubbing?
|
162
|
+
true
|
163
|
+
end
|
164
|
+
|
165
|
+
def scrub(transcript)
|
166
|
+
transcript.
|
167
|
+
gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
|
168
|
+
gsub(%r((<card-number>).+(</card-number>)), '\1[FILTERED]\2').
|
169
|
+
gsub(%r((<security-code>).+(</security-code>)), '\1[FILTERED]\2').
|
170
|
+
gsub(%r((<(?:public-)?account-number>).+(</(?:public-)?account-number>)), '\1[FILTERED]\2').
|
171
|
+
gsub(%r((<(?:public-)?routing-number>).+(</(?:public-)?routing-number>)), '\1[FILTERED]\2')
|
172
|
+
end
|
173
|
+
|
174
|
+
private
|
175
|
+
|
176
|
+
def add_auth_purchase(doc, money, payment_method, options)
|
177
|
+
doc.send('recurring-transaction', options[:recurring] ? 'RECURRING' : 'ECOMMERCE')
|
178
|
+
add_order(doc, options)
|
179
|
+
doc.send('store-card', options[:store_card] || false)
|
180
|
+
add_amount(doc, money, options)
|
181
|
+
add_fraud_info(doc, payment_method, options)
|
182
|
+
|
183
|
+
if payment_method.is_a?(String)
|
184
|
+
doc.send('vaulted-shopper-id', payment_method)
|
185
|
+
else
|
186
|
+
doc.send('card-holder-info') do
|
187
|
+
add_personal_info(doc, payment_method, options)
|
188
|
+
end
|
189
|
+
add_credit_card(doc, payment_method)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def add_amount(doc, money, options)
|
194
|
+
currency = options[:currency] || currency(money)
|
195
|
+
doc.amount(localized_amount(money, currency))
|
196
|
+
doc.currency(currency)
|
197
|
+
end
|
198
|
+
|
199
|
+
def add_personal_info(doc, payment_method, options)
|
200
|
+
doc.send('first-name', payment_method.first_name)
|
201
|
+
doc.send('last-name', payment_method.last_name)
|
202
|
+
doc.send('personal-identification-number', options[:personal_identification_number]) if options[:personal_identification_number]
|
203
|
+
doc.email(options[:email]) if options[:email]
|
204
|
+
doc.phone(options[:phone_number]) if options[:phone_number]
|
205
|
+
add_address(doc, options)
|
206
|
+
end
|
207
|
+
|
208
|
+
def add_credit_card(doc, card)
|
209
|
+
doc.send('credit-card') do
|
210
|
+
doc.send('card-number', card.number)
|
211
|
+
doc.send('security-code', card.verification_value)
|
212
|
+
doc.send('expiration-month', card.month)
|
213
|
+
doc.send('expiration-year', card.year)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
def add_metadata(doc, options)
|
218
|
+
transaction_meta_data = options[:transaction_meta_data] || []
|
219
|
+
return if transaction_meta_data.empty? && !options[:description]
|
220
|
+
|
221
|
+
doc.send('transaction-meta-data') do
|
222
|
+
# ensure backwards compatibility for calls expecting :description
|
223
|
+
# to become meta-data fields.
|
224
|
+
if options[:description]
|
225
|
+
doc.send('meta-data') do
|
226
|
+
doc.send('meta-key', 'description')
|
227
|
+
doc.send('meta-value', truncate(options[:description], 500))
|
228
|
+
doc.send('meta-description', 'Description')
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
# https://developers.bluesnap.com/v8976-XML/docs/meta-data
|
233
|
+
transaction_meta_data.each do |entry|
|
234
|
+
doc.send('meta-data') do
|
235
|
+
doc.send('meta-key', truncate(entry[:meta_key], 40))
|
236
|
+
doc.send('meta-value', truncate(entry[:meta_value], 500))
|
237
|
+
doc.send('meta-description', truncate(entry[:meta_description], 40))
|
238
|
+
doc.send('is-visible', truncate(entry[:meta_is_visible], 5))
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
def add_order(doc, options)
|
245
|
+
doc.send('merchant-transaction-id', truncate(options[:order_id], 50)) if options[:order_id]
|
246
|
+
doc.send('soft-descriptor', options[:soft_descriptor]) if options[:soft_descriptor]
|
247
|
+
add_metadata(doc, options)
|
248
|
+
add_3ds(doc, options[:three_d_secure]) if options[:three_d_secure]
|
249
|
+
add_level_3_data(doc, options)
|
250
|
+
end
|
251
|
+
|
252
|
+
def add_address(doc, options)
|
253
|
+
address = options[:billing_address]
|
254
|
+
return unless address
|
255
|
+
|
256
|
+
doc.country(address[:country]) if address[:country]
|
257
|
+
doc.state(address[:state]) if address[:state] && STATE_CODE_COUNTRIES.include?(address[:country])
|
258
|
+
doc.address(address[:address1]) if address[:address1]
|
259
|
+
doc.address2(address[:address2]) if address[:address2]
|
260
|
+
doc.city(address[:city]) if address[:city]
|
261
|
+
doc.zip(address[:zip]) if address[:zip]
|
262
|
+
end
|
263
|
+
|
264
|
+
def add_3ds(doc, three_d_secure_options)
|
265
|
+
eci = three_d_secure_options[:eci]
|
266
|
+
cavv = three_d_secure_options[:cavv]
|
267
|
+
xid = three_d_secure_options[:xid]
|
268
|
+
ds_transaction_id = three_d_secure_options[:ds_transaction_id]
|
269
|
+
version = three_d_secure_options[:version]
|
270
|
+
|
271
|
+
doc.send('three-d-secure') do
|
272
|
+
doc.eci(eci) if eci
|
273
|
+
doc.cavv(cavv) if cavv
|
274
|
+
doc.xid(xid) if xid
|
275
|
+
doc.send('three-d-secure-version', version) if version
|
276
|
+
doc.send('ds-transaction-id', ds_transaction_id) if ds_transaction_id
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
def add_level_3_data(doc, options)
|
281
|
+
return unless options[:customer_reference_number]
|
282
|
+
|
283
|
+
doc.send('level-3-data') do
|
284
|
+
send_when_present(doc, :customer_reference_number, options)
|
285
|
+
send_when_present(doc, :sales_tax_amount, options)
|
286
|
+
send_when_present(doc, :freight_amount, options)
|
287
|
+
send_when_present(doc, :duty_amount, options)
|
288
|
+
send_when_present(doc, :destination_zip_code, options)
|
289
|
+
send_when_present(doc, :destination_country_code, options)
|
290
|
+
send_when_present(doc, :ship_from_zip_code, options)
|
291
|
+
send_when_present(doc, :discount_amount, options)
|
292
|
+
send_when_present(doc, :tax_amount, options)
|
293
|
+
send_when_present(doc, :tax_rate, options)
|
294
|
+
add_level_3_data_items(doc, options[:level_3_data_items]) if options[:level_3_data_items]
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
def send_when_present(doc, options_key, options, xml_element_name = nil)
|
299
|
+
return unless options[options_key]
|
300
|
+
|
301
|
+
xml_element_name ||= options_key.to_s
|
302
|
+
|
303
|
+
doc.send(xml_element_name.dasherize, options[options_key])
|
304
|
+
end
|
305
|
+
|
306
|
+
def add_level_3_data_items(doc, items)
|
307
|
+
items.each do |item|
|
308
|
+
doc.send('level-3-data-item') do
|
309
|
+
item.each do |key, value|
|
310
|
+
key = key.to_s.dasherize
|
311
|
+
doc.send(key, value)
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
def add_authorization(doc, authorization)
|
318
|
+
doc.send('transaction-id', authorization)
|
319
|
+
end
|
320
|
+
|
321
|
+
def add_fraud_info(doc, payment_method, options)
|
322
|
+
doc.send('transaction-fraud-info') do
|
323
|
+
doc.send('shopper-ip-address', options[:ip]) if options[:ip]
|
324
|
+
if fraud_info = options[:transaction_fraud_info]
|
325
|
+
doc.send('fraud-session-id', fraud_info[:fraud_session_id]) if fraud_info[:fraud_session_id]
|
326
|
+
end
|
327
|
+
unless payment_method.is_a? String
|
328
|
+
doc.send('shipping-contact-info') do
|
329
|
+
add_shipping_contact_info(doc, payment_method, options)
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
def add_shipping_contact_info(doc, payment_method, options)
|
336
|
+
if address = options[:shipping_address]
|
337
|
+
# https://developers.bluesnap.com/v8976-XML/docs/shipping-contact-info
|
338
|
+
doc.send('first-name', payment_method.first_name)
|
339
|
+
doc.send('last-name', payment_method.last_name)
|
340
|
+
|
341
|
+
doc.country(address[:country]) if address[:country]
|
342
|
+
doc.state(address[:state]) if address[:state] && STATE_CODE_COUNTRIES.include?(address[:country])
|
343
|
+
doc.address1(address[:address1]) if address[:address1]
|
344
|
+
doc.address2(address[:address2]) if address[:address2]
|
345
|
+
doc.city(address[:city]) if address[:city]
|
346
|
+
doc.zip(address[:zip]) if address[:zip]
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
def add_alt_transaction_purchase(doc, money, payment_method_details, options)
|
351
|
+
doc.send('merchant-transaction-id', truncate(options[:order_id], 50)) if options[:order_id]
|
352
|
+
doc.send('soft-descriptor', options[:soft_descriptor]) if options[:soft_descriptor]
|
353
|
+
add_amount(doc, money, options)
|
354
|
+
|
355
|
+
vaulted_shopper_id = payment_method_details.vaulted_shopper_id
|
356
|
+
doc.send('vaulted-shopper-id', vaulted_shopper_id) if vaulted_shopper_id
|
357
|
+
|
358
|
+
add_echeck_transaction(doc, payment_method_details.payment_method, options, vaulted_shopper_id.present?) if payment_method_details.check?
|
359
|
+
|
360
|
+
add_fraud_info(doc, payment_method_details.payment_method, options)
|
361
|
+
add_metadata(doc, options)
|
362
|
+
end
|
363
|
+
|
364
|
+
def add_echeck_transaction(doc, check, options, vaulted_shopper)
|
365
|
+
unless vaulted_shopper
|
366
|
+
doc.send('payer-info') do
|
367
|
+
add_personal_info(doc, check, options)
|
368
|
+
add_echeck_company(doc, check)
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
doc.send('ecp-transaction') do
|
373
|
+
add_echeck(doc, check) unless vaulted_shopper
|
374
|
+
end
|
375
|
+
|
376
|
+
doc.send('authorized-by-shopper', options[:authorized_by_shopper])
|
377
|
+
end
|
378
|
+
|
379
|
+
def add_echeck_company(doc, check)
|
380
|
+
doc.send('company-name', truncate(check.name, 50)) if check.account_holder_type = 'business'
|
381
|
+
end
|
382
|
+
|
383
|
+
def add_echeck(doc, check)
|
384
|
+
doc.send('account-number', check.account_number)
|
385
|
+
doc.send('routing-number', check.routing_number)
|
386
|
+
doc.send('account-type', BANK_ACCOUNT_TYPE_MAPPING["#{check.account_holder_type}_#{check.account_type}"])
|
387
|
+
end
|
388
|
+
|
389
|
+
def parse(response)
|
390
|
+
return bad_authentication_response if response.code.to_i == 401
|
391
|
+
return generic_error_response(response.body) if [403, 405, 429].include?(response.code.to_i)
|
392
|
+
|
393
|
+
parsed = {}
|
394
|
+
doc = Nokogiri::XML(response.body)
|
395
|
+
doc.root.xpath('*').each do |node|
|
396
|
+
name = node.name.downcase
|
397
|
+
if node.elements.empty?
|
398
|
+
parsed[name] = node.text
|
399
|
+
elsif name == 'transaction-meta-data'
|
400
|
+
metadata = []
|
401
|
+
node.elements.each { |m|
|
402
|
+
metadata.push parse_metadata_entry(m)
|
403
|
+
}
|
404
|
+
|
405
|
+
parsed['transaction-meta-data'] = metadata
|
406
|
+
else
|
407
|
+
node.elements.each { |childnode|
|
408
|
+
parse_element(parsed, childnode)
|
409
|
+
}
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
parsed['content-location-header'] = response['content-location']
|
414
|
+
parsed
|
415
|
+
end
|
416
|
+
|
417
|
+
def parse_metadata_entry(node)
|
418
|
+
entry = {}
|
419
|
+
|
420
|
+
node.elements.each { |e|
|
421
|
+
entry = entry.merge({
|
422
|
+
e.name => e.text
|
423
|
+
})
|
424
|
+
}
|
425
|
+
|
426
|
+
entry
|
427
|
+
end
|
428
|
+
|
429
|
+
def parse_element(parsed, node)
|
430
|
+
if !node.elements.empty?
|
431
|
+
node.elements.each { |e| parse_element(parsed, e) }
|
432
|
+
else
|
433
|
+
parsed[node.name.downcase] = node.text
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
def api_request(action, request, verb, payment_method_details, options)
|
438
|
+
ssl_request(verb, url(action, options, payment_method_details), request, headers(options))
|
439
|
+
rescue ResponseError => e
|
440
|
+
e.response
|
441
|
+
end
|
442
|
+
|
443
|
+
def commit(action, options, verb = :post, payment_method_details = PaymentMethodDetails.new())
|
444
|
+
request = build_xml_request(action, payment_method_details) { |doc| yield(doc) }
|
445
|
+
response = api_request(action, request, verb, payment_method_details, options)
|
446
|
+
parsed = parse(response)
|
447
|
+
|
448
|
+
succeeded = success_from(action, response)
|
449
|
+
Response.new(
|
450
|
+
succeeded,
|
451
|
+
message_from(succeeded, response),
|
452
|
+
parsed,
|
453
|
+
authorization: authorization_from(action, parsed, payment_method_details),
|
454
|
+
avs_result: avs_result(parsed),
|
455
|
+
cvv_result: cvv_result(parsed),
|
456
|
+
error_code: error_code_from(parsed),
|
457
|
+
test: test?
|
458
|
+
)
|
459
|
+
end
|
460
|
+
|
461
|
+
def url(action = nil, options = {}, payment_method_details = PaymentMethodDetails.new())
|
462
|
+
base = test? ? test_url : live_url
|
463
|
+
resource = action == :store ? 'vaulted-shoppers' : payment_method_details.resource_url
|
464
|
+
resource += options[:endpoint] if action == :refund
|
465
|
+
"#{base}/#{resource}"
|
466
|
+
end
|
467
|
+
|
468
|
+
def cvv_result(parsed)
|
469
|
+
CVVResult.new(CVC_CODE_TRANSLATOR[parsed['cvv-response-code']])
|
470
|
+
end
|
471
|
+
|
472
|
+
def avs_result(parsed)
|
473
|
+
AVSResult.new(code: AVS_CODE_TRANSLATOR[avs_lookup_key(parsed)])
|
474
|
+
end
|
475
|
+
|
476
|
+
def avs_lookup_key(p)
|
477
|
+
"line1: #{p['avs-response-code-address']}, zip: #{p['avs-response-code-zip']}, name: #{p['avs-response-code-name']}"
|
478
|
+
end
|
479
|
+
|
480
|
+
def success_from(action, response)
|
481
|
+
(200...300).cover?(response.code.to_i)
|
482
|
+
end
|
483
|
+
|
484
|
+
def message_from(succeeded, response)
|
485
|
+
return 'Success' if succeeded
|
486
|
+
|
487
|
+
parsed = parse(response)
|
488
|
+
if parsed.dig('error-name') == 'FRAUD_DETECTED'
|
489
|
+
fraud_codes_from(response)
|
490
|
+
else
|
491
|
+
parsed['description']
|
492
|
+
end
|
493
|
+
end
|
494
|
+
|
495
|
+
def fraud_codes_from(response)
|
496
|
+
event_summary = {}
|
497
|
+
doc = Nokogiri::XML(response.body)
|
498
|
+
fraud_events = doc.xpath('//xmlns:fraud-events', 'xmlns' => 'http://ws.plimus.com')
|
499
|
+
fraud_events.children.each do |child|
|
500
|
+
if child.children.children.any?
|
501
|
+
event_summary[child.name] = event_summary[child.name] || []
|
502
|
+
event = {}
|
503
|
+
child.children.each do |chi|
|
504
|
+
event[chi.name] = chi.text
|
505
|
+
end
|
506
|
+
event_summary[child.name] << event
|
507
|
+
else
|
508
|
+
event_summary[child.name] = child.text
|
509
|
+
end
|
510
|
+
end
|
511
|
+
event_summary.to_json
|
512
|
+
end
|
513
|
+
|
514
|
+
def authorization_from(action, parsed_response, payment_method_details)
|
515
|
+
action == :store ? vaulted_shopper_id(parsed_response, payment_method_details) : parsed_response['transaction-id']
|
516
|
+
end
|
517
|
+
|
518
|
+
def vaulted_shopper_id(parsed_response, payment_method_details)
|
519
|
+
return nil unless parsed_response['content-location-header']
|
520
|
+
|
521
|
+
vaulted_shopper_id = parsed_response['content-location-header'].split('/').last
|
522
|
+
vaulted_shopper_id += "|#{payment_method_details.payment_method_type}" if payment_method_details.alt_transaction?
|
523
|
+
vaulted_shopper_id
|
524
|
+
end
|
525
|
+
|
526
|
+
def error_code_from(parsed_response)
|
527
|
+
parsed_response['code']
|
528
|
+
end
|
529
|
+
|
530
|
+
def root_attributes
|
531
|
+
{
|
532
|
+
xmlns: 'http://ws.plimus.com'
|
533
|
+
}
|
534
|
+
end
|
535
|
+
|
536
|
+
def root_element(action, payment_method_details)
|
537
|
+
return 'refund' if action == :refund
|
538
|
+
return 'vaulted-shopper' if action == :store
|
539
|
+
|
540
|
+
payment_method_details.root_element
|
541
|
+
end
|
542
|
+
|
543
|
+
def headers(options)
|
544
|
+
idempotency_key = options[:idempotency_key] if options[:idempotency_key]
|
545
|
+
|
546
|
+
headers = {
|
547
|
+
'Content-Type' => 'application/xml',
|
548
|
+
'Authorization' => ('Basic ' + Base64.strict_encode64("#{@options[:api_username]}:#{@options[:api_password]}").strip)
|
549
|
+
}
|
550
|
+
|
551
|
+
headers['Idempotency-Key'] = idempotency_key if idempotency_key
|
552
|
+
headers
|
553
|
+
end
|
554
|
+
|
555
|
+
def build_xml_request(action, payment_method_details)
|
556
|
+
builder = Nokogiri::XML::Builder.new
|
557
|
+
builder.__send__(root_element(action, payment_method_details), root_attributes) do |doc|
|
558
|
+
doc.send('card-transaction-type', TRANSACTIONS[action]) if TRANSACTIONS[action] && !payment_method_details.alt_transaction? && action != :refund
|
559
|
+
yield(doc)
|
560
|
+
end
|
561
|
+
builder.doc.root.to_xml
|
562
|
+
end
|
563
|
+
|
564
|
+
def handle_response(response)
|
565
|
+
case response.code.to_i
|
566
|
+
when 200...300
|
567
|
+
response
|
568
|
+
else
|
569
|
+
raise ResponseError.new(response)
|
570
|
+
end
|
571
|
+
end
|
572
|
+
|
573
|
+
def bad_authentication_response
|
574
|
+
{ 'description' => 'Unable to authenticate. Please check your credentials.' }
|
575
|
+
end
|
576
|
+
|
577
|
+
def generic_error_response(body)
|
578
|
+
{ 'description' => body }
|
579
|
+
end
|
580
|
+
end
|
581
|
+
|
582
|
+
class PaymentMethodDetails
|
583
|
+
attr_reader :payment_method, :vaulted_shopper_id, :payment_method_type
|
584
|
+
|
585
|
+
def initialize(payment_method = nil)
|
586
|
+
@payment_method = payment_method
|
587
|
+
@payment_method_type = nil
|
588
|
+
parse(payment_method)
|
589
|
+
end
|
590
|
+
|
591
|
+
def check?
|
592
|
+
@payment_method.is_a?(Check) || @payment_method_type == 'check'
|
593
|
+
end
|
594
|
+
|
595
|
+
def alt_transaction?
|
596
|
+
check?
|
597
|
+
end
|
598
|
+
|
599
|
+
def root_element
|
600
|
+
alt_transaction? ? 'alt-transaction' : 'card-transaction'
|
601
|
+
end
|
602
|
+
|
603
|
+
def resource_url
|
604
|
+
alt_transaction? ? 'alt-transactions' : 'transactions'
|
605
|
+
end
|
606
|
+
|
607
|
+
private
|
608
|
+
|
609
|
+
def parse(payment_method)
|
610
|
+
return unless payment_method
|
611
|
+
|
612
|
+
if payment_method.is_a?(String)
|
613
|
+
@vaulted_shopper_id, payment_method_type = payment_method.split('|')
|
614
|
+
@payment_method_type = payment_method_type if payment_method_type.present?
|
615
|
+
elsif payment_method.is_a?(Check)
|
616
|
+
@payment_method_type = payment_method.type
|
617
|
+
else
|
618
|
+
@payment_method_type = 'credit_card'
|
619
|
+
end
|
620
|
+
end
|
621
|
+
end
|
622
|
+
end
|
623
|
+
end
|