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,206 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class PayJunctionV2Gateway < Gateway
|
4
|
+
self.display_name = 'PayJunction'
|
5
|
+
self.homepage_url = 'https://www.payjunction.com/'
|
6
|
+
|
7
|
+
self.test_url = 'https://api.payjunctionlabs.com/transactions'
|
8
|
+
self.live_url = 'https://api.payjunction.com/transactions'
|
9
|
+
|
10
|
+
self.supported_countries = ['US']
|
11
|
+
self.default_currency = 'USD'
|
12
|
+
self.money_format = :dollars
|
13
|
+
self.supported_cardtypes = %i[visa master american_express discover]
|
14
|
+
|
15
|
+
def initialize(options = {})
|
16
|
+
requires!(options, :api_login, :api_password, :api_key)
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def purchase(amount, payment_method, options = {})
|
21
|
+
post = {}
|
22
|
+
add_invoice(post, amount, options)
|
23
|
+
add_payment_method(post, payment_method)
|
24
|
+
add_address(post, options)
|
25
|
+
|
26
|
+
commit('purchase', post)
|
27
|
+
end
|
28
|
+
|
29
|
+
def authorize(amount, payment_method, options = {})
|
30
|
+
post = {}
|
31
|
+
post[:status] = 'HOLD'
|
32
|
+
add_invoice(post, amount, options)
|
33
|
+
add_payment_method(post, payment_method)
|
34
|
+
add_address(post, options)
|
35
|
+
|
36
|
+
commit('authorize', post)
|
37
|
+
end
|
38
|
+
|
39
|
+
def capture(amount, authorization, options = {})
|
40
|
+
post = {}
|
41
|
+
post[:status] = 'CAPTURE'
|
42
|
+
post[:transactionId] = authorization
|
43
|
+
add_invoice(post, amount, options)
|
44
|
+
|
45
|
+
commit('capture', post)
|
46
|
+
end
|
47
|
+
|
48
|
+
def void(authorization, options = {})
|
49
|
+
post = {}
|
50
|
+
post[:status] = 'VOID'
|
51
|
+
post[:transactionId] = authorization
|
52
|
+
|
53
|
+
commit('void', post)
|
54
|
+
end
|
55
|
+
|
56
|
+
def refund(amount, authorization, options = {})
|
57
|
+
post = {}
|
58
|
+
post[:action] = 'REFUND'
|
59
|
+
post[:transactionId] = authorization
|
60
|
+
add_invoice(post, amount, options)
|
61
|
+
|
62
|
+
commit('refund', post)
|
63
|
+
end
|
64
|
+
|
65
|
+
def credit(amount, payment_method, options = {})
|
66
|
+
post = {}
|
67
|
+
post[:action] = 'REFUND'
|
68
|
+
add_invoice(post, amount, options)
|
69
|
+
add_payment_method(post, payment_method)
|
70
|
+
|
71
|
+
commit('credit', post)
|
72
|
+
end
|
73
|
+
|
74
|
+
def verify(credit_card, options = {})
|
75
|
+
MultiResponse.run(:use_first_response) do |r|
|
76
|
+
r.process { authorize(100, credit_card, options) }
|
77
|
+
r.process(:ignore_result) { void(r.authorization, options) }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def store(payment_method, options = {})
|
82
|
+
verify(payment_method, options)
|
83
|
+
end
|
84
|
+
|
85
|
+
def supports_scrubbing?
|
86
|
+
true
|
87
|
+
end
|
88
|
+
|
89
|
+
def scrub(transcript)
|
90
|
+
transcript.
|
91
|
+
gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
|
92
|
+
gsub(%r((X-Pj-Application-Key: )[\w-]+), '\1[FILTERED]').
|
93
|
+
gsub(%r((cardNumber=)\d+), '\1[FILTERED]').
|
94
|
+
gsub(%r((cardCvv=)\d+), '\1[FILTERED]')
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def add_invoice(post, money, options)
|
100
|
+
post[:amountBase] = amount(money) if money
|
101
|
+
post[:invoiceNumber] = options[:order_id] if options[:order_id]
|
102
|
+
end
|
103
|
+
|
104
|
+
def add_payment_method(post, payment_method)
|
105
|
+
if payment_method.is_a? Integer
|
106
|
+
post[:transactionId] = payment_method
|
107
|
+
else
|
108
|
+
post[:cardNumber] = payment_method.number
|
109
|
+
post[:cardExpMonth] = format(payment_method.month, :two_digits)
|
110
|
+
post[:cardExpYear] = format(payment_method.year, :four_digits)
|
111
|
+
post[:cardCvv] = payment_method.verification_value
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def add_address(post, options)
|
116
|
+
if address = options[:billing_address]
|
117
|
+
post[:billingFirstName] = address[:first_name] if address[:first_name]
|
118
|
+
post[:billingLastName] = address[:last_name] if address[:last_name]
|
119
|
+
post[:billingCompanyName] = address[:company] if address[:company]
|
120
|
+
post[:billingPhone] = address[:phone_number] if address[:phone_number]
|
121
|
+
post[:billingAddress] = address[:address1] if address[:address1]
|
122
|
+
post[:billingCity] = address[:city] if address[:city]
|
123
|
+
post[:billingState] = address[:state] if address[:state]
|
124
|
+
post[:billingCountry] = address[:country] if address[:country]
|
125
|
+
post[:billingZip] = address[:zip] if address[:zip]
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def commit(action, params)
|
130
|
+
response =
|
131
|
+
begin
|
132
|
+
parse(ssl_invoke(action, params))
|
133
|
+
rescue ResponseError => e
|
134
|
+
parse(e.response.body)
|
135
|
+
end
|
136
|
+
|
137
|
+
success = success_from(response)
|
138
|
+
Response.new(
|
139
|
+
success,
|
140
|
+
message_from(response),
|
141
|
+
response,
|
142
|
+
authorization: success ? authorization_from(response) : nil,
|
143
|
+
error_code: success ? nil : error_from(response),
|
144
|
+
test: test?
|
145
|
+
)
|
146
|
+
end
|
147
|
+
|
148
|
+
def ssl_invoke(action, params)
|
149
|
+
if %w[purchase authorize refund credit].include?(action)
|
150
|
+
ssl_post(url(), post_data(params), headers)
|
151
|
+
else
|
152
|
+
ssl_request(:put, url(params), post_data(params), headers)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def headers
|
157
|
+
{
|
158
|
+
'Authorization' => 'Basic ' + Base64.encode64("#{@options[:api_login]}:#{@options[:api_password]}").strip,
|
159
|
+
'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8',
|
160
|
+
'Accept' => 'application/json',
|
161
|
+
'X-PJ-Application-Key' => @options[:api_key].to_s
|
162
|
+
}
|
163
|
+
end
|
164
|
+
|
165
|
+
def post_data(params)
|
166
|
+
params.map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&')
|
167
|
+
end
|
168
|
+
|
169
|
+
def url(params = {})
|
170
|
+
test? ? "#{test_url}/#{params[:transactionId]}" : "#{live_url}/#{params[:transactionId]}"
|
171
|
+
end
|
172
|
+
|
173
|
+
def parse(body)
|
174
|
+
JSON.parse(body)
|
175
|
+
rescue JSON::ParserError
|
176
|
+
message = 'Invalid JSON response received from PayJunctionV2Gateway. Please contact PayJunctionV2Gateway if you continue to receive this message.'
|
177
|
+
message += " (The raw response returned by the API was #{body.inspect})"
|
178
|
+
{
|
179
|
+
'errors' => [{
|
180
|
+
'message' => message
|
181
|
+
}]
|
182
|
+
}
|
183
|
+
end
|
184
|
+
|
185
|
+
def success_from(response)
|
186
|
+
return response['response']['approved'] if response['response']
|
187
|
+
|
188
|
+
false
|
189
|
+
end
|
190
|
+
|
191
|
+
def message_from(response)
|
192
|
+
return response['response']['message'] if response['response']
|
193
|
+
|
194
|
+
response['errors']&.inject('') { |message, error| error['message'] + '|' + message }
|
195
|
+
end
|
196
|
+
|
197
|
+
def authorization_from(response)
|
198
|
+
response['transactionId']
|
199
|
+
end
|
200
|
+
|
201
|
+
def error_from(response)
|
202
|
+
response['response']['code'] if response['response']
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
@@ -8,10 +8,10 @@ module ActiveMerchant #:nodoc:
|
|
8
8
|
# Currently Authorization and Capture is not implemented because
|
9
9
|
# capturing requires the original credit card information
|
10
10
|
TRANSACTIONS = {
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
11
|
+
purchase: 'PURCHASE',
|
12
|
+
authorization: 'AUTHORISE',
|
13
|
+
capture: 'ADVICE',
|
14
|
+
credit: 'REFUND'
|
15
15
|
}
|
16
16
|
|
17
17
|
SUCCESS = 'Accepted'
|
@@ -20,7 +20,7 @@ module ActiveMerchant #:nodoc:
|
|
20
20
|
self.supported_countries = ['AU']
|
21
21
|
self.homepage_url = 'http://www.commsecure.com.au/paysecure.shtml'
|
22
22
|
self.display_name = 'PaySecure'
|
23
|
-
self.supported_cardtypes = [
|
23
|
+
self.supported_cardtypes = %i[visa master american_express diners_club]
|
24
24
|
|
25
25
|
def initialize(options = {})
|
26
26
|
requires!(options, :login, :password)
|
@@ -39,10 +39,11 @@ module ActiveMerchant #:nodoc:
|
|
39
39
|
end
|
40
40
|
|
41
41
|
private
|
42
|
+
|
42
43
|
# Used for capturing, which is currently not supported.
|
43
44
|
def add_reference(post, identification)
|
44
|
-
auth, trans_id = identification.split(
|
45
|
-
post[:authnum]
|
45
|
+
auth, trans_id = identification.split(';')
|
46
|
+
post[:authnum] = auth
|
46
47
|
post[:transid] = trans_id
|
47
48
|
end
|
48
49
|
|
@@ -51,7 +52,7 @@ module ActiveMerchant #:nodoc:
|
|
51
52
|
end
|
52
53
|
|
53
54
|
def add_invoice(post, options)
|
54
|
-
post[:merchant_transid] = options[:order_id].to_s.slice(0,21)
|
55
|
+
post[:merchant_transid] = options[:order_id].to_s.slice(0, 21)
|
55
56
|
post[:memnum] = options[:invoice]
|
56
57
|
post[:custnum] = options[:customer]
|
57
58
|
post[:clientdata] = options[:description]
|
@@ -65,13 +66,11 @@ module ActiveMerchant #:nodoc:
|
|
65
66
|
end
|
66
67
|
|
67
68
|
def commit(action, money, parameters)
|
68
|
-
response = parse(
|
69
|
+
response = parse(ssl_post(self.live_url, post_data(action, parameters)))
|
69
70
|
|
70
71
|
Response.new(successful?(response), message_from(response), response,
|
71
|
-
:
|
72
|
-
:
|
73
|
-
)
|
74
|
-
|
72
|
+
test: test_response?(response),
|
73
|
+
authorization: authorization_from(response))
|
75
74
|
end
|
76
75
|
|
77
76
|
def successful?(response)
|
@@ -79,7 +78,7 @@ module ActiveMerchant #:nodoc:
|
|
79
78
|
end
|
80
79
|
|
81
80
|
def authorization_from(response)
|
82
|
-
[
|
81
|
+
[response[:authnum], response[:transid]].compact.join(';')
|
83
82
|
end
|
84
83
|
|
85
84
|
def test_response?(response)
|
@@ -93,7 +92,7 @@ module ActiveMerchant #:nodoc:
|
|
93
92
|
def parse(body)
|
94
93
|
response = {}
|
95
94
|
body.to_s.each_line do |l|
|
96
|
-
key, value = l.split(
|
95
|
+
key, value = l.split(':', 2)
|
97
96
|
response[key.to_s.downcase.to_sym] = value.strip
|
98
97
|
end
|
99
98
|
response
|
@@ -104,9 +103,8 @@ module ActiveMerchant #:nodoc:
|
|
104
103
|
parameters[:merchant_id] = @options[:login]
|
105
104
|
parameters[:password] = @options[:password]
|
106
105
|
|
107
|
-
parameters.reject{|
|
106
|
+
parameters.reject { |_k, v| v.blank? }.collect { |key, value| "#{key.to_s.upcase}=#{CGI.escape(value.to_s)}" }.join('&')
|
108
107
|
end
|
109
108
|
end
|
110
109
|
end
|
111
110
|
end
|
112
|
-
|
@@ -0,0 +1,404 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class PayTraceGateway < Gateway
|
4
|
+
self.test_url = 'https://api.paytrace.com'
|
5
|
+
self.live_url = 'https://api.paytrace.com'
|
6
|
+
|
7
|
+
self.supported_countries = ['US']
|
8
|
+
self.default_currency = 'USD'
|
9
|
+
self.supported_cardtypes = %i[visa master american_express discover]
|
10
|
+
|
11
|
+
self.homepage_url = 'https://paytrace.com/'
|
12
|
+
self.display_name = 'PayTrace'
|
13
|
+
|
14
|
+
# Response codes based on API Response Codes found here: https://developers.paytrace.com/support/home#14000041297
|
15
|
+
STANDARD_ERROR_CODE_MAPPING = {
|
16
|
+
'1' => STANDARD_ERROR_CODE[:error_occurred],
|
17
|
+
'102' => STANDARD_ERROR_CODE[:declined],
|
18
|
+
'103' => STANDARD_ERROR_CODE[:auto_voided],
|
19
|
+
'107' => STANDARD_ERROR_CODE[:unsuccessful_refund],
|
20
|
+
'108' => STANDARD_ERROR_CODE[:test_refund],
|
21
|
+
'110' => STANDARD_ERROR_CODE[:unsuccessful_void],
|
22
|
+
'113' => STANDARD_ERROR_CODE[:unsuccessful_capture]
|
23
|
+
}
|
24
|
+
|
25
|
+
ENDPOINTS = {
|
26
|
+
customer_id_sale: 'transactions/sale/by_customer',
|
27
|
+
keyed_sale: 'transactions/sale/keyed',
|
28
|
+
customer_id_auth: 'transactions/authorization/by_customer',
|
29
|
+
keyed_auth: 'transactions/authorization/keyed',
|
30
|
+
capture: 'transactions/authorization/capture',
|
31
|
+
transaction_refund: 'transactions/refund/for_transaction',
|
32
|
+
transaction_void: 'transactions/void',
|
33
|
+
store: 'customer/create',
|
34
|
+
redact: 'customer/delete',
|
35
|
+
level_3_visa: 'level_three/visa',
|
36
|
+
level_3_mastercard: 'level_three/mastercard'
|
37
|
+
}
|
38
|
+
|
39
|
+
def initialize(options = {})
|
40
|
+
requires!(options, :username, :password, :integrator_id)
|
41
|
+
super
|
42
|
+
acquire_access_token
|
43
|
+
end
|
44
|
+
|
45
|
+
def purchase(money, payment_or_customer_id, options = {})
|
46
|
+
if visa_or_mastercard?(options)
|
47
|
+
MultiResponse.run(:use_first_response) do |r|
|
48
|
+
endpoint = customer_id?(payment_or_customer_id) ? ENDPOINTS[:customer_id_sale] : ENDPOINTS[:keyed_sale]
|
49
|
+
|
50
|
+
r.process { commit(endpoint, build_purchase_request(money, payment_or_customer_id, options)) }
|
51
|
+
r.process { commit(ENDPOINTS[:"level_3_#{options[:visa_or_mastercard]}"], send_level_3_data(r, options)) }
|
52
|
+
end
|
53
|
+
else
|
54
|
+
post = build_purchase_request(money, payment_or_customer_id, options)
|
55
|
+
post[:customer_id] ? endpoint = ENDPOINTS[:customer_id_sale] : endpoint = ENDPOINTS[:keyed_sale]
|
56
|
+
response = commit(endpoint, post)
|
57
|
+
check_token_response(response, endpoint, post, options)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def authorize(money, payment_or_customer_id, options = {})
|
62
|
+
post = {}
|
63
|
+
add_amount(post, money, options)
|
64
|
+
if customer_id?(payment_or_customer_id)
|
65
|
+
post[:customer_id] = payment_or_customer_id
|
66
|
+
endpoint = ENDPOINTS[:customer_id_auth]
|
67
|
+
else
|
68
|
+
add_payment(post, payment_or_customer_id)
|
69
|
+
add_address(post, payment_or_customer_id, options)
|
70
|
+
add_customer_data(post, options)
|
71
|
+
endpoint = ENDPOINTS[:keyed_auth]
|
72
|
+
end
|
73
|
+
response = commit(endpoint, post)
|
74
|
+
check_token_response(response, endpoint, post, options)
|
75
|
+
end
|
76
|
+
|
77
|
+
def capture(money, authorization, options = {})
|
78
|
+
if visa_or_mastercard?(options)
|
79
|
+
MultiResponse.run do |r|
|
80
|
+
r.process { commit(ENDPOINTS[:capture], build_capture_request(money, authorization, options)) }
|
81
|
+
r.process { commit(ENDPOINTS[:"level_3_#{options[:visa_or_mastercard]}"], send_level_3_data(r, options)) }
|
82
|
+
end
|
83
|
+
else
|
84
|
+
post = build_capture_request(money, authorization, options)
|
85
|
+
response = commit(ENDPOINTS[:capture], post)
|
86
|
+
check_token_response(response, ENDPOINTS[:capture], post, options)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def refund(money, authorization, options = {})
|
91
|
+
# currently only support full and partial refunds of settled transactions via a transaction ID
|
92
|
+
post = {}
|
93
|
+
add_amount(post, money, options)
|
94
|
+
post[:transaction_id] = authorization
|
95
|
+
response = commit(ENDPOINTS[:transaction_refund], post)
|
96
|
+
check_token_response(response, ENDPOINTS[:transaction_refund], post, options)
|
97
|
+
end
|
98
|
+
|
99
|
+
def void(authorization, options = {})
|
100
|
+
post = {}
|
101
|
+
post[:transaction_id] = authorization
|
102
|
+
|
103
|
+
response = commit(ENDPOINTS[:transaction_void], post)
|
104
|
+
check_token_response(response, ENDPOINTS[:transaction_void], post, options)
|
105
|
+
end
|
106
|
+
|
107
|
+
def verify(credit_card, options = {})
|
108
|
+
authorize(0, credit_card, options)
|
109
|
+
end
|
110
|
+
|
111
|
+
# The customer_IDs that come from storing cards can be used for auth and purchase transaction types
|
112
|
+
def store(credit_card, options = {})
|
113
|
+
post = {}
|
114
|
+
post[:customer_id] = options[:customer_id] || SecureRandom.hex(12)
|
115
|
+
add_payment(post, credit_card)
|
116
|
+
add_address(post, credit_card, options)
|
117
|
+
response = commit(ENDPOINTS[:store], post)
|
118
|
+
check_token_response(response, ENDPOINTS[:store], post, options)
|
119
|
+
end
|
120
|
+
|
121
|
+
def unstore(customer_id)
|
122
|
+
post = {}
|
123
|
+
post[:customer_id] = customer_id
|
124
|
+
response = commit(ENDPOINTS[:redact], post)
|
125
|
+
check_token_response(response, ENDPOINTS[:redact], post, options)
|
126
|
+
end
|
127
|
+
|
128
|
+
def supports_scrubbing?
|
129
|
+
true
|
130
|
+
end
|
131
|
+
|
132
|
+
def scrub(transcript)
|
133
|
+
transcript.
|
134
|
+
gsub(%r((Authorization: Bearer )[a-zA-Z0-9:_]+), '\1[FILTERED]').
|
135
|
+
gsub(%r(("credit_card\\?":{\\?"number\\?":\\?")\d+), '\1[FILTERED]').
|
136
|
+
gsub(%r(("cvv\\?":\\?")\d+), '\1[FILTERED]').
|
137
|
+
gsub(%r(("username\\?":\\?")\w+@+\w+.+\w+), '\1[FILTERED]').
|
138
|
+
gsub(%r(("password\\?":\\?")\w+), '\1[FILTERED]').
|
139
|
+
gsub(%r(("integrator_id\\?":\\?")\w+), '\1[FILTERED]')
|
140
|
+
end
|
141
|
+
|
142
|
+
def acquire_access_token
|
143
|
+
post = {}
|
144
|
+
post[:grant_type] = 'password'
|
145
|
+
post[:username] = @options[:username]
|
146
|
+
post[:password] = @options[:password]
|
147
|
+
data = post.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join('&')
|
148
|
+
url = live_url + '/oauth/token'
|
149
|
+
oauth_headers = {
|
150
|
+
'Accept' => '*/*',
|
151
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
152
|
+
}
|
153
|
+
response = ssl_post(url, data, oauth_headers)
|
154
|
+
json_response = JSON.parse(response)
|
155
|
+
|
156
|
+
@options[:access_token] = json_response['access_token'] if json_response['access_token']
|
157
|
+
response
|
158
|
+
end
|
159
|
+
|
160
|
+
private
|
161
|
+
|
162
|
+
def build_purchase_request(money, payment_or_customer_id, options)
|
163
|
+
post = {}
|
164
|
+
add_amount(post, money, options)
|
165
|
+
if customer_id?(payment_or_customer_id)
|
166
|
+
post[:customer_id] = payment_or_customer_id
|
167
|
+
else
|
168
|
+
add_payment(post, payment_or_customer_id)
|
169
|
+
add_address(post, payment_or_customer_id, options)
|
170
|
+
add_customer_data(post, options)
|
171
|
+
end
|
172
|
+
|
173
|
+
post
|
174
|
+
end
|
175
|
+
|
176
|
+
def build_capture_request(money, authorization, options)
|
177
|
+
post = {}
|
178
|
+
post[:transaction_id] = authorization
|
179
|
+
add_amount(post, money, options)
|
180
|
+
|
181
|
+
post
|
182
|
+
end
|
183
|
+
|
184
|
+
# method can only be used to add level 3 data to any approved and unsettled sale transaction so it is built into the standard purchase workflow above
|
185
|
+
def send_level_3_data(response, options)
|
186
|
+
post = {}
|
187
|
+
post[:transaction_id] = response.authorization
|
188
|
+
add_level_3_data(post, options)
|
189
|
+
|
190
|
+
post
|
191
|
+
end
|
192
|
+
|
193
|
+
def visa_or_mastercard?(options)
|
194
|
+
return false unless options[:visa_or_mastercard]
|
195
|
+
|
196
|
+
options[:visa_or_mastercard] == 'visa' || options[:visa_or_mastercard] == 'mastercard'
|
197
|
+
end
|
198
|
+
|
199
|
+
def customer_id?(payment_or_customer_id)
|
200
|
+
payment_or_customer_id.class == String
|
201
|
+
end
|
202
|
+
|
203
|
+
def string_literal_to_boolean(value)
|
204
|
+
return value unless value.class == String
|
205
|
+
|
206
|
+
if value.casecmp('true').zero?
|
207
|
+
true
|
208
|
+
elsif value.casecmp('false').zero?
|
209
|
+
false
|
210
|
+
else return nil
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def add_customer_data(post, options)
|
215
|
+
return unless options[:email]
|
216
|
+
|
217
|
+
post[:email] = options[:email]
|
218
|
+
end
|
219
|
+
|
220
|
+
def add_address(post, creditcard, options)
|
221
|
+
return unless options[:billing_address] || options[:address]
|
222
|
+
|
223
|
+
address = options[:billing_address] || options[:address]
|
224
|
+
post[:billing_address] = {}
|
225
|
+
post[:billing_address][:name] = creditcard.name
|
226
|
+
post[:billing_address][:street_address] = address[:address1]
|
227
|
+
post[:billing_address][:city] = address[:city]
|
228
|
+
post[:billing_address][:state] = address[:state]
|
229
|
+
post[:billing_address][:zip] = address[:zip]
|
230
|
+
end
|
231
|
+
|
232
|
+
def add_amount(post, money, options)
|
233
|
+
post[:amount] = amount(money)
|
234
|
+
end
|
235
|
+
|
236
|
+
def add_payment(post, payment)
|
237
|
+
post[:credit_card] = {}
|
238
|
+
post[:credit_card][:number] = payment.number
|
239
|
+
post[:credit_card][:expiration_month] = payment.month
|
240
|
+
post[:credit_card][:expiration_year] = payment.year
|
241
|
+
end
|
242
|
+
|
243
|
+
def add_level_3_data(post, options)
|
244
|
+
post[:invoice_id] = options[:invoice_id] if options[:invoice_id]
|
245
|
+
post[:customer_reference_id] = options[:customer_reference_id] if options[:customer_reference_id]
|
246
|
+
post[:tax_amount] = options[:tax_amount].to_i if options[:tax_amount]
|
247
|
+
post[:national_tax_amount] = options[:national_tax_amount].to_i if options[:national_tax_amount]
|
248
|
+
post[:merchant_tax_id] = options[:merchant_tax_id] if options[:merchant_tax_id]
|
249
|
+
post[:customer_tax_id] = options[:customer_tax_id] if options[:customer_tax_id]
|
250
|
+
post[:commodity_code] = options[:commodity_code] if options[:commodity_code]
|
251
|
+
post[:discount_amount] = options[:discount_amount].to_i if options[:discount_amount]
|
252
|
+
post[:freight_amount] = options[:freight_amount].to_i if options[:freight_amount]
|
253
|
+
post[:duty_amount] = options[:duty_amount].to_i if options[:duty_amount]
|
254
|
+
post[:additional_tax_amount] = options[:additional_tax_amount].to_i if options[:additional_tax_amount]
|
255
|
+
post[:additional_tax_rate] = options[:additional_tax_rate].to_i if options[:additional_tax_rate]
|
256
|
+
|
257
|
+
add_source_address(post, options)
|
258
|
+
add_shipping_address(post, options)
|
259
|
+
add_line_items(post, options)
|
260
|
+
end
|
261
|
+
|
262
|
+
def add_source_address(post, options)
|
263
|
+
return unless source_address = options[:source_address] ||
|
264
|
+
options[:billing_address] ||
|
265
|
+
options[:address]
|
266
|
+
|
267
|
+
post[:source_address] = {}
|
268
|
+
post[:source_address][:zip] = source_address[:zip] if source_address[:zip]
|
269
|
+
end
|
270
|
+
|
271
|
+
def add_shipping_address(post, options)
|
272
|
+
return unless shipping_address = options[:shipping_address]
|
273
|
+
|
274
|
+
post[:shipping_address] = {}
|
275
|
+
post[:shipping_address][:name] = shipping_address[:name] if shipping_address[:name]
|
276
|
+
post[:shipping_address][:street_address] = shipping_address[:address1] if shipping_address[:address1]
|
277
|
+
post[:shipping_address][:street_address2] = shipping_address[:address2] if shipping_address[:address2]
|
278
|
+
post[:shipping_address][:city] = shipping_address[:city] if shipping_address[:city]
|
279
|
+
post[:shipping_address][:state] = shipping_address[:state] if shipping_address[:state]
|
280
|
+
post[:shipping_address][:zip] = shipping_address[:zip] if shipping_address[:zip]
|
281
|
+
post[:shipping_address][:country] = shipping_address[:country] if shipping_address[:country]
|
282
|
+
end
|
283
|
+
|
284
|
+
def add_line_items(post, options)
|
285
|
+
return unless options[:line_items]
|
286
|
+
|
287
|
+
line_items = []
|
288
|
+
options[:line_items].each do |li|
|
289
|
+
obj = {}
|
290
|
+
|
291
|
+
obj[:additional_tax_amount] = li[:additional_tax_amount].to_i if li[:additional_tax_amount]
|
292
|
+
obj[:additional_tax_included] = string_literal_to_boolean(li[:additional_tax_included]) if li[:additional_tax_included]
|
293
|
+
obj[:additional_tax_rate] = li[:additional_tax_rate].to_i if li[:additional_tax_rate]
|
294
|
+
obj[:amount] = li[:amount].to_i if li[:amount]
|
295
|
+
obj[:commodity_code] = li[:commodity_code] if li[:commodity_code]
|
296
|
+
obj[:debit_or_credit] = li[:debit_or_credit] if li[:debit_or_credit]
|
297
|
+
obj[:description] = li[:description] if li[:description]
|
298
|
+
obj[:discount_amount] = li[:discount_amount].to_i if li[:discount_amount]
|
299
|
+
obj[:discount_rate] = li[:discount_rate].to_i if li[:discount_rate]
|
300
|
+
obj[:discount_included] = string_literal_to_boolean(li[:discount_included]) if li[:discount_included]
|
301
|
+
obj[:merchant_tax_id] = li[:merchant_tax_id] if li[:merchant_tax_id]
|
302
|
+
obj[:product_id] = li[:product_id] if li[:product_id]
|
303
|
+
obj[:quantity] = li[:quantity] if li[:quantity]
|
304
|
+
obj[:transaction_id] = li[:transaction_id] if li[:transaction_id]
|
305
|
+
obj[:tax_included] = string_literal_to_boolean(li[:tax_included]) if li[:tax_included]
|
306
|
+
obj[:unit_of_measure] = li[:unit_of_measure] if li[:unit_of_measure]
|
307
|
+
obj[:unit_cost] = li[:unit_cost].to_i if li[:unit_cost]
|
308
|
+
|
309
|
+
line_items << obj
|
310
|
+
end
|
311
|
+
post[:line_items] = line_items
|
312
|
+
end
|
313
|
+
|
314
|
+
def check_token_response(response, endpoint, body = {}, options = {})
|
315
|
+
return response unless response.params['error'] == 'invalid_token'
|
316
|
+
|
317
|
+
acquire_access_token
|
318
|
+
commit(endpoint, body)
|
319
|
+
end
|
320
|
+
|
321
|
+
def parse(body)
|
322
|
+
JSON.parse(body)
|
323
|
+
end
|
324
|
+
|
325
|
+
def commit(action, parameters)
|
326
|
+
base_url = (test? ? test_url : live_url)
|
327
|
+
url = base_url + '/v1/' + action
|
328
|
+
raw_response = ssl_post(url, post_data(parameters), headers)
|
329
|
+
response = parse(raw_response)
|
330
|
+
success = success_from(response)
|
331
|
+
|
332
|
+
Response.new(
|
333
|
+
success,
|
334
|
+
message_from(success, response),
|
335
|
+
response,
|
336
|
+
authorization: authorization_from(action, response),
|
337
|
+
avs_result: AVSResult.new(code: response['avs_response']),
|
338
|
+
cvv_result: response['csc_response'],
|
339
|
+
test: test?,
|
340
|
+
error_code: success ? nil : error_code_from(response)
|
341
|
+
)
|
342
|
+
rescue JSON::ParserError
|
343
|
+
unparsable_response(raw_response)
|
344
|
+
end
|
345
|
+
|
346
|
+
def unparsable_response(raw_response)
|
347
|
+
message = 'Unparsable response received from PayTrace. Please contact PayTrace if you continue to receive this message.'
|
348
|
+
message += " (The raw response returned by the API was #{raw_response.inspect})"
|
349
|
+
return Response.new(false, message)
|
350
|
+
end
|
351
|
+
|
352
|
+
def headers
|
353
|
+
{
|
354
|
+
'Content-type' => 'application/json',
|
355
|
+
'Authorization' => 'Bearer ' + @options[:access_token]
|
356
|
+
}
|
357
|
+
end
|
358
|
+
|
359
|
+
def success_from(response)
|
360
|
+
response['success']
|
361
|
+
end
|
362
|
+
|
363
|
+
def message_from(success, response)
|
364
|
+
return response['status_message'] if success
|
365
|
+
|
366
|
+
if error = response['errors']
|
367
|
+
message = 'Errors-'
|
368
|
+
error.each do |k, v|
|
369
|
+
message.concat(" code:#{k}, message:#{v}")
|
370
|
+
end
|
371
|
+
else
|
372
|
+
message = response['status_message'].to_s + " #{response['approval_message']}"
|
373
|
+
end
|
374
|
+
|
375
|
+
message
|
376
|
+
end
|
377
|
+
|
378
|
+
# store transactions do not return a transaction_id, but they return a customer_id that will then be used as the third_party_token for the stored payment method
|
379
|
+
def authorization_from(action, response)
|
380
|
+
if action == ENDPOINTS[:store]
|
381
|
+
response['customer_id']
|
382
|
+
else
|
383
|
+
response['transaction_id']
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
def post_data(parameters = {})
|
388
|
+
parameters[:password] = @options[:password]
|
389
|
+
parameters[:username] = @options[:username]
|
390
|
+
parameters[:integrator_id] = @options[:integrator_id]
|
391
|
+
|
392
|
+
parameters.to_json
|
393
|
+
end
|
394
|
+
|
395
|
+
def error_code_from(response)
|
396
|
+
STANDARD_ERROR_CODE_MAPPING[response['response_code']]
|
397
|
+
end
|
398
|
+
|
399
|
+
def handle_response(response)
|
400
|
+
response.body
|
401
|
+
end
|
402
|
+
end
|
403
|
+
end
|
404
|
+
end
|