swiss-crm-activemerchant 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG +4033 -0
- data/CONTRIBUTORS +568 -0
- data/MIT-LICENSE +20 -0
- data/README.md +252 -0
- data/lib/active_merchant/billing/apple_pay_payment_token.rb +22 -0
- data/lib/active_merchant/billing/avs_result.rb +95 -0
- data/lib/active_merchant/billing/base.rb +48 -0
- data/lib/active_merchant/billing/check.rb +112 -0
- data/lib/active_merchant/billing/compatibility.rb +118 -0
- data/lib/active_merchant/billing/credit_card.rb +451 -0
- data/lib/active_merchant/billing/credit_card_formatting.rb +24 -0
- data/lib/active_merchant/billing/credit_card_methods.rb +512 -0
- data/lib/active_merchant/billing/cvv_result.rb +37 -0
- data/lib/active_merchant/billing/gateway.rb +332 -0
- data/lib/active_merchant/billing/gateways/adyen.rb +774 -0
- data/lib/active_merchant/billing/gateways/airwallex.rb +370 -0
- data/lib/active_merchant/billing/gateways/alelo.rb +256 -0
- data/lib/active_merchant/billing/gateways/allied_wallet.rb +205 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +1125 -0
- data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +424 -0
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +977 -0
- data/lib/active_merchant/billing/gateways/axcessms.rb +242 -0
- data/lib/active_merchant/billing/gateways/balanced.rb +263 -0
- data/lib/active_merchant/billing/gateways/bambora_apac.rb +222 -0
- data/lib/active_merchant/billing/gateways/bank_frick.rb +225 -0
- data/lib/active_merchant/billing/gateways/banwire.rb +116 -0
- data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +397 -0
- data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +15 -0
- data/lib/active_merchant/billing/gateways/be2bill.rb +131 -0
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +474 -0
- data/lib/active_merchant/billing/gateways/beanstream.rb +238 -0
- data/lib/active_merchant/billing/gateways/beanstream_interac.rb +57 -0
- data/lib/active_merchant/billing/gateways/blue_pay.rb +549 -0
- data/lib/active_merchant/billing/gateways/blue_snap.rb +644 -0
- data/lib/active_merchant/billing/gateways/bogus.rb +190 -0
- data/lib/active_merchant/billing/gateways/borgun.rb +272 -0
- data/lib/active_merchant/billing/gateways/bpoint.rb +277 -0
- data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +28 -0
- data/lib/active_merchant/billing/gateways/braintree/token_nonce.rb +113 -0
- data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
- data/lib/active_merchant/billing/gateways/braintree_blue.rb +952 -0
- data/lib/active_merchant/billing/gateways/braintree_orange.rb +19 -0
- data/lib/active_merchant/billing/gateways/bridge_pay.rb +244 -0
- data/lib/active_merchant/billing/gateways/cams.rb +230 -0
- data/lib/active_merchant/billing/gateways/card_connect.rb +338 -0
- data/lib/active_merchant/billing/gateways/card_save.rb +21 -0
- data/lib/active_merchant/billing/gateways/card_stream.rb +394 -0
- 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 +235 -0
- data/lib/active_merchant/billing/gateways/cc5.rb +198 -0
- data/lib/active_merchant/billing/gateways/cecabank.rb +249 -0
- data/lib/active_merchant/billing/gateways/cenpos.rb +328 -0
- data/lib/active_merchant/billing/gateways/checkout.rb +212 -0
- data/lib/active_merchant/billing/gateways/checkout_v2.rb +587 -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/commerce_hub.rb +366 -0
- data/lib/active_merchant/billing/gateways/commercegate.rb +142 -0
- data/lib/active_merchant/billing/gateways/conekta.rb +230 -0
- data/lib/active_merchant/billing/gateways/creditcall.rb +272 -0
- data/lib/active_merchant/billing/gateways/credorax.rb +526 -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/cyber_source_common.rb +36 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +1148 -0
- data/lib/active_merchant/billing/gateways/cyber_source_rest.rb +454 -0
- data/lib/active_merchant/billing/gateways/d_local.rb +343 -0
- data/lib/active_merchant/billing/gateways/data_cash.rb +302 -0
- data/lib/active_merchant/billing/gateways/decidir.rb +358 -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 +346 -0
- data/lib/active_merchant/billing/gateways/efsnet.rb +215 -0
- data/lib/active_merchant/billing/gateways/elavon.rb +475 -0
- data/lib/active_merchant/billing/gateways/element.rb +406 -0
- data/lib/active_merchant/billing/gateways/epay.rb +296 -0
- data/lib/active_merchant/billing/gateways/evo_ca.rb +307 -0
- data/lib/active_merchant/billing/gateways/eway.rb +226 -0
- data/lib/active_merchant/billing/gateways/eway_managed.rb +289 -0
- data/lib/active_merchant/billing/gateways/eway_rapid.rb +578 -0
- data/lib/active_merchant/billing/gateways/exact.rb +219 -0
- data/lib/active_merchant/billing/gateways/ezic.rb +195 -0
- data/lib/active_merchant/billing/gateways/fat_zebra.rb +223 -0
- data/lib/active_merchant/billing/gateways/federated_canada.rb +158 -0
- data/lib/active_merchant/billing/gateways/finansbank.rb +22 -0
- data/lib/active_merchant/billing/gateways/first_giving.rb +143 -0
- data/lib/active_merchant/billing/gateways/first_pay.rb +182 -0
- data/lib/active_merchant/billing/gateways/firstdata_e4.rb +452 -0
- 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/fluidpay.rb +275 -0
- data/lib/active_merchant/billing/gateways/forte.rb +286 -0
- data/lib/active_merchant/billing/gateways/garanti.rb +256 -0
- data/lib/active_merchant/billing/gateways/global_collect.rb +580 -0
- data/lib/active_merchant/billing/gateways/global_transport.rb +193 -0
- data/lib/active_merchant/billing/gateways/hdfc.rb +205 -0
- data/lib/active_merchant/billing/gateways/hps.rb +472 -0
- data/lib/active_merchant/billing/gateways/iats_payments.rb +312 -0
- data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +15 -0
- data/lib/active_merchant/billing/gateways/inspire.rb +213 -0
- data/lib/active_merchant/billing/gateways/instapay.rb +159 -0
- data/lib/active_merchant/billing/gateways/ipg.rb +420 -0
- data/lib/active_merchant/billing/gateways/ipp.rb +176 -0
- data/lib/active_merchant/billing/gateways/iridium.rb +467 -0
- data/lib/active_merchant/billing/gateways/itransact.rb +448 -0
- data/lib/active_merchant/billing/gateways/iveri.rb +290 -0
- data/lib/active_merchant/billing/gateways/ixopay.rb +320 -0
- data/lib/active_merchant/billing/gateways/jetpay.rb +395 -0
- data/lib/active_merchant/billing/gateways/jetpay_v2.rb +432 -0
- data/lib/active_merchant/billing/gateways/klarna.rb +317 -0
- data/lib/active_merchant/billing/gateways/komoju.rb +115 -0
- data/lib/active_merchant/billing/gateways/kushki.rb +297 -0
- data/lib/active_merchant/billing/gateways/latitude19.rb +412 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +448 -0
- data/lib/active_merchant/billing/gateways/litle.rb +643 -0
- data/lib/active_merchant/billing/gateways/mastercard.rb +286 -0
- data/lib/active_merchant/billing/gateways/maxipago.rb +220 -0
- data/lib/active_merchant/billing/gateways/mercado_pago.rb +348 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +228 -0
- data/lib/active_merchant/billing/gateways/merchant_one.rb +110 -0
- data/lib/active_merchant/billing/gateways/merchant_partners.rb +245 -0
- data/lib/active_merchant/billing/gateways/merchant_ware.rb +313 -0
- data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +284 -0
- data/lib/active_merchant/billing/gateways/merchant_warrior.rb +248 -0
- data/lib/active_merchant/billing/gateways/mercury.rb +352 -0
- data/lib/active_merchant/billing/gateways/metrics_global.rb +293 -0
- data/lib/active_merchant/billing/gateways/micropayment.rb +182 -0
- data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
- data/lib/active_merchant/billing/gateways/migs.rb +329 -0
- data/lib/active_merchant/billing/gateways/mit.rb +260 -0
- data/lib/active_merchant/billing/gateways/modern_payments.rb +37 -0
- data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +215 -0
- data/lib/active_merchant/billing/gateways/moka.rb +290 -0
- data/lib/active_merchant/billing/gateways/monei.rb +424 -0
- data/lib/active_merchant/billing/gateways/moneris.rb +488 -0
- data/lib/active_merchant/billing/gateways/money_movers.rb +150 -0
- data/lib/active_merchant/billing/gateways/mundipagg.rb +366 -0
- data/lib/active_merchant/billing/gateways/nab_transact.rb +299 -0
- data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +163 -0
- data/lib/active_merchant/billing/gateways/net_registry.rb +198 -0
- data/lib/active_merchant/billing/gateways/netaxept.rb +180 -0
- data/lib/active_merchant/billing/gateways/netbanx.rb +376 -0
- data/lib/active_merchant/billing/gateways/netbilling.rb +229 -0
- data/lib/active_merchant/billing/gateways/netpay.rb +223 -0
- data/lib/active_merchant/billing/gateways/network_merchants.rb +238 -0
- data/lib/active_merchant/billing/gateways/nmi.rb +396 -0
- data/lib/active_merchant/billing/gateways/ogone.rb +509 -0
- data/lib/active_merchant/billing/gateways/omise.rb +323 -0
- data/lib/active_merchant/billing/gateways/openpay.rb +246 -0
- data/lib/active_merchant/billing/gateways/opp.rb +394 -0
- data/lib/active_merchant/billing/gateways/optimal_payment.rb +331 -0
- data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +45 -0
- data/lib/active_merchant/billing/gateways/orbital.rb +1267 -0
- data/lib/active_merchant/billing/gateways/pac_net_raven.rb +206 -0
- data/lib/active_merchant/billing/gateways/pagarme.rb +239 -0
- data/lib/active_merchant/billing/gateways/pago_facil.rb +120 -0
- 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 +277 -0
- data/lib/active_merchant/billing/gateways/pay_hub.rb +213 -0
- data/lib/active_merchant/billing/gateways/pay_junction.rb +390 -0
- data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +206 -0
- data/lib/active_merchant/billing/gateways/pay_secure.rb +110 -0
- data/lib/active_merchant/billing/gateways/pay_trace.rb +450 -0
- data/lib/active_merchant/billing/gateways/paybox_direct.rb +224 -0
- data/lib/active_merchant/billing/gateways/payeezy.rb +513 -0
- data/lib/active_merchant/billing/gateways/payex.rb +409 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +235 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +42 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
- data/lib/active_merchant/billing/gateways/payflow.rb +473 -0
- data/lib/active_merchant/billing/gateways/payflow_express.rb +220 -0
- data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +14 -0
- data/lib/active_merchant/billing/gateways/payflow_uk.rb +20 -0
- data/lib/active_merchant/billing/gateways/payment_express.rb +373 -0
- data/lib/active_merchant/billing/gateways/paymentez.rb +365 -0
- data/lib/active_merchant/billing/gateways/paymill.rb +369 -0
- data/lib/active_merchant/billing/gateways/paynetworx.rb +228 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +718 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +69 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +262 -0
- data/lib/active_merchant/billing/gateways/paypal.rb +136 -0
- data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
- data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +44 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +272 -0
- data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
- data/lib/active_merchant/billing/gateways/paypal_standard.rb +281 -0
- data/lib/active_merchant/billing/gateways/paysafe.rb +420 -0
- data/lib/active_merchant/billing/gateways/payscout.rb +159 -0
- data/lib/active_merchant/billing/gateways/paystation.rb +204 -0
- data/lib/active_merchant/billing/gateways/payu_in.rb +249 -0
- data/lib/active_merchant/billing/gateways/payu_latam.rb +482 -0
- data/lib/active_merchant/billing/gateways/payway.rb +207 -0
- data/lib/active_merchant/billing/gateways/payway_dot_com.rb +253 -0
- data/lib/active_merchant/billing/gateways/pin.rb +273 -0
- data/lib/active_merchant/billing/gateways/pixxels.rb +263 -0
- data/lib/active_merchant/billing/gateways/plexo.rb +308 -0
- data/lib/active_merchant/billing/gateways/plugnpay.rb +283 -0
- data/lib/active_merchant/billing/gateways/priority.rb +392 -0
- data/lib/active_merchant/billing/gateways/pro_pay.rb +325 -0
- data/lib/active_merchant/billing/gateways/psigate.rb +227 -0
- data/lib/active_merchant/billing/gateways/psl_card.rb +295 -0
- data/lib/active_merchant/billing/gateways/qbms.rb +302 -0
- data/lib/active_merchant/billing/gateways/quantum.rb +274 -0
- 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 +24 -0
- data/lib/active_merchant/billing/gateways/qvalent.rb +305 -0
- data/lib/active_merchant/billing/gateways/rapyd.rb +319 -0
- data/lib/active_merchant/billing/gateways/reach.rb +277 -0
- data/lib/active_merchant/billing/gateways/realex.rb +400 -0
- data/lib/active_merchant/billing/gateways/redsys.rb +723 -0
- 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 +446 -0
- data/lib/active_merchant/billing/gateways/sage_pay.rb +434 -0
- data/lib/active_merchant/billing/gateways/sallie_mae.rb +141 -0
- data/lib/active_merchant/billing/gateways/secure_net.rb +260 -0
- data/lib/active_merchant/billing/gateways/secure_pay.rb +191 -0
- data/lib/active_merchant/billing/gateways/secure_pay_au.rb +290 -0
- data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +103 -0
- data/lib/active_merchant/billing/gateways/securion_pay.rb +305 -0
- data/lib/active_merchant/billing/gateways/shift4.rb +345 -0
- data/lib/active_merchant/billing/gateways/simetrik.rb +368 -0
- data/lib/active_merchant/billing/gateways/skip_jack.rb +450 -0
- data/lib/active_merchant/billing/gateways/smart_ps.rb +274 -0
- data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
- data/lib/active_merchant/billing/gateways/spreedly_core.rb +354 -0
- data/lib/active_merchant/billing/gateways/stripe.rb +866 -0
- data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +602 -0
- data/lib/active_merchant/billing/gateways/swipe_checkout.rb +151 -0
- data/lib/active_merchant/billing/gateways/telr.rb +273 -0
- data/lib/active_merchant/billing/gateways/tns.rb +23 -0
- data/lib/active_merchant/billing/gateways/trans_first.rb +240 -0
- 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 +21 -0
- data/lib/active_merchant/billing/gateways/transnational.rb +9 -0
- data/lib/active_merchant/billing/gateways/trexle.rb +221 -0
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +500 -0
- data/lib/active_merchant/billing/gateways/usa_epay.rb +24 -0
- data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1612 -0
- data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +367 -0
- data/lib/active_merchant/billing/gateways/vanco.rb +303 -0
- data/lib/active_merchant/billing/gateways/verifi.rb +224 -0
- data/lib/active_merchant/billing/gateways/viaklix.rb +171 -0
- data/lib/active_merchant/billing/gateways/visanet_peru.rb +250 -0
- data/lib/active_merchant/billing/gateways/vpos.rb +223 -0
- data/lib/active_merchant/billing/gateways/webpay.rb +97 -0
- data/lib/active_merchant/billing/gateways/wepay.rb +235 -0
- data/lib/active_merchant/billing/gateways/wirecard.rb +430 -0
- data/lib/active_merchant/billing/gateways/wompi.rb +197 -0
- data/lib/active_merchant/billing/gateways/world_net.rb +345 -0
- data/lib/active_merchant/billing/gateways/worldpay.rb +1050 -0
- data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +208 -0
- data/lib/active_merchant/billing/gateways/worldpay_us.rb +221 -0
- data/lib/active_merchant/billing/gateways.rb +14 -0
- data/lib/active_merchant/billing/model.rb +30 -0
- data/lib/active_merchant/billing/network_tokenization_credit_card.rb +39 -0
- data/lib/active_merchant/billing/payment_token.rb +21 -0
- data/lib/active_merchant/billing/rails.rb +3 -0
- data/lib/active_merchant/billing/response.rb +121 -0
- data/lib/active_merchant/billing/three_d_secure_eci_mapper.rb +27 -0
- data/lib/active_merchant/billing.rb +16 -0
- data/lib/active_merchant/connection.rb +194 -0
- data/lib/active_merchant/country.rb +338 -0
- data/lib/active_merchant/empty.rb +20 -0
- data/lib/active_merchant/errors.rb +38 -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 +3 -0
- data/lib/active_merchant.rb +63 -0
- data/lib/activemerchant.rb +1 -0
- data/lib/certs/cacert.pem +3214 -0
- data/lib/support/gateway_support.rb +69 -0
- data/lib/support/outbound_hosts.rb +28 -0
- data/lib/support/ssl_verify.rb +88 -0
- data/lib/support/ssl_version.rb +86 -0
- metadata +506 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'digest/md5'
|
3
|
+
|
4
|
+
require 'active_merchant/billing/gateways/quickpay/quickpay_v10'
|
5
|
+
require 'active_merchant/billing/gateways/quickpay/quickpay_v4to7'
|
6
|
+
|
7
|
+
module ActiveMerchant #:nodoc:
|
8
|
+
module Billing #:nodoc:
|
9
|
+
class QuickpayGateway < Gateway
|
10
|
+
self.abstract_class = true
|
11
|
+
|
12
|
+
def self.new(options = {})
|
13
|
+
options.fetch(:login) { raise ArgumentError.new('Missing required parameter: login') }
|
14
|
+
|
15
|
+
version = options[:login].to_i < 10000000 ? 10 : 7
|
16
|
+
if version <= 7
|
17
|
+
QuickpayV4to7Gateway.new(options)
|
18
|
+
else
|
19
|
+
QuickpayV10Gateway.new(options)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,305 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class QvalentGateway < Gateway
|
4
|
+
self.display_name = 'Qvalent'
|
5
|
+
self.homepage_url = 'https://www.qvalent.com/'
|
6
|
+
|
7
|
+
self.test_url = 'https://ccapi.client.support.qvalent.com/post/CreditCardAPIReceiver'
|
8
|
+
self.live_url = 'https://ccapi.client.qvalent.com/post/CreditCardAPIReceiver'
|
9
|
+
|
10
|
+
self.supported_countries = ['AU']
|
11
|
+
self.default_currency = 'AUD'
|
12
|
+
self.money_format = :cents
|
13
|
+
self.supported_cardtypes = %i[visa master american_express discover jcb diners]
|
14
|
+
|
15
|
+
CVV_CODE_MAPPING = {
|
16
|
+
'S' => 'D'
|
17
|
+
}
|
18
|
+
|
19
|
+
def initialize(options = {})
|
20
|
+
requires!(options, :username, :password, :merchant, :pem)
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
def purchase(amount, payment_method, options = {})
|
25
|
+
post = {}
|
26
|
+
add_invoice(post, amount, options)
|
27
|
+
add_order_number(post, options)
|
28
|
+
add_payment_method(post, payment_method)
|
29
|
+
add_verification_value(post, payment_method)
|
30
|
+
add_stored_credential_data(post, payment_method, options)
|
31
|
+
add_customer_data(post, options)
|
32
|
+
add_soft_descriptors(post, options)
|
33
|
+
add_customer_reference(post, options)
|
34
|
+
|
35
|
+
commit('capture', post)
|
36
|
+
end
|
37
|
+
|
38
|
+
def authorize(amount, payment_method, options = {})
|
39
|
+
post = {}
|
40
|
+
add_invoice(post, amount, options)
|
41
|
+
add_order_number(post, options)
|
42
|
+
add_payment_method(post, payment_method)
|
43
|
+
add_verification_value(post, payment_method)
|
44
|
+
add_stored_credential_data(post, payment_method, options)
|
45
|
+
add_customer_data(post, options)
|
46
|
+
add_soft_descriptors(post, options)
|
47
|
+
add_customer_reference(post, options)
|
48
|
+
|
49
|
+
commit('preauth', post)
|
50
|
+
end
|
51
|
+
|
52
|
+
def capture(amount, authorization, options = {})
|
53
|
+
post = {}
|
54
|
+
add_invoice(post, amount, options)
|
55
|
+
add_reference(post, authorization, options)
|
56
|
+
add_customer_data(post, options)
|
57
|
+
add_soft_descriptors(post, options)
|
58
|
+
add_customer_reference(post, options)
|
59
|
+
|
60
|
+
commit('captureWithoutAuth', post)
|
61
|
+
end
|
62
|
+
|
63
|
+
def refund(amount, authorization, options = {})
|
64
|
+
post = {}
|
65
|
+
add_invoice(post, amount, options)
|
66
|
+
add_reference(post, authorization, options)
|
67
|
+
add_customer_data(post, options)
|
68
|
+
add_soft_descriptors(post, options)
|
69
|
+
post['order.ECI'] = options[:eci] || 'SSL'
|
70
|
+
add_customer_reference(post, options)
|
71
|
+
|
72
|
+
commit('refund', post)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Credit requires the merchant account to be enabled for "Adhoc Refunds"
|
76
|
+
def credit(amount, payment_method, options = {})
|
77
|
+
post = {}
|
78
|
+
add_invoice(post, amount, options)
|
79
|
+
add_order_number(post, options)
|
80
|
+
add_payment_method(post, payment_method)
|
81
|
+
add_customer_data(post, options)
|
82
|
+
add_soft_descriptors(post, options)
|
83
|
+
add_customer_reference(post, options)
|
84
|
+
|
85
|
+
commit('refund', post)
|
86
|
+
end
|
87
|
+
|
88
|
+
def void(authorization, options = {})
|
89
|
+
post = {}
|
90
|
+
add_reference(post, authorization, options)
|
91
|
+
add_customer_data(post, options)
|
92
|
+
add_soft_descriptors(post, options)
|
93
|
+
add_customer_reference(post, options)
|
94
|
+
|
95
|
+
commit('reversal', post)
|
96
|
+
end
|
97
|
+
|
98
|
+
def store(payment_method, options = {})
|
99
|
+
post = {}
|
100
|
+
add_payment_method(post, payment_method)
|
101
|
+
add_card_reference(post, options)
|
102
|
+
|
103
|
+
commit('registerAccount', post)
|
104
|
+
end
|
105
|
+
|
106
|
+
def supports_scrubbing?
|
107
|
+
true
|
108
|
+
end
|
109
|
+
|
110
|
+
def scrub(transcript)
|
111
|
+
transcript.
|
112
|
+
gsub(%r((&?customer.password=)[^&]*), '\1[FILTERED]').
|
113
|
+
gsub(%r((&?card.PAN=)[^&]*), '\1[FILTERED]').
|
114
|
+
gsub(%r((&?card.CVN=)[^&]*), '\1[FILTERED]')
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
CURRENCY_CODES = Hash.new { |_h, k| raise ArgumentError.new("Unsupported currency: #{k}") }
|
120
|
+
CURRENCY_CODES['AUD'] = 'AUD'
|
121
|
+
CURRENCY_CODES['INR'] = 'INR'
|
122
|
+
|
123
|
+
def add_soft_descriptors(post, options)
|
124
|
+
post['customer.merchantName'] = options[:customer_merchant_name] if options[:customer_merchant_name]
|
125
|
+
post['customer.merchantStreetAddress'] = options[:customer_merchant_street_address] if options[:customer_merchant_street_address]
|
126
|
+
post['customer.merchantLocation'] = options[:customer_merchant_location] if options[:customer_merchant_location]
|
127
|
+
post['customer.merchantState'] = options[:customer_merchant_state] if options[:customer_merchant_state]
|
128
|
+
post['customer.merchantCountry'] = options[:customer_merchant_country] if options[:customer_merchant_country]
|
129
|
+
post['customer.merchantPostCode'] = options[:customer_merchant_post_code] if options[:customer_merchant_post_code]
|
130
|
+
post['customer.subMerchantId'] = options[:customer_sub_merchant_id] if options[:customer_sub_merchant_id]
|
131
|
+
end
|
132
|
+
|
133
|
+
def add_invoice(post, money, options)
|
134
|
+
post['order.amount'] = amount(money)
|
135
|
+
post['card.currency'] = CURRENCY_CODES[options[:currency] || currency(money)]
|
136
|
+
end
|
137
|
+
|
138
|
+
def add_payment_method(post, payment_method)
|
139
|
+
post['card.cardHolderName'] = payment_method.name
|
140
|
+
post['card.PAN'] = payment_method.number
|
141
|
+
post['card.expiryYear'] = format(payment_method.year, :two_digits)
|
142
|
+
post['card.expiryMonth'] = format(payment_method.month, :two_digits)
|
143
|
+
end
|
144
|
+
|
145
|
+
def add_stored_credential_data(post, payment_method, options)
|
146
|
+
post['order.ECI'] = options[:eci] || eci(options)
|
147
|
+
if (stored_credential = options[:stored_credential]) && %w(visa master).include?(payment_method.brand)
|
148
|
+
post['card.posEntryMode'] = stored_credential[:initial_transaction] ? 'MANUAL' : 'STORED_CREDENTIAL'
|
149
|
+
stored_credential_usage(post, payment_method, options) unless stored_credential[:initiator] && stored_credential[:initiator] == 'cardholder'
|
150
|
+
post['order.authTraceId'] = stored_credential[:network_transaction_id] if stored_credential[:network_transaction_id]
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def stored_credential_usage(post, payment_method, options)
|
155
|
+
return unless payment_method.brand == 'visa'
|
156
|
+
|
157
|
+
stored_credential = options[:stored_credential]
|
158
|
+
if stored_credential[:reason_type] == 'unscheduled'
|
159
|
+
if stored_credential[:initiator] == 'merchant'
|
160
|
+
post['card.storedCredentialUsage'] = 'UNSCHEDULED_MIT'
|
161
|
+
elsif stored_credential[:initiator] == 'customer'
|
162
|
+
post['card.storedCredentialUsage'] = 'UNSCHEDULED_CIT'
|
163
|
+
end
|
164
|
+
elsif stored_credential[:reason_type] == 'recurring'
|
165
|
+
post['card.storedCredentialUsage'] = 'RECURRING'
|
166
|
+
elsif stored_credential[:reason_type] == 'installment'
|
167
|
+
post['card.storedCredentialUsage'] = 'INSTALLMENT'
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def eci(options)
|
172
|
+
if options.dig(:stored_credential, :initial_transaction)
|
173
|
+
'SSL'
|
174
|
+
elsif options.dig(:stored_credential, :initiator) && options[:stored_credential][:initiator] == 'cardholder'
|
175
|
+
'MTO'
|
176
|
+
elsif options.dig(:stored_credential, :reason_type)
|
177
|
+
case options[:stored_credential][:reason_type]
|
178
|
+
when 'recurring'
|
179
|
+
'REC'
|
180
|
+
when 'installment'
|
181
|
+
'INS'
|
182
|
+
when 'unscheduled'
|
183
|
+
'MTO'
|
184
|
+
end
|
185
|
+
else
|
186
|
+
'SSL'
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def add_verification_value(post, payment_method)
|
191
|
+
post['card.CVN'] = payment_method.verification_value
|
192
|
+
end
|
193
|
+
|
194
|
+
def add_card_reference(post, options)
|
195
|
+
post['customer.customerReferenceNumber'] = options[:customer_reference_number] || options[:order_id]
|
196
|
+
end
|
197
|
+
|
198
|
+
def add_customer_reference(post, options)
|
199
|
+
post['customer.customerReferenceNumber'] = options[:customer_reference_number] if options[:customer_reference_number]
|
200
|
+
end
|
201
|
+
|
202
|
+
def add_reference(post, authorization, options)
|
203
|
+
post['customer.originalOrderNumber'] = authorization
|
204
|
+
add_order_number(post, options)
|
205
|
+
end
|
206
|
+
|
207
|
+
def add_order_number(post, options)
|
208
|
+
post['customer.orderNumber'] = options[:order_id] || SecureRandom.uuid
|
209
|
+
end
|
210
|
+
|
211
|
+
def add_customer_data(post, options)
|
212
|
+
post['order.ipAddress'] = options[:ip] || '127.0.0.1'
|
213
|
+
post['order.xid'] = options[:xid] if options[:xid]
|
214
|
+
post['order.cavv'] = options[:cavv] if options[:cavv]
|
215
|
+
end
|
216
|
+
|
217
|
+
def commit(action, post)
|
218
|
+
post['customer.username'] = @options[:username]
|
219
|
+
post['customer.password'] = @options[:password]
|
220
|
+
post['customer.merchant'] = @options[:merchant]
|
221
|
+
post['order.type'] = action
|
222
|
+
|
223
|
+
data = build_request(post)
|
224
|
+
raw = parse(ssl_post(url(action), data, headers))
|
225
|
+
|
226
|
+
succeeded = success_from(raw['response.responseCode'])
|
227
|
+
Response.new(
|
228
|
+
succeeded,
|
229
|
+
message_from(succeeded, raw),
|
230
|
+
raw,
|
231
|
+
authorization: raw['response.orderNumber'] || raw['response.customerReferenceNumber'],
|
232
|
+
cvv_result: cvv_result(succeeded, raw),
|
233
|
+
error_code: error_code_from(succeeded, raw),
|
234
|
+
test: test?
|
235
|
+
)
|
236
|
+
end
|
237
|
+
|
238
|
+
def cvv_result(succeeded, raw)
|
239
|
+
return unless succeeded
|
240
|
+
|
241
|
+
code = CVV_CODE_MAPPING[raw['response.cvnResponse']] || raw['response.cvnResponse']
|
242
|
+
CVVResult.new(code)
|
243
|
+
end
|
244
|
+
|
245
|
+
def headers
|
246
|
+
{
|
247
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
248
|
+
}
|
249
|
+
end
|
250
|
+
|
251
|
+
def build_request(post)
|
252
|
+
post.to_query + '&message.end'
|
253
|
+
end
|
254
|
+
|
255
|
+
def url(action)
|
256
|
+
(test? ? test_url : live_url)
|
257
|
+
end
|
258
|
+
|
259
|
+
def parse(body)
|
260
|
+
result = {}
|
261
|
+
body.to_s.each_line do |pair|
|
262
|
+
result[$1] = $2 if pair.strip =~ /\A([^=]+)=(.+)\Z/im
|
263
|
+
end
|
264
|
+
result
|
265
|
+
end
|
266
|
+
|
267
|
+
def parse_element(response, node)
|
268
|
+
if node.has_elements?
|
269
|
+
node.elements.each { |element| parse_element(response, element) }
|
270
|
+
else
|
271
|
+
response[node.name.underscore.to_sym] = node.text
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
SUCCESS_CODES = %w(00 08 10 11 16 QS QZ)
|
276
|
+
|
277
|
+
def success_from(response)
|
278
|
+
SUCCESS_CODES.include?(response)
|
279
|
+
end
|
280
|
+
|
281
|
+
def message_from(succeeded, response)
|
282
|
+
if succeeded
|
283
|
+
'Succeeded'
|
284
|
+
else
|
285
|
+
response['response.text'] || 'Unable to read error message'
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
STANDARD_ERROR_CODE_MAPPING = {
|
290
|
+
'14' => STANDARD_ERROR_CODE[:invalid_number],
|
291
|
+
'QQ' => STANDARD_ERROR_CODE[:invalid_cvc],
|
292
|
+
'33' => STANDARD_ERROR_CODE[:expired_card],
|
293
|
+
'NT' => STANDARD_ERROR_CODE[:incorrect_address],
|
294
|
+
'12' => STANDARD_ERROR_CODE[:card_declined],
|
295
|
+
'06' => STANDARD_ERROR_CODE[:processing_error],
|
296
|
+
'01' => STANDARD_ERROR_CODE[:call_issuer],
|
297
|
+
'04' => STANDARD_ERROR_CODE[:pickup_card]
|
298
|
+
}
|
299
|
+
|
300
|
+
def error_code_from(succeeded, response)
|
301
|
+
succeeded ? nil : STANDARD_ERROR_CODE_MAPPING[response['response.responseCode']]
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
@@ -0,0 +1,319 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class RapydGateway < Gateway
|
4
|
+
self.test_url = 'https://sandboxapi.rapyd.net/v1/'
|
5
|
+
self.live_url = 'https://api.rapyd.net/v1/'
|
6
|
+
|
7
|
+
self.supported_countries = %w(CA CL CO DO SV PE PT VI AU HK IN ID JP MY NZ PH SG KR TW TH VN AD AT BE BA BG HR CY CZ DK EE FI FR GE DE GI GR GL HU IS IE IL IT LV LI LT LU MK MT MD MC ME NL GB NO PL RO RU SM SK SI ZA ES SE CH TR VA)
|
8
|
+
self.default_currency = 'USD'
|
9
|
+
self.supported_cardtypes = %i[visa master american_express discover]
|
10
|
+
|
11
|
+
self.homepage_url = 'https://www.rapyd.net/'
|
12
|
+
self.display_name = 'Rapyd Gateway'
|
13
|
+
|
14
|
+
USA_PAYMENT_METHODS = %w[us_debit_discover_card us_debit_mastercard_card us_debit_visa_card us_ach_bank]
|
15
|
+
|
16
|
+
STANDARD_ERROR_CODE_MAPPING = {}
|
17
|
+
|
18
|
+
def initialize(options = {})
|
19
|
+
requires!(options, :secret_key, :access_key)
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
def purchase(money, payment, options = {})
|
24
|
+
post = {}
|
25
|
+
add_auth_purchase(post, money, payment, options)
|
26
|
+
post[:capture] = true unless payment.is_a?(Check)
|
27
|
+
|
28
|
+
commit(:post, 'payments', post)
|
29
|
+
end
|
30
|
+
|
31
|
+
def authorize(money, payment, options = {})
|
32
|
+
post = {}
|
33
|
+
add_auth_purchase(post, money, payment, options)
|
34
|
+
post[:capture] = false unless payment.is_a?(Check)
|
35
|
+
|
36
|
+
commit(:post, 'payments', post)
|
37
|
+
end
|
38
|
+
|
39
|
+
def capture(money, authorization, options = {})
|
40
|
+
post = {}
|
41
|
+
commit(:post, "payments/#{add_reference(authorization)}/capture", post)
|
42
|
+
end
|
43
|
+
|
44
|
+
def refund(money, authorization, options = {})
|
45
|
+
post = {}
|
46
|
+
post[:payment] = add_reference(authorization)
|
47
|
+
add_invoice(post, money, options)
|
48
|
+
add_metadata(post, options)
|
49
|
+
add_ewallet(post, options)
|
50
|
+
|
51
|
+
commit(:post, 'refunds', post)
|
52
|
+
end
|
53
|
+
|
54
|
+
def void(authorization, options = {})
|
55
|
+
post = {}
|
56
|
+
commit(:delete, "payments/#{add_reference(authorization)}", post)
|
57
|
+
end
|
58
|
+
|
59
|
+
def verify(credit_card, options = {})
|
60
|
+
authorize(0, credit_card, options)
|
61
|
+
end
|
62
|
+
|
63
|
+
def store(payment, options = {})
|
64
|
+
post = {}
|
65
|
+
add_payment(post, payment, options)
|
66
|
+
add_customer_object(post, payment, options)
|
67
|
+
add_metadata(post, options)
|
68
|
+
add_ewallet(post, options)
|
69
|
+
add_payment_fields(post, options)
|
70
|
+
add_payment_urls(post, options)
|
71
|
+
add_address(post, payment, options)
|
72
|
+
commit(:post, 'customers', post)
|
73
|
+
end
|
74
|
+
|
75
|
+
def unstore(customer)
|
76
|
+
commit(:delete, "customers/#{add_reference(customer)}", {})
|
77
|
+
end
|
78
|
+
|
79
|
+
def supports_scrubbing?
|
80
|
+
true
|
81
|
+
end
|
82
|
+
|
83
|
+
def scrub(transcript)
|
84
|
+
transcript.
|
85
|
+
gsub(%r((Access_key: )\w+), '\1[FILTERED]').
|
86
|
+
gsub(%r(("number\\?":\\?")\d+), '\1[FILTERED]').
|
87
|
+
gsub(%r(("account_number\\?":\\?")\d+), '\1[FILTERED]').
|
88
|
+
gsub(%r(("routing_number\\?":\\?")\d+), '\1[FILTERED]').
|
89
|
+
gsub(%r(("cvv\\?":\\?")\d+), '\1[FILTERED]')
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def add_reference(authorization)
|
95
|
+
return unless authorization
|
96
|
+
|
97
|
+
authorization.split('|')[0]
|
98
|
+
end
|
99
|
+
|
100
|
+
def add_auth_purchase(post, money, payment, options)
|
101
|
+
add_invoice(post, money, options)
|
102
|
+
add_payment(post, payment, options)
|
103
|
+
add_customer_object(post, payment, options)
|
104
|
+
add_3ds(post, payment, options)
|
105
|
+
add_address(post, payment, options)
|
106
|
+
add_metadata(post, options)
|
107
|
+
add_ewallet(post, options)
|
108
|
+
add_payment_fields(post, options)
|
109
|
+
add_payment_urls(post, options)
|
110
|
+
add_customer_id(post, options)
|
111
|
+
end
|
112
|
+
|
113
|
+
def add_address(post, creditcard, options)
|
114
|
+
return unless address = options[:billing_address]
|
115
|
+
|
116
|
+
post[:address] = {}
|
117
|
+
# name and line_1 are required at the gateway
|
118
|
+
post[:address][:name] = address[:name] if address[:name]
|
119
|
+
post[:address][:line_1] = address[:address1] if address[:address1]
|
120
|
+
post[:address][:line_2] = address[:address2] if address[:address2]
|
121
|
+
post[:address][:city] = address[:city] if address[:city]
|
122
|
+
post[:address][:state] = address[:state] if address[:state]
|
123
|
+
post[:address][:country] = address[:country] if address[:country]
|
124
|
+
post[:address][:zip] = address[:zip] if address[:zip]
|
125
|
+
post[:address][:phone_number] = address[:phone].gsub(/\D/, '') if address[:phone]
|
126
|
+
end
|
127
|
+
|
128
|
+
def add_invoice(post, money, options)
|
129
|
+
post[:amount] = money.zero? ? 0 : amount(money).to_f.to_s
|
130
|
+
post[:currency] = (options[:currency] || currency(money))
|
131
|
+
end
|
132
|
+
|
133
|
+
def add_payment(post, payment, options)
|
134
|
+
if payment.is_a?(CreditCard)
|
135
|
+
add_creditcard(post, payment, options)
|
136
|
+
elsif payment.is_a?(Check)
|
137
|
+
add_ach(post, payment, options)
|
138
|
+
else
|
139
|
+
add_token(post, payment, options)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def add_stored_credential(post, options)
|
144
|
+
return unless stored_credential = options[:stored_credential]
|
145
|
+
|
146
|
+
post[:payment_method][:fields][:network_reference_id] = stored_credential[:network_transaction_id] if stored_credential[:network_transaction_id]
|
147
|
+
post[:initiation_type] = stored_credential[:reason_type] if stored_credential[:reason_type]
|
148
|
+
end
|
149
|
+
|
150
|
+
def add_creditcard(post, payment, options)
|
151
|
+
post[:payment_method] = {}
|
152
|
+
post[:payment_method][:fields] = {}
|
153
|
+
pm_fields = post[:payment_method][:fields]
|
154
|
+
|
155
|
+
post[:payment_method][:type] = options[:pm_type]
|
156
|
+
pm_fields[:number] = payment.number
|
157
|
+
pm_fields[:expiration_month] = payment.month.to_s
|
158
|
+
pm_fields[:expiration_year] = payment.year.to_s
|
159
|
+
pm_fields[:name] = "#{payment.first_name} #{payment.last_name}"
|
160
|
+
pm_fields[:cvv] = payment.verification_value.to_s
|
161
|
+
|
162
|
+
add_stored_credential(post, options)
|
163
|
+
end
|
164
|
+
|
165
|
+
def add_ach(post, payment, options)
|
166
|
+
post[:payment_method] = {}
|
167
|
+
post[:payment_method][:fields] = {}
|
168
|
+
|
169
|
+
post[:payment_method][:type] = options[:pm_type]
|
170
|
+
post[:payment_method][:fields][:proof_of_authorization] = options[:proof_of_authorization]
|
171
|
+
post[:payment_method][:fields][:first_name] = payment.first_name if payment.first_name
|
172
|
+
post[:payment_method][:fields][:last_name] = payment.last_name if payment.last_name
|
173
|
+
post[:payment_method][:fields][:routing_number] = payment.routing_number
|
174
|
+
post[:payment_method][:fields][:account_number] = payment.account_number
|
175
|
+
post[:payment_method][:fields][:payment_purpose] = options[:payment_purpose] if options[:payment_purpose]
|
176
|
+
end
|
177
|
+
|
178
|
+
def add_token(post, payment, options)
|
179
|
+
return unless token = payment.split('|')[1]
|
180
|
+
|
181
|
+
post[:payment_method] = token
|
182
|
+
end
|
183
|
+
|
184
|
+
def add_3ds(post, payment, options)
|
185
|
+
return unless three_d_secure = options[:three_d_secure]
|
186
|
+
|
187
|
+
post[:payment_method_options] = {}
|
188
|
+
post[:payment_method_options]['3d_required'] = three_d_secure[:required]
|
189
|
+
post[:payment_method_options]['3d_version'] = three_d_secure[:version]
|
190
|
+
post[:payment_method_options][:cavv] = three_d_secure[:cavv]
|
191
|
+
post[:payment_method_options][:eci] = three_d_secure[:eci]
|
192
|
+
post[:payment_method_options][:xid] = three_d_secure[:xid]
|
193
|
+
post[:payment_method_options][:ds_trans_id] = three_d_secure[:ds_transaction_id]
|
194
|
+
end
|
195
|
+
|
196
|
+
def add_metadata(post, options)
|
197
|
+
post[:metadata] = options[:metadata] if options[:metadata]
|
198
|
+
end
|
199
|
+
|
200
|
+
def add_ewallet(post, options)
|
201
|
+
post[:ewallet_id] = options[:ewallet_id] if options[:ewallet_id]
|
202
|
+
end
|
203
|
+
|
204
|
+
def add_payment_fields(post, options)
|
205
|
+
post[:payment] = {}
|
206
|
+
|
207
|
+
post[:payment][:description] = options[:description] if options[:description]
|
208
|
+
post[:payment][:statement_descriptor] = options[:statement_descriptor] if options[:statement_descriptor]
|
209
|
+
end
|
210
|
+
|
211
|
+
def add_payment_urls(post, options)
|
212
|
+
post[:complete_payment_url] = options[:complete_payment_url] if options[:complete_payment_url]
|
213
|
+
post[:error_payment_url] = options[:error_payment_url] if options[:error_payment_url]
|
214
|
+
end
|
215
|
+
|
216
|
+
def add_customer_object(post, payment, options)
|
217
|
+
post[:name] = "#{payment.first_name} #{payment.last_name}" unless payment.is_a?(String)
|
218
|
+
phone = options.dig(:billing_address, :phone) .gsub(/\D/, '') unless options[:billing_address].nil?
|
219
|
+
post[:phone_number] = phone || options.dig(:customer, :phone_number)
|
220
|
+
post[:email] = options[:email] || options.dig(:customer, :email)
|
221
|
+
post[:addresses] = options.dig(:customer, :addresses) if USA_PAYMENT_METHODS.include?(options[:pm_type])
|
222
|
+
end
|
223
|
+
|
224
|
+
def add_customer_id(post, options)
|
225
|
+
post[:customer] = options[:customer_id] if options[:customer_id]
|
226
|
+
end
|
227
|
+
|
228
|
+
def parse(body)
|
229
|
+
return {} if body.empty? || body.nil?
|
230
|
+
|
231
|
+
JSON.parse(body)
|
232
|
+
end
|
233
|
+
|
234
|
+
def commit(method, action, parameters)
|
235
|
+
url = (test? ? test_url : live_url) + action.to_s
|
236
|
+
rel_path = "#{method}/v1/#{action}"
|
237
|
+
response = api_request(method, url, rel_path, parameters)
|
238
|
+
|
239
|
+
Response.new(
|
240
|
+
success_from(response),
|
241
|
+
message_from(response),
|
242
|
+
response,
|
243
|
+
authorization: authorization_from(response),
|
244
|
+
avs_result: avs_result(response),
|
245
|
+
cvv_result: cvv_result(response),
|
246
|
+
test: test?,
|
247
|
+
error_code: error_code_from(response)
|
248
|
+
)
|
249
|
+
end
|
250
|
+
|
251
|
+
def api_request(method, url, rel_path, params)
|
252
|
+
params == {} ? body = '' : body = params.to_json
|
253
|
+
parse(ssl_request(method, url, body, headers(rel_path, body)))
|
254
|
+
end
|
255
|
+
|
256
|
+
def headers(rel_path, payload)
|
257
|
+
salt = SecureRandom.base64(12)
|
258
|
+
timestamp = Time.new.to_i.to_s
|
259
|
+
{
|
260
|
+
'Content-Type' => 'application/json',
|
261
|
+
'access_key' => @options[:access_key],
|
262
|
+
'salt' => salt,
|
263
|
+
'timestamp' => timestamp,
|
264
|
+
'signature' => generate_hmac(rel_path, salt, timestamp, payload)
|
265
|
+
}
|
266
|
+
end
|
267
|
+
|
268
|
+
def generate_hmac(rel_path, salt, timestamp, payload)
|
269
|
+
signature = "#{rel_path}#{salt}#{timestamp}#{@options[:access_key]}#{@options[:secret_key]}#{payload}"
|
270
|
+
hash = Base64.urlsafe_encode64(OpenSSL::HMAC.hexdigest('sha256', @options[:secret_key], signature))
|
271
|
+
hash
|
272
|
+
end
|
273
|
+
|
274
|
+
def avs_result(response)
|
275
|
+
return nil unless (code = response.dig('data', 'payment_method_data', 'acs_check'))
|
276
|
+
|
277
|
+
AVSResult.new(code: code)
|
278
|
+
end
|
279
|
+
|
280
|
+
def cvv_result(response)
|
281
|
+
return nil unless (code = response.dig('data', 'payment_method_data', 'cvv_check'))
|
282
|
+
|
283
|
+
CVVResult.new(code)
|
284
|
+
end
|
285
|
+
|
286
|
+
def success_from(response)
|
287
|
+
response.dig('status', 'status') == 'SUCCESS' && response.dig('status', 'error') != 'ERR'
|
288
|
+
end
|
289
|
+
|
290
|
+
def message_from(response)
|
291
|
+
case response.dig('status', 'status')
|
292
|
+
when 'ERROR'
|
293
|
+
response.dig('status', 'message') == '' ? response.dig('status', 'error_code') : response.dig('status', 'message')
|
294
|
+
else
|
295
|
+
response.dig('status', 'status')
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
def authorization_from(response)
|
300
|
+
id = response.dig('data') ? response.dig('data', 'id') : response.dig('status', 'operation_id')
|
301
|
+
|
302
|
+
"#{id}|#{response.dig('data', 'default_payment_method')}"
|
303
|
+
end
|
304
|
+
|
305
|
+
def error_code_from(response)
|
306
|
+
response.dig('status', 'error_code') unless success_from(response)
|
307
|
+
end
|
308
|
+
|
309
|
+
def handle_response(response)
|
310
|
+
case response.code.to_i
|
311
|
+
when 200...300, 400, 401, 404
|
312
|
+
response.body
|
313
|
+
else
|
314
|
+
raise ResponseError.new(response)
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|