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,265 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class SecurionPayGateway < Gateway
|
4
|
+
self.test_url = 'https://api.securionpay.com/'
|
5
|
+
self.live_url = 'https://api.securionpay.com/'
|
6
|
+
|
7
|
+
self.supported_countries = %w(AD BE BG CH CY CZ DE DK EE ES FI FO FR GI GL GR GS GT HR HU IE IS IT LI LR LT
|
8
|
+
LU LV MC MT MU MV MW NL NO PL RO SE SI)
|
9
|
+
|
10
|
+
self.default_currency = 'USD'
|
11
|
+
self.money_format = :cents
|
12
|
+
self.supported_cardtypes = %i[visa master american_express discover jcb diners_club]
|
13
|
+
|
14
|
+
self.homepage_url = 'https://securionpay.com/'
|
15
|
+
self.display_name = 'SecurionPay'
|
16
|
+
|
17
|
+
STANDARD_ERROR_CODE_MAPPING = {
|
18
|
+
'incorrect_number' => STANDARD_ERROR_CODE[:incorrect_number],
|
19
|
+
'invalid_number' => STANDARD_ERROR_CODE[:invalid_number],
|
20
|
+
'invalid_expiry_month' => STANDARD_ERROR_CODE[:invalid_expiry_date],
|
21
|
+
'invalid_expiry_year' => STANDARD_ERROR_CODE[:invalid_expiry_date],
|
22
|
+
'invalid_cvc' => STANDARD_ERROR_CODE[:invalid_cvc],
|
23
|
+
'expired_card' => STANDARD_ERROR_CODE[:expired_card],
|
24
|
+
'insufficient_funds' => STANDARD_ERROR_CODE[:card_declined],
|
25
|
+
'incorrect_cvc' => STANDARD_ERROR_CODE[:incorrect_cvc],
|
26
|
+
'incorrect_zip' => STANDARD_ERROR_CODE[:incorrect_zip],
|
27
|
+
'card_declined' => STANDARD_ERROR_CODE[:card_declined],
|
28
|
+
'processing_error' => STANDARD_ERROR_CODE[:processing_error],
|
29
|
+
'lost_or_stolen' => STANDARD_ERROR_CODE[:card_declined],
|
30
|
+
'suspected_fraud' => STANDARD_ERROR_CODE[:card_declined],
|
31
|
+
'expired_token' => STANDARD_ERROR_CODE[:card_declined]
|
32
|
+
}
|
33
|
+
|
34
|
+
def initialize(options = {})
|
35
|
+
requires!(options, :secret_key)
|
36
|
+
super
|
37
|
+
end
|
38
|
+
|
39
|
+
def purchase(money, payment, options = {})
|
40
|
+
post = create_post_for_auth_or_purchase(money, payment, options)
|
41
|
+
commit('charges', post, options)
|
42
|
+
end
|
43
|
+
|
44
|
+
def authorize(money, payment, options = {})
|
45
|
+
post = create_post_for_auth_or_purchase(money, payment, options)
|
46
|
+
post[:captured] = 'false'
|
47
|
+
commit('charges', post, options)
|
48
|
+
end
|
49
|
+
|
50
|
+
def capture(money, authorization, options = {})
|
51
|
+
post = {}
|
52
|
+
add_amount(post, money, options)
|
53
|
+
commit("charges/#{CGI.escape(authorization)}/capture", post, options)
|
54
|
+
end
|
55
|
+
|
56
|
+
def refund(money, authorization, options = {})
|
57
|
+
post = {}
|
58
|
+
add_amount(post, money, options)
|
59
|
+
commit("charges/#{CGI.escape(authorization)}/refund", post, options)
|
60
|
+
end
|
61
|
+
|
62
|
+
def void(authorization, options = {})
|
63
|
+
commit("charges/#{CGI.escape(authorization)}/refund", {}, options)
|
64
|
+
end
|
65
|
+
|
66
|
+
def verify(credit_card, options = {})
|
67
|
+
MultiResponse.run(:use_first_response) do |r|
|
68
|
+
r.process { authorize(100, credit_card, options) }
|
69
|
+
r.process(:ignore_result) { void(r.authorization, options) }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def store(credit_card, options = {})
|
74
|
+
if options[:customer_id].blank?
|
75
|
+
MultiResponse.run() do |r|
|
76
|
+
# create charge object
|
77
|
+
r.process { authorize(100, credit_card, options) }
|
78
|
+
# create customer and save card
|
79
|
+
r.process { create_customer_add_card(r.authorization, options) }
|
80
|
+
# void the charge
|
81
|
+
r.process(:ignore_result) { void(r.params['metadata']['chargeId'], options) }
|
82
|
+
end
|
83
|
+
else
|
84
|
+
verify(credit_card, options)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def customer(options = {})
|
89
|
+
if options[:customer_id].blank?
|
90
|
+
return nil
|
91
|
+
else
|
92
|
+
commit("customers/#{CGI.escape(options[:customer_id])}", nil, options, :get)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def supports_scrubbing?
|
97
|
+
true
|
98
|
+
end
|
99
|
+
|
100
|
+
def scrub(transcript)
|
101
|
+
transcript.
|
102
|
+
gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
|
103
|
+
gsub(%r((card\[number\]=)\d+), '\1[FILTERED]').
|
104
|
+
gsub(%r((card\[cvc\]=)\d+), '\1[FILTERED]')
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
def create_customer_add_card(authorization, options)
|
110
|
+
post = {}
|
111
|
+
post[:email] = options[:email]
|
112
|
+
post[:description] = options[:description]
|
113
|
+
post[:card] = authorization
|
114
|
+
post[:metadata] = {}
|
115
|
+
post[:metadata][:chargeId] = authorization
|
116
|
+
commit('customers', post, options)
|
117
|
+
end
|
118
|
+
|
119
|
+
def add_customer(post, payment, options)
|
120
|
+
post[:customerId] = options[:customer_id] if options[:customer_id]
|
121
|
+
end
|
122
|
+
|
123
|
+
def add_customer_data(post, options)
|
124
|
+
post[:description] = options[:description]
|
125
|
+
post[:ip] = options[:ip]
|
126
|
+
post[:user_agent] = options[:user_agent]
|
127
|
+
post[:referrer] = options[:referrer]
|
128
|
+
end
|
129
|
+
|
130
|
+
def create_post_for_auth_or_purchase(money, payment, options)
|
131
|
+
post = {}
|
132
|
+
add_amount(post, money, options, true)
|
133
|
+
add_creditcard(post, payment, options)
|
134
|
+
add_customer(post, payment, options)
|
135
|
+
add_customer_data(post, options)
|
136
|
+
if options[:email]
|
137
|
+
post[:metadata] = {}
|
138
|
+
post[:metadata][:email] = options[:email]
|
139
|
+
end
|
140
|
+
post
|
141
|
+
end
|
142
|
+
|
143
|
+
def add_amount(post, money, options, include_currency = false)
|
144
|
+
currency = (options[:currency] || default_currency)
|
145
|
+
post[:amount] = localized_amount(money, currency)
|
146
|
+
post[:currency] = currency.downcase if include_currency
|
147
|
+
end
|
148
|
+
|
149
|
+
def add_creditcard(post, creditcard, options)
|
150
|
+
card = {}
|
151
|
+
if creditcard.respond_to?(:number)
|
152
|
+
card[:number] = creditcard.number
|
153
|
+
card[:expMonth] = creditcard.month
|
154
|
+
card[:expYear] = creditcard.year
|
155
|
+
card[:cvc] = creditcard.verification_value if creditcard.verification_value?
|
156
|
+
card[:cardholderName] = creditcard.name if creditcard.name
|
157
|
+
|
158
|
+
post[:card] = card
|
159
|
+
add_address(post, options)
|
160
|
+
elsif creditcard.kind_of?(String)
|
161
|
+
post[:card] = creditcard
|
162
|
+
else
|
163
|
+
raise ArgumentError.new("Unhandled payment method #{creditcard.class}.")
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def add_address(post, options)
|
168
|
+
return unless post[:card]&.kind_of?(Hash)
|
169
|
+
|
170
|
+
if address = options[:billing_address]
|
171
|
+
post[:card][:addressLine1] = address[:address1] if address[:address1]
|
172
|
+
post[:card][:addressLine2] = address[:address2] if address[:address2]
|
173
|
+
post[:card][:addressCountry] = address[:country] if address[:country]
|
174
|
+
post[:card][:addressZip] = address[:zip] if address[:zip]
|
175
|
+
post[:card][:addressState] = address[:state] if address[:state]
|
176
|
+
post[:card][:addressCity] = address[:city] if address[:city]
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def parse(body)
|
181
|
+
JSON.parse(body)
|
182
|
+
end
|
183
|
+
|
184
|
+
def commit(url, parameters = nil, options = {}, method = nil)
|
185
|
+
response = api_request(url, parameters, options, method)
|
186
|
+
success = !response.key?('error')
|
187
|
+
|
188
|
+
Response.new(success,
|
189
|
+
(success ? 'Transaction approved' : response['error']['message']),
|
190
|
+
response,
|
191
|
+
test: test?,
|
192
|
+
authorization: (success ? response['id'] : response['error']['charge']),
|
193
|
+
error_code: (success ? nil : STANDARD_ERROR_CODE_MAPPING[response['error']['code']]))
|
194
|
+
end
|
195
|
+
|
196
|
+
def headers(options = {})
|
197
|
+
secret_key = options[:secret_key] || @options[:secret_key]
|
198
|
+
|
199
|
+
headers = {
|
200
|
+
'Authorization' => 'Basic ' + Base64.encode64(secret_key.to_s + ':').strip,
|
201
|
+
'User-Agent' => "SecurionPay/v1 ActiveMerchantBindings/#{ActiveMerchant::VERSION}"
|
202
|
+
}
|
203
|
+
headers
|
204
|
+
end
|
205
|
+
|
206
|
+
def response_error(raw_response)
|
207
|
+
parse(raw_response)
|
208
|
+
rescue JSON::ParserError
|
209
|
+
json_error(raw_response)
|
210
|
+
end
|
211
|
+
|
212
|
+
def post_data(params)
|
213
|
+
return nil unless params
|
214
|
+
|
215
|
+
params.map do |key, value|
|
216
|
+
next if value.blank?
|
217
|
+
|
218
|
+
if value.is_a?(Hash)
|
219
|
+
h = {}
|
220
|
+
value.each do |k, v|
|
221
|
+
h["#{key}[#{k}]"] = v unless v.blank?
|
222
|
+
end
|
223
|
+
post_data(h)
|
224
|
+
elsif value.is_a?(Array)
|
225
|
+
value.map { |v| "#{key}[]=#{CGI.escape(v.to_s)}" }.join('&')
|
226
|
+
else
|
227
|
+
"#{key}=#{CGI.escape(value.to_s)}"
|
228
|
+
end
|
229
|
+
end.compact.join('&')
|
230
|
+
end
|
231
|
+
|
232
|
+
def api_request(endpoint, parameters = nil, options = {}, method = nil)
|
233
|
+
raw_response = response = nil
|
234
|
+
begin
|
235
|
+
if method.blank?
|
236
|
+
raw_response = ssl_post(self.live_url + endpoint, post_data(parameters), headers(options))
|
237
|
+
else
|
238
|
+
raw_response = ssl_request(method, self.live_url + endpoint, post_data(parameters), headers(options))
|
239
|
+
end
|
240
|
+
response = parse(raw_response)
|
241
|
+
rescue ResponseError => e
|
242
|
+
raw_response = e.response.body
|
243
|
+
response = response_error(raw_response)
|
244
|
+
rescue JSON::ParserError
|
245
|
+
response = json_error(raw_response)
|
246
|
+
end
|
247
|
+
response
|
248
|
+
end
|
249
|
+
|
250
|
+
def json_error(raw_response)
|
251
|
+
msg = 'Invalid response received from the SecurionPay API.'
|
252
|
+
msg += " (The raw response returned by the API was #{raw_response.inspect})"
|
253
|
+
{
|
254
|
+
'error' => {
|
255
|
+
'message' => msg
|
256
|
+
}
|
257
|
+
}
|
258
|
+
end
|
259
|
+
|
260
|
+
def test?
|
261
|
+
(@options[:secret_key]&.include?('_test_'))
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
@@ -0,0 +1,362 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class SimetrikGateway < Gateway
|
4
|
+
self.test_url = 'https://payments.sta.simetrik.com/v1'
|
5
|
+
self.live_url = 'https://payments.simetrik.com/v1'
|
6
|
+
|
7
|
+
class_attribute :test_auth_url, :live_auth_url
|
8
|
+
self.test_auth_url = 'https://tenant-payments-dev.us.auth0.com/oauth/token'
|
9
|
+
self.live_auth_url = 'https://tenant-payments-prod.us.auth0.com/oauth/token'
|
10
|
+
|
11
|
+
self.supported_countries = %w(PE AR)
|
12
|
+
self.default_currency = 'USD'
|
13
|
+
self.supported_cardtypes = %i[visa master american_express discover]
|
14
|
+
|
15
|
+
self.homepage_url = 'https://www.simetrik.com'
|
16
|
+
self.display_name = 'Simetrik'
|
17
|
+
|
18
|
+
STANDARD_ERROR_CODE_MAPPING = {
|
19
|
+
'R101' => STANDARD_ERROR_CODE[:incorrect_number],
|
20
|
+
'R102' => STANDARD_ERROR_CODE[:invalid_number],
|
21
|
+
'R103' => STANDARD_ERROR_CODE[:invalid_expiry_date],
|
22
|
+
'R104' => STANDARD_ERROR_CODE[:invalid_cvc],
|
23
|
+
'R105' => STANDARD_ERROR_CODE[:expired_card],
|
24
|
+
'R106' => STANDARD_ERROR_CODE[:incorrect_cvc],
|
25
|
+
'R107' => STANDARD_ERROR_CODE[:incorrect_pin],
|
26
|
+
'R201' => STANDARD_ERROR_CODE[:incorrect_zip],
|
27
|
+
'R202' => STANDARD_ERROR_CODE[:incorrect_address],
|
28
|
+
'R301' => STANDARD_ERROR_CODE[:card_declined],
|
29
|
+
'R302' => STANDARD_ERROR_CODE[:processing_error],
|
30
|
+
'R303' => STANDARD_ERROR_CODE[:call_issuer],
|
31
|
+
'R304' => STANDARD_ERROR_CODE[:pick_up_card],
|
32
|
+
'R305' => STANDARD_ERROR_CODE[:processing_error],
|
33
|
+
'R306' => STANDARD_ERROR_CODE[:processing_error],
|
34
|
+
'R307' => STANDARD_ERROR_CODE[:processing_error],
|
35
|
+
'R401' => STANDARD_ERROR_CODE[:config_error],
|
36
|
+
'R402' => STANDARD_ERROR_CODE[:test_mode_live_card],
|
37
|
+
'R403' => STANDARD_ERROR_CODE[:unsupported_feature]
|
38
|
+
|
39
|
+
}
|
40
|
+
|
41
|
+
def initialize(options = {})
|
42
|
+
requires!(options, :client_id, :client_secret, :audience)
|
43
|
+
super
|
44
|
+
@access_token = {}
|
45
|
+
sign_access_token()
|
46
|
+
end
|
47
|
+
|
48
|
+
def authorize(money, payment, options = {})
|
49
|
+
requires!(options, :token_acquirer)
|
50
|
+
|
51
|
+
post = {}
|
52
|
+
add_forward_route(post, options)
|
53
|
+
add_forward_payload(post, money, payment, options)
|
54
|
+
add_stored_credential(post, options)
|
55
|
+
|
56
|
+
commit('authorize', post, { token_acquirer: options[:token_acquirer] })
|
57
|
+
end
|
58
|
+
|
59
|
+
def capture(money, authorization, options = {})
|
60
|
+
requires!(options, :token_acquirer)
|
61
|
+
post = {
|
62
|
+
forward_payload: {
|
63
|
+
amount: {
|
64
|
+
total_amount: amount(money).to_f,
|
65
|
+
currency: (options[:currency] || currency(money))
|
66
|
+
},
|
67
|
+
transaction: {
|
68
|
+
id: authorization
|
69
|
+
},
|
70
|
+
acquire_extra_options: options[:acquire_extra_options] || {}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
post[:forward_payload][:amount][:vat] = options[:vat] if options[:vat]
|
74
|
+
|
75
|
+
add_forward_route(post, options)
|
76
|
+
commit('capture', post, { token_acquirer: options[:token_acquirer] })
|
77
|
+
end
|
78
|
+
|
79
|
+
def refund(money, authorization, options = {})
|
80
|
+
requires!(options, :token_acquirer)
|
81
|
+
post = {
|
82
|
+
forward_payload: {
|
83
|
+
amount: {
|
84
|
+
total_amount: amount(money).to_f,
|
85
|
+
currency: (options[:currency] || currency(money))
|
86
|
+
},
|
87
|
+
transaction: {
|
88
|
+
id: authorization
|
89
|
+
},
|
90
|
+
acquire_extra_options: options[:acquire_extra_options] || {}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
post[:forward_payload][:transaction][:comment] = options[:comment] if options[:comment]
|
94
|
+
|
95
|
+
add_forward_route(post, options)
|
96
|
+
commit('refund', post, { token_acquirer: options[:token_acquirer] })
|
97
|
+
end
|
98
|
+
|
99
|
+
def void(authorization, options = {})
|
100
|
+
requires!(options, :token_acquirer)
|
101
|
+
post = {
|
102
|
+
forward_payload: {
|
103
|
+
transaction: {
|
104
|
+
id: authorization
|
105
|
+
},
|
106
|
+
acquire_extra_options: options[:acquire_extra_options] || {}
|
107
|
+
}
|
108
|
+
}
|
109
|
+
add_forward_route(post, options)
|
110
|
+
commit('void', post, { token_acquirer: options[:token_acquirer] })
|
111
|
+
end
|
112
|
+
|
113
|
+
def purchase(money, payment, options = {})
|
114
|
+
requires!(options, :token_acquirer)
|
115
|
+
|
116
|
+
post = {}
|
117
|
+
add_forward_route(post, options)
|
118
|
+
add_forward_payload(post, money, payment, options)
|
119
|
+
|
120
|
+
add_stored_credential(post, options)
|
121
|
+
commit('charge', post, { token_acquirer: options[:token_acquirer] })
|
122
|
+
end
|
123
|
+
|
124
|
+
def supports_scrubbing?
|
125
|
+
true
|
126
|
+
end
|
127
|
+
|
128
|
+
def scrub(transcript)
|
129
|
+
transcript.
|
130
|
+
gsub(%r((\"number\\\":\\\")\d+), '\1[FILTERED]').
|
131
|
+
gsub(%r((\"security_code\\\":\\\")\d+), '\1[FILTERED]').
|
132
|
+
gsub(%r((\"exp_month\\\":\\\")\d+), '\1[FILTERED]').
|
133
|
+
gsub(%r((\"exp_year\\\":\\\")\d+), '\1[FILTERED]').
|
134
|
+
gsub(%r((\"holder_first_name\\\":\\\")"\w+"), '\1[FILTERED]').
|
135
|
+
gsub(%r((\"holder_last_name\\\":\\\")"\w+"), '\1[FILTERED]')
|
136
|
+
end
|
137
|
+
|
138
|
+
private
|
139
|
+
|
140
|
+
def add_forward_route(post, options)
|
141
|
+
forward_route = {}
|
142
|
+
forward_route[:trace_id] = options[:trace_id] if options[:trace_id]
|
143
|
+
|
144
|
+
forward_route[:psp_extra_fields] = options[:psp_extra_fields] || {}
|
145
|
+
post[:forward_route] = forward_route
|
146
|
+
end
|
147
|
+
|
148
|
+
def add_forward_payload(post, money, payment, options)
|
149
|
+
forward_payload = {}
|
150
|
+
add_user(forward_payload, options[:user]) if options[:user]
|
151
|
+
add_order(forward_payload, money, options[:order]) if options[:order] || money
|
152
|
+
add_payment_method(forward_payload, payment, options[:payment_method]) if options[:payment_method] || payment
|
153
|
+
|
154
|
+
forward_payload[:payment_method] = {} unless forward_payload[:payment_method]
|
155
|
+
forward_payload[:payment_method][:card] = {} unless forward_payload[:payment_method][:card]
|
156
|
+
add_address('billing_address', forward_payload[:payment_method][:card], options[:billing_address]) if options[:billing_address]
|
157
|
+
|
158
|
+
add_three_ds_fields(forward_payload[:authentication] = {}, options[:three_ds_fields]) if options[:three_ds_fields]
|
159
|
+
add_sub_merchant(forward_payload, options[:sub_merchant]) if options[:sub_merchant]
|
160
|
+
forward_payload[:acquire_extra_options] = options[:acquire_extra_options] || {}
|
161
|
+
post[:forward_payload] = forward_payload
|
162
|
+
end
|
163
|
+
|
164
|
+
def add_sub_merchant(post, sub_merchant_options)
|
165
|
+
sub_merchant = {}
|
166
|
+
sub_merchant[:merchant_id] = sub_merchant_options[:merchant_id] if sub_merchant_options[:merchant_id]
|
167
|
+
sub_merchant[:extra_params] = sub_merchant_options[:extra_params] if sub_merchant_options[:extra_params]
|
168
|
+
sub_merchant[:mcc] = sub_merchant_options[:mcc] if sub_merchant_options[:mcc]
|
169
|
+
sub_merchant[:name] = sub_merchant_options[:name] if sub_merchant_options[:name]
|
170
|
+
sub_merchant[:address] = sub_merchant_options[:address] if sub_merchant_options[:address]
|
171
|
+
sub_merchant[:postal_code] = sub_merchant_options[:postal_code] if sub_merchant_options[:postal_code]
|
172
|
+
sub_merchant[:url] = sub_merchant_options[:url] if sub_merchant_options[:url]
|
173
|
+
sub_merchant[:phone_number] = sub_merchant_options[:phone_number] if sub_merchant_options[:phone_number]
|
174
|
+
|
175
|
+
post[:sub_merchant] = sub_merchant
|
176
|
+
end
|
177
|
+
|
178
|
+
def add_payment_method(post, payment, payment_method_options)
|
179
|
+
payment_method = {}
|
180
|
+
opts = nil
|
181
|
+
opts = payment_method_options[:card] if payment_method_options
|
182
|
+
add_card(payment_method, payment, opts) if opts || payment
|
183
|
+
|
184
|
+
post[:payment_method] = payment_method
|
185
|
+
end
|
186
|
+
|
187
|
+
def add_three_ds_fields(post, three_ds_options)
|
188
|
+
three_ds = {}
|
189
|
+
three_ds[:version] = three_ds_options[:version] if three_ds_options[:version]
|
190
|
+
three_ds[:eci] = three_ds_options[:eci] if three_ds_options[:eci]
|
191
|
+
three_ds[:cavv] = three_ds_options[:cavv] if three_ds_options[:cavv]
|
192
|
+
three_ds[:ds_transaction_id] = three_ds_options[:ds_transaction_id] if three_ds_options[:ds_transaction_id]
|
193
|
+
three_ds[:acs_transaction_id] = three_ds_options[:acs_transaction_id] if three_ds_options[:acs_transaction_id]
|
194
|
+
three_ds[:xid] = three_ds_options[:xid] if three_ds_options[:xid]
|
195
|
+
three_ds[:enrolled] = three_ds_options[:enrolled] if three_ds_options[:enrolled]
|
196
|
+
three_ds[:cavv_algorithm] = three_ds_options[:cavv_algorithm] if three_ds_options[:cavv_algorithm]
|
197
|
+
three_ds[:directory_response_status] = three_ds_options[:directory_response_status] if three_ds_options[:directory_response_status]
|
198
|
+
three_ds[:authentication_response_status] = three_ds_options[:authentication_response_status] if three_ds_options[:authentication_response_status]
|
199
|
+
three_ds[:three_ds_server_trans_id] = three_ds_options[:three_ds_server_trans_id] if three_ds_options[:three_ds_server_trans_id]
|
200
|
+
|
201
|
+
post[:three_ds_fields] = three_ds
|
202
|
+
end
|
203
|
+
|
204
|
+
def add_card(post, card, card_options = {})
|
205
|
+
card_hash = {}
|
206
|
+
card_hash[:number] = card.number
|
207
|
+
card_hash[:exp_month] = card.month
|
208
|
+
card_hash[:exp_year] = card.year
|
209
|
+
card_hash[:security_code] = card.verification_value
|
210
|
+
card_hash[:type] = card.brand
|
211
|
+
card_hash[:holder_first_name] = card.first_name
|
212
|
+
card_hash[:holder_last_name] = card.last_name
|
213
|
+
post[:card] = card_hash
|
214
|
+
end
|
215
|
+
|
216
|
+
def add_user(post, user_options)
|
217
|
+
user = {}
|
218
|
+
user[:id] = user_options[:id] if user_options[:id]
|
219
|
+
user[:email] = user_options[:email] if user_options[:email]
|
220
|
+
|
221
|
+
post[:user] = user
|
222
|
+
end
|
223
|
+
|
224
|
+
def add_stored_credential(post, options)
|
225
|
+
return unless options[:stored_credential]
|
226
|
+
|
227
|
+
check_initiator = %w[merchant cardholder].any? { |item| item == options[:stored_credential][:initiator] }
|
228
|
+
check_reason_type = %w[recurring installment unscheduled].any? { |item| item == options[:stored_credential][:reason_type] }
|
229
|
+
post[:forward_payload][:authentication] = {} unless post[:forward_payload].key?(:authentication)
|
230
|
+
post[:forward_payload][:authentication][:stored_credential] = options[:stored_credential] if check_initiator && check_reason_type
|
231
|
+
end
|
232
|
+
|
233
|
+
def add_order(post, money, order_options)
|
234
|
+
order = {}
|
235
|
+
order[:id] = order_options[:id] if order_options[:id]
|
236
|
+
order[:description] = order_options[:description] if order_options[:description]
|
237
|
+
order[:installments] = order_options[:installments] if order_options[:installments]
|
238
|
+
order[:datetime_local_transaction] = order_options[:datetime_local_transaction] if order_options[:datetime_local_transaction]
|
239
|
+
|
240
|
+
add_amount(order, money, order_options[:amount]) if order_options[:amount]
|
241
|
+
add_address('shipping_address', order, order_options[:shipping_address]) if order_options[:shipping_address]
|
242
|
+
|
243
|
+
post[:order] = order
|
244
|
+
end
|
245
|
+
|
246
|
+
def add_amount(post, money, amount_options)
|
247
|
+
amount_obj = {}
|
248
|
+
amount_obj[:total_amount] = amount(money).to_f
|
249
|
+
amount_obj[:currency] = (amount_options[:currency] || currency(money))
|
250
|
+
amount_obj[:vat] = amount_options[:vat] if amount_options[:vat]
|
251
|
+
|
252
|
+
post[:amount] = amount_obj
|
253
|
+
end
|
254
|
+
|
255
|
+
def add_address(tag, post, address_options)
|
256
|
+
address = {}
|
257
|
+
address[:name] = address_options[:name] if address_options[:name]
|
258
|
+
address[:address1] = address_options[:address1] if address_options[:address1]
|
259
|
+
address[:address2] = address_options[:address2] if address_options[:address2]
|
260
|
+
address[:company] = address_options[:company] if address_options[:company]
|
261
|
+
address[:city] = address_options[:city] if address_options[:city]
|
262
|
+
address[:state] = address_options[:state] if address_options[:state]
|
263
|
+
address[:zip] = address_options[:zip] if address_options[:zip]
|
264
|
+
address[:country] = address_options[:country] if address_options[:country]
|
265
|
+
address[:phone] = address_options[:phone] if address_options[:phone]
|
266
|
+
address[:fax] = address_options[:fax] if address_options[:fax]
|
267
|
+
|
268
|
+
post[tag] = address
|
269
|
+
end
|
270
|
+
|
271
|
+
def parse(body)
|
272
|
+
JSON.parse(body)
|
273
|
+
end
|
274
|
+
|
275
|
+
def commit(action, parameters, url_params = {})
|
276
|
+
begin
|
277
|
+
response = JSON.parse ssl_post(url(action, url_params), post_data(parameters), authorized_headers())
|
278
|
+
rescue ResponseError => exception
|
279
|
+
case exception.response.code.to_i
|
280
|
+
when 400...499
|
281
|
+
response = JSON.parse exception.response.body
|
282
|
+
else
|
283
|
+
raise exception
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
Response.new(
|
288
|
+
success_from(response['code']),
|
289
|
+
message_from(response),
|
290
|
+
response,
|
291
|
+
authorization: authorization_from(response),
|
292
|
+
avs_result: AVSResult.new(code: avs_code_from(response)),
|
293
|
+
cvv_result: CVVResult.new(cvv_code_from(response)),
|
294
|
+
test: test?,
|
295
|
+
error_code: error_code_from(response)
|
296
|
+
)
|
297
|
+
end
|
298
|
+
|
299
|
+
def avs_code_from(response)
|
300
|
+
response['avs_result']
|
301
|
+
end
|
302
|
+
|
303
|
+
def cvv_code_from(response)
|
304
|
+
response['cvv_result']
|
305
|
+
end
|
306
|
+
|
307
|
+
def success_from(code)
|
308
|
+
code == 'S001'
|
309
|
+
end
|
310
|
+
|
311
|
+
def message_from(response)
|
312
|
+
response['message']
|
313
|
+
end
|
314
|
+
|
315
|
+
def url(action, url_params)
|
316
|
+
"#{(test? ? test_url : live_url)}/#{url_params[:token_acquirer]}/#{action}"
|
317
|
+
end
|
318
|
+
|
319
|
+
def post_data(data = {})
|
320
|
+
data.to_json
|
321
|
+
end
|
322
|
+
|
323
|
+
def authorization_from(response)
|
324
|
+
response['simetrik_authorization_id']
|
325
|
+
end
|
326
|
+
|
327
|
+
def error_code_from(response)
|
328
|
+
STANDARD_ERROR_CODE_MAPPING[response['code']] unless success_from(response['code'])
|
329
|
+
end
|
330
|
+
|
331
|
+
def authorized_headers
|
332
|
+
{
|
333
|
+
'content-Type' => 'application/json',
|
334
|
+
'Authorization' => "Bearer #{sign_access_token()}"
|
335
|
+
}
|
336
|
+
end
|
337
|
+
|
338
|
+
def sign_access_token
|
339
|
+
fetch_access_token() if Time.new.to_i > (@access_token[:expires_at] || 0) + 10
|
340
|
+
@access_token[:access_token]
|
341
|
+
end
|
342
|
+
|
343
|
+
def auth_url
|
344
|
+
(test? ? test_auth_url : live_auth_url)
|
345
|
+
end
|
346
|
+
|
347
|
+
def fetch_access_token
|
348
|
+
login_info = {}
|
349
|
+
login_info[:client_id] = @options[:client_id]
|
350
|
+
login_info[:client_secret] = @options[:client_secret]
|
351
|
+
login_info[:audience] = @options[:audience]
|
352
|
+
login_info[:grant_type] = 'client_credentials'
|
353
|
+
response = parse(ssl_post(auth_url(), login_info.to_json, {
|
354
|
+
'content-Type' => 'application/json'
|
355
|
+
}))
|
356
|
+
|
357
|
+
@access_token[:access_token] = response['access_token']
|
358
|
+
@access_token[:expires_at] = Time.new.to_i + response['expires_in']
|
359
|
+
end
|
360
|
+
end
|
361
|
+
end
|
362
|
+
end
|