active_accountability_merchant 1.97.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +2948 -0
- data/CONTRIBUTORS +568 -0
- data/MIT-LICENSE +20 -0
- data/README.md +246 -0
- data/lib/active_merchant.rb +63 -0
- data/lib/active_merchant/billing.rb +15 -0
- data/lib/active_merchant/billing/apple_pay_payment_token.rb +22 -0
- data/lib/active_merchant/billing/avs_result.rb +96 -0
- data/lib/active_merchant/billing/base.rb +61 -0
- data/lib/active_merchant/billing/check.rb +80 -0
- data/lib/active_merchant/billing/compatibility.rb +117 -0
- data/lib/active_merchant/billing/credit_card.rb +406 -0
- data/lib/active_merchant/billing/credit_card_formatting.rb +23 -0
- data/lib/active_merchant/billing/credit_card_methods.rb +343 -0
- data/lib/active_merchant/billing/cvv_result.rb +38 -0
- data/lib/active_merchant/billing/gateway.rb +330 -0
- data/lib/active_merchant/billing/gateways.rb +14 -0
- data/lib/active_merchant/billing/gateways/adyen.rb +503 -0
- data/lib/active_merchant/billing/gateways/allied_wallet.rb +205 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +1055 -0
- data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +417 -0
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +980 -0
- data/lib/active_merchant/billing/gateways/axcessms.rb +181 -0
- data/lib/active_merchant/billing/gateways/balanced.rb +256 -0
- data/lib/active_merchant/billing/gateways/bambora_apac.rb +226 -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 +384 -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.rb +217 -0
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +473 -0
- data/lib/active_merchant/billing/gateways/beanstream_interac.rb +57 -0
- data/lib/active_merchant/billing/gateways/blue_pay.rb +522 -0
- data/lib/active_merchant/billing/gateways/blue_snap.rb +522 -0
- data/lib/active_merchant/billing/gateways/bogus.rb +186 -0
- data/lib/active_merchant/billing/gateways/borgun.rb +220 -0
- data/lib/active_merchant/billing/gateways/bpoint.rb +277 -0
- data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
- data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +22 -0
- data/lib/active_merchant/billing/gateways/braintree_blue.rb +740 -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 +316 -0
- data/lib/active_merchant/billing/gateways/card_save.rb +22 -0
- data/lib/active_merchant/billing/gateways/card_stream.rb +367 -0
- data/lib/active_merchant/billing/gateways/cardknox.rb +327 -0
- data/lib/active_merchant/billing/gateways/cardprocess.rb +254 -0
- data/lib/active_merchant/billing/gateways/cashnet.rb +219 -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 +327 -0
- data/lib/active_merchant/billing/gateways/checkout.rb +214 -0
- data/lib/active_merchant/billing/gateways/checkout_v2.rb +270 -0
- data/lib/active_merchant/billing/gateways/citrus_pay.rb +22 -0
- data/lib/active_merchant/billing/gateways/clearhaus.rb +220 -0
- data/lib/active_merchant/billing/gateways/commercegate.rb +142 -0
- data/lib/active_merchant/billing/gateways/conekta.rb +228 -0
- data/lib/active_merchant/billing/gateways/creditcall.rb +271 -0
- data/lib/active_merchant/billing/gateways/credorax.rb +382 -0
- data/lib/active_merchant/billing/gateways/ct_payment.rb +268 -0
- data/lib/active_merchant/billing/gateways/culqi.rb +277 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +828 -0
- data/lib/active_merchant/billing/gateways/d_local.rb +226 -0
- data/lib/active_merchant/billing/gateways/data_cash.rb +305 -0
- data/lib/active_merchant/billing/gateways/decidir.rb +233 -0
- data/lib/active_merchant/billing/gateways/dibs.rb +199 -0
- data/lib/active_merchant/billing/gateways/digitzs.rb +292 -0
- data/lib/active_merchant/billing/gateways/ebanx.rb +296 -0
- data/lib/active_merchant/billing/gateways/efsnet.rb +215 -0
- data/lib/active_merchant/billing/gateways/elavon.rb +320 -0
- data/lib/active_merchant/billing/gateways/element.rb +356 -0
- data/lib/active_merchant/billing/gateways/epay.rb +285 -0
- data/lib/active_merchant/billing/gateways/evo_ca.rb +308 -0
- data/lib/active_merchant/billing/gateways/eway.rb +226 -0
- data/lib/active_merchant/billing/gateways/eway_managed.rb +290 -0
- data/lib/active_merchant/billing/gateways/eway_rapid.rb +563 -0
- data/lib/active_merchant/billing/gateways/exact.rb +224 -0
- data/lib/active_merchant/billing/gateways/ezic.rb +195 -0
- data/lib/active_merchant/billing/gateways/fat_zebra.rb +218 -0
- data/lib/active_merchant/billing/gateways/federated_canada.rb +159 -0
- data/lib/active_merchant/billing/gateways/finansbank.rb +22 -0
- data/lib/active_merchant/billing/gateways/first_giving.rb +142 -0
- data/lib/active_merchant/billing/gateways/first_pay.rb +182 -0
- data/lib/active_merchant/billing/gateways/firstdata_e4.rb +451 -0
- data/lib/active_merchant/billing/gateways/firstdata_e4_v27.rb +485 -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 +270 -0
- data/lib/active_merchant/billing/gateways/garanti.rb +259 -0
- data/lib/active_merchant/billing/gateways/global_collect.rb +336 -0
- data/lib/active_merchant/billing/gateways/global_transport.rb +194 -0
- data/lib/active_merchant/billing/gateways/hdfc.rb +206 -0
- data/lib/active_merchant/billing/gateways/hps.rb +350 -0
- data/lib/active_merchant/billing/gateways/iats_payments.rb +290 -0
- data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +15 -0
- data/lib/active_merchant/billing/gateways/inspire.rb +218 -0
- data/lib/active_merchant/billing/gateways/instapay.rb +162 -0
- data/lib/active_merchant/billing/gateways/ipp.rb +176 -0
- data/lib/active_merchant/billing/gateways/iridium.rb +468 -0
- data/lib/active_merchant/billing/gateways/itransact.rb +447 -0
- data/lib/active_merchant/billing/gateways/iveri.rb +251 -0
- data/lib/active_merchant/billing/gateways/jetpay.rb +402 -0
- data/lib/active_merchant/billing/gateways/jetpay_v2.rb +437 -0
- data/lib/active_merchant/billing/gateways/komoju.rb +115 -0
- data/lib/active_merchant/billing/gateways/kushki.rb +219 -0
- data/lib/active_merchant/billing/gateways/latitude19.rb +411 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +449 -0
- data/lib/active_merchant/billing/gateways/litle.rb +507 -0
- data/lib/active_merchant/billing/gateways/mastercard.rb +267 -0
- data/lib/active_merchant/billing/gateways/maxipago.rb +220 -0
- data/lib/active_merchant/billing/gateways/mercado_pago.rb +277 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +194 -0
- data/lib/active_merchant/billing/gateways/merchant_one.rb +113 -0
- data/lib/active_merchant/billing/gateways/merchant_partners.rb +245 -0
- data/lib/active_merchant/billing/gateways/merchant_ware.rb +319 -0
- data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +286 -0
- data/lib/active_merchant/billing/gateways/merchant_warrior.rb +210 -0
- data/lib/active_merchant/billing/gateways/mercury.rb +356 -0
- data/lib/active_merchant/billing/gateways/metrics_global.rb +303 -0
- data/lib/active_merchant/billing/gateways/micropayment.rb +183 -0
- data/lib/active_merchant/billing/gateways/migs.rb +332 -0
- data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
- data/lib/active_merchant/billing/gateways/modern_payments.rb +37 -0
- data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +217 -0
- data/lib/active_merchant/billing/gateways/monei.rb +338 -0
- data/lib/active_merchant/billing/gateways/moneris.rb +377 -0
- data/lib/active_merchant/billing/gateways/moneris_us.rb +352 -0
- data/lib/active_merchant/billing/gateways/money_movers.rb +151 -0
- data/lib/active_merchant/billing/gateways/mundipagg.rb +293 -0
- data/lib/active_merchant/billing/gateways/nab_transact.rb +301 -0
- data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +165 -0
- data/lib/active_merchant/billing/gateways/net_registry.rb +199 -0
- data/lib/active_merchant/billing/gateways/netaxept.rb +180 -0
- data/lib/active_merchant/billing/gateways/netbanx.rb +294 -0
- data/lib/active_merchant/billing/gateways/netbilling.rb +232 -0
- data/lib/active_merchant/billing/gateways/netpay.rb +222 -0
- data/lib/active_merchant/billing/gateways/network_merchants.rb +241 -0
- data/lib/active_merchant/billing/gateways/nmi.rb +324 -0
- data/lib/active_merchant/billing/gateways/ogone.rb +478 -0
- data/lib/active_merchant/billing/gateways/omise.rb +324 -0
- data/lib/active_merchant/billing/gateways/openpay.rb +228 -0
- data/lib/active_merchant/billing/gateways/opp.rb +388 -0
- data/lib/active_merchant/billing/gateways/optimal_payment.rb +332 -0
- data/lib/active_merchant/billing/gateways/orbital.rb +1006 -0
- data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +47 -0
- data/lib/active_merchant/billing/gateways/pac_net_raven.rb +206 -0
- data/lib/active_merchant/billing/gateways/pagarme.rb +246 -0
- data/lib/active_merchant/billing/gateways/pago_facil.rb +122 -0
- data/lib/active_merchant/billing/gateways/pay_conex.rb +245 -0
- data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +280 -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 +188 -0
- data/lib/active_merchant/billing/gateways/pay_secure.rb +111 -0
- data/lib/active_merchant/billing/gateways/paybox_direct.rb +200 -0
- data/lib/active_merchant/billing/gateways/payeezy.rb +410 -0
- data/lib/active_merchant/billing/gateways/payex.rb +410 -0
- data/lib/active_merchant/billing/gateways/payflow.rb +383 -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 +43 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -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 +369 -0
- data/lib/active_merchant/billing/gateways/paymentez.rb +300 -0
- data/lib/active_merchant/billing/gateways/paymill.rb +371 -0
- data/lib/active_merchant/billing/gateways/paypal.rb +128 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +717 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +65 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +262 -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 +269 -0
- data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
- data/lib/active_merchant/billing/gateways/payscout.rb +160 -0
- data/lib/active_merchant/billing/gateways/paystation.rb +207 -0
- data/lib/active_merchant/billing/gateways/payu_in.rb +248 -0
- data/lib/active_merchant/billing/gateways/payu_latam.rb +449 -0
- data/lib/active_merchant/billing/gateways/payway.rb +207 -0
- data/lib/active_merchant/billing/gateways/pin.rb +234 -0
- data/lib/active_merchant/billing/gateways/plugnpay.rb +284 -0
- data/lib/active_merchant/billing/gateways/pro_pay.rb +326 -0
- data/lib/active_merchant/billing/gateways/psigate.rb +227 -0
- data/lib/active_merchant/billing/gateways/psl_card.rb +296 -0
- data/lib/active_merchant/billing/gateways/qbms.rb +303 -0
- data/lib/active_merchant/billing/gateways/quantum.rb +276 -0
- data/lib/active_merchant/billing/gateways/quickbooks.rb +290 -0
- data/lib/active_merchant/billing/gateways/quickpay.rb +25 -0
- data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +184 -0
- data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +301 -0
- data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +226 -0
- data/lib/active_merchant/billing/gateways/qvalent.rb +289 -0
- data/lib/active_merchant/billing/gateways/realex.rb +374 -0
- data/lib/active_merchant/billing/gateways/redsys.rb +534 -0
- data/lib/active_merchant/billing/gateways/s5.rb +246 -0
- data/lib/active_merchant/billing/gateways/safe_charge.rb +262 -0
- data/lib/active_merchant/billing/gateways/sage.rb +448 -0
- data/lib/active_merchant/billing/gateways/sage_pay.rb +434 -0
- data/lib/active_merchant/billing/gateways/sallie_mae.rb +142 -0
- data/lib/active_merchant/billing/gateways/secure_net.rb +267 -0
- data/lib/active_merchant/billing/gateways/secure_pay.rb +200 -0
- data/lib/active_merchant/billing/gateways/secure_pay_au.rb +292 -0
- data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +104 -0
- data/lib/active_merchant/billing/gateways/securion_pay.rb +264 -0
- data/lib/active_merchant/billing/gateways/skip_jack.rb +450 -0
- data/lib/active_merchant/billing/gateways/smart_ps.rb +280 -0
- data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
- data/lib/active_merchant/billing/gateways/spreedly_core.rb +306 -0
- data/lib/active_merchant/billing/gateways/stripe.rb +790 -0
- data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +267 -0
- data/lib/active_merchant/billing/gateways/swipe_checkout.rb +152 -0
- data/lib/active_merchant/billing/gateways/telr.rb +274 -0
- data/lib/active_merchant/billing/gateways/tns.rb +22 -0
- data/lib/active_merchant/billing/gateways/trans_first.rb +239 -0
- data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +608 -0
- data/lib/active_merchant/billing/gateways/transact_pro.rb +224 -0
- data/lib/active_merchant/billing/gateways/transax.rb +22 -0
- data/lib/active_merchant/billing/gateways/transnational.rb +9 -0
- data/lib/active_merchant/billing/gateways/trexle.rb +218 -0
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +490 -0
- data/lib/active_merchant/billing/gateways/usa_epay.rb +25 -0
- data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1620 -0
- data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +355 -0
- data/lib/active_merchant/billing/gateways/vanco.rb +294 -0
- data/lib/active_merchant/billing/gateways/verifi.rb +225 -0
- data/lib/active_merchant/billing/gateways/viaklix.rb +176 -0
- data/lib/active_merchant/billing/gateways/visanet_peru.rb +245 -0
- data/lib/active_merchant/billing/gateways/webpay.rb +97 -0
- data/lib/active_merchant/billing/gateways/wepay.rb +237 -0
- data/lib/active_merchant/billing/gateways/wirecard.rb +432 -0
- data/lib/active_merchant/billing/gateways/world_net.rb +344 -0
- data/lib/active_merchant/billing/gateways/worldpay.rb +634 -0
- data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +215 -0
- data/lib/active_merchant/billing/gateways/worldpay_us.rb +221 -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 +92 -0
- data/lib/active_merchant/connection.rb +195 -0
- data/lib/active_merchant/country.rb +336 -0
- data/lib/active_merchant/empty.rb +20 -0
- data/lib/active_merchant/errors.rb +35 -0
- data/lib/active_merchant/net_http_ssl_connection.rb +10 -0
- data/lib/active_merchant/network_connection_retries.rb +80 -0
- data/lib/active_merchant/post_data.rb +25 -0
- data/lib/active_merchant/posts_data.rb +92 -0
- data/lib/active_merchant/version.rb +3 -0
- data/lib/activemerchant.rb +1 -0
- data/lib/certs/cacert.pem +3988 -0
- data/lib/support/gateway_support.rb +69 -0
- data/lib/support/outbound_hosts.rb +28 -0
- data/lib/support/ssl_verify.rb +92 -0
- data/lib/support/ssl_version.rb +87 -0
- metadata +435 -0
@@ -0,0 +1,300 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'digest'
|
3
|
+
|
4
|
+
module ActiveMerchant #:nodoc:
|
5
|
+
module Billing #:nodoc:
|
6
|
+
class PaymentezGateway < Gateway #:nodoc:
|
7
|
+
self.test_url = 'https://ccapi-stg.paymentez.com/v2/'
|
8
|
+
self.live_url = 'https://ccapi.paymentez.com/v2/'
|
9
|
+
|
10
|
+
self.supported_countries = %w[MX EC VE CO BR CL]
|
11
|
+
self.default_currency = 'USD'
|
12
|
+
self.supported_cardtypes = %i[visa master american_express diners_club elo]
|
13
|
+
|
14
|
+
self.homepage_url = 'https://secure.paymentez.com/'
|
15
|
+
self.display_name = 'Paymentez'
|
16
|
+
|
17
|
+
STANDARD_ERROR_CODE_MAPPING = {
|
18
|
+
1 => :processing_error,
|
19
|
+
6 => :card_declined,
|
20
|
+
9 => :card_declined,
|
21
|
+
10 => :processing_error,
|
22
|
+
11 => :card_declined,
|
23
|
+
12 => :config_error,
|
24
|
+
13 => :config_error,
|
25
|
+
19 => :invalid_cvc,
|
26
|
+
20 => :config_error,
|
27
|
+
21 => :card_declined,
|
28
|
+
22 => :card_declined,
|
29
|
+
23 => :card_declined,
|
30
|
+
24 => :card_declined,
|
31
|
+
25 => :card_declined,
|
32
|
+
26 => :card_declined,
|
33
|
+
27 => :card_declined,
|
34
|
+
28 => :card_declined
|
35
|
+
}.freeze
|
36
|
+
|
37
|
+
CARD_MAPPING = {
|
38
|
+
'visa' => 'vi',
|
39
|
+
'master' => 'mc',
|
40
|
+
'american_express' => 'ax',
|
41
|
+
'diners_club' => 'di',
|
42
|
+
'elo' => 'el'
|
43
|
+
}.freeze
|
44
|
+
|
45
|
+
def initialize(options = {})
|
46
|
+
requires!(options, :application_code, :app_key)
|
47
|
+
super
|
48
|
+
end
|
49
|
+
|
50
|
+
def purchase(money, payment, options = {})
|
51
|
+
post = {}
|
52
|
+
|
53
|
+
add_invoice(post, money, options)
|
54
|
+
add_payment(post, payment)
|
55
|
+
add_customer_data(post, options)
|
56
|
+
add_extra_params(post, options)
|
57
|
+
action = payment.is_a?(String) ? 'debit' : 'debit_cc'
|
58
|
+
|
59
|
+
commit_transaction(action, post)
|
60
|
+
end
|
61
|
+
|
62
|
+
def authorize(money, payment, options = {})
|
63
|
+
post = {}
|
64
|
+
|
65
|
+
add_invoice(post, money, options)
|
66
|
+
add_payment(post, payment)
|
67
|
+
add_customer_data(post, options)
|
68
|
+
add_extra_params(post, options)
|
69
|
+
|
70
|
+
commit_transaction('authorize', post)
|
71
|
+
end
|
72
|
+
|
73
|
+
def capture(money, authorization, _options = {})
|
74
|
+
post = {
|
75
|
+
transaction: { id: authorization }
|
76
|
+
}
|
77
|
+
post[:order] = {amount: amount(money).to_f} if money
|
78
|
+
|
79
|
+
commit_transaction('capture', post)
|
80
|
+
end
|
81
|
+
|
82
|
+
def refund(money, authorization, options = {})
|
83
|
+
post = {transaction: {id: authorization}}
|
84
|
+
post[:order] = {amount: amount(money).to_f} if money
|
85
|
+
|
86
|
+
commit_transaction('refund', post)
|
87
|
+
end
|
88
|
+
|
89
|
+
def void(authorization, _options = {})
|
90
|
+
post = { transaction: { id: authorization } }
|
91
|
+
commit_transaction('refund', post)
|
92
|
+
end
|
93
|
+
|
94
|
+
def verify(credit_card, options = {})
|
95
|
+
MultiResponse.run do |r|
|
96
|
+
r.process { authorize(100, credit_card, options) }
|
97
|
+
r.process { void(r.authorization, options) }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def store(credit_card, options = {})
|
102
|
+
post = {}
|
103
|
+
|
104
|
+
add_customer_data(post, options)
|
105
|
+
add_payment(post, credit_card)
|
106
|
+
|
107
|
+
response = commit_card('add', post)
|
108
|
+
if !response.success? && !(token = extract_previous_card_token(response)).nil?
|
109
|
+
unstore(token, options)
|
110
|
+
response = commit_card('add', post)
|
111
|
+
end
|
112
|
+
response
|
113
|
+
end
|
114
|
+
|
115
|
+
def unstore(identification, options = {})
|
116
|
+
post = { card: { token: identification }, user: { id: options[:user_id] }}
|
117
|
+
commit_card('delete', post)
|
118
|
+
end
|
119
|
+
|
120
|
+
def supports_scrubbing?
|
121
|
+
true
|
122
|
+
end
|
123
|
+
|
124
|
+
def scrub(transcript)
|
125
|
+
transcript.
|
126
|
+
gsub(%r{(\\?"number\\?":)(\\?"[^"]+\\?")}, '\1[FILTERED]').
|
127
|
+
gsub(%r{(\\?"cvc\\?":)(\\?"[^"]+\\?")}, '\1[FILTERED]').
|
128
|
+
gsub(%r{(Auth-Token: )([A-Za-z0-9=]+)}, '\1[FILTERED]')
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def add_customer_data(post, options)
|
134
|
+
requires!(options, :user_id, :email)
|
135
|
+
post[:user] ||= {}
|
136
|
+
post[:user][:id] = options[:user_id]
|
137
|
+
post[:user][:email] = options[:email]
|
138
|
+
post[:user][:ip_address] = options[:ip] if options[:ip]
|
139
|
+
post[:user][:fiscal_number] = options[:fiscal_number] if options[:fiscal_number]
|
140
|
+
if phone = options[:phone] || options.dig(:billing_address, :phone)
|
141
|
+
post[:user][:phone] = phone
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def add_invoice(post, money, options)
|
146
|
+
post[:session_id] = options[:session_id] if options[:session_id]
|
147
|
+
|
148
|
+
post[:order] ||= {}
|
149
|
+
post[:order][:amount] = amount(money).to_f
|
150
|
+
post[:order][:vat] = options[:vat] if options[:vat]
|
151
|
+
post[:order][:dev_reference] = options[:dev_reference] if options[:dev_reference]
|
152
|
+
post[:order][:description] = options[:description] if options[:description]
|
153
|
+
post[:order][:discount] = options[:discount] if options[:discount]
|
154
|
+
post[:order][:installments] = options[:installments] if options[:installments]
|
155
|
+
post[:order][:installments_type] = options[:installments_type] if options[:installments_type]
|
156
|
+
post[:order][:taxable_amount] = options[:taxable_amount] if options[:taxable_amount]
|
157
|
+
post[:order][:tax_percentage] = options[:tax_percentage] if options[:tax_percentage]
|
158
|
+
end
|
159
|
+
|
160
|
+
def add_payment(post, payment)
|
161
|
+
post[:card] ||= {}
|
162
|
+
if payment.is_a?(String)
|
163
|
+
post[:card][:token] = payment
|
164
|
+
else
|
165
|
+
post[:card][:number] = payment.number
|
166
|
+
post[:card][:holder_name] = payment.name
|
167
|
+
post[:card][:expiry_month] = payment.month
|
168
|
+
post[:card][:expiry_year] = payment.year
|
169
|
+
post[:card][:cvc] = payment.verification_value
|
170
|
+
post[:card][:type] = CARD_MAPPING[payment.brand]
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def add_extra_params(post, options)
|
175
|
+
extra_params = {}
|
176
|
+
extra_params.merge!(options[:extra_params]) if options[:extra_params]
|
177
|
+
|
178
|
+
post['extra_params'] = extra_params unless extra_params.empty?
|
179
|
+
end
|
180
|
+
|
181
|
+
def parse(body)
|
182
|
+
JSON.parse(body)
|
183
|
+
end
|
184
|
+
|
185
|
+
def commit_raw(object, action, parameters)
|
186
|
+
url = "#{(test? ? test_url : live_url)}#{object}/#{action}"
|
187
|
+
|
188
|
+
begin
|
189
|
+
raw_response = ssl_post(url, post_data(parameters), headers)
|
190
|
+
rescue ResponseError => e
|
191
|
+
raw_response = e.response.body
|
192
|
+
end
|
193
|
+
|
194
|
+
begin
|
195
|
+
parse(raw_response)
|
196
|
+
rescue JSON::ParserError
|
197
|
+
{'status' => 'Internal server error'}
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def commit_transaction(action, parameters)
|
202
|
+
response = commit_raw('transaction', action, parameters)
|
203
|
+
Response.new(
|
204
|
+
success_from(response),
|
205
|
+
message_from(response),
|
206
|
+
response,
|
207
|
+
authorization: authorization_from(response),
|
208
|
+
test: test?,
|
209
|
+
error_code: error_code_from(response)
|
210
|
+
)
|
211
|
+
end
|
212
|
+
|
213
|
+
def commit_card(action, parameters)
|
214
|
+
response = commit_raw('card', action, parameters)
|
215
|
+
Response.new(
|
216
|
+
card_success_from(response),
|
217
|
+
card_message_from(response),
|
218
|
+
response,
|
219
|
+
authorization: card_authorization_from(response),
|
220
|
+
test: test?,
|
221
|
+
error_code: card_error_code_from(response)
|
222
|
+
)
|
223
|
+
end
|
224
|
+
|
225
|
+
def headers
|
226
|
+
{
|
227
|
+
'Auth-Token' => authentication_code,
|
228
|
+
'Content-Type' => 'application/json'
|
229
|
+
}
|
230
|
+
end
|
231
|
+
|
232
|
+
def success_from(response)
|
233
|
+
!response.include?('error') && (response['status'] || response['transaction']['status']) == 'success'
|
234
|
+
end
|
235
|
+
|
236
|
+
def card_success_from(response)
|
237
|
+
return false if response.include?('error')
|
238
|
+
return true if response['message'] == 'card deleted'
|
239
|
+
response['card']['status'] == 'valid'
|
240
|
+
end
|
241
|
+
|
242
|
+
def message_from(response)
|
243
|
+
if !success_from(response) && response['error']
|
244
|
+
response['error'] && response['error']['type']
|
245
|
+
else
|
246
|
+
response['transaction'] && response['transaction']['message']
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def card_message_from(response)
|
251
|
+
if !response.include?('error')
|
252
|
+
response['message'] || response['card']['message']
|
253
|
+
else
|
254
|
+
response['error']['type']
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
def authorization_from(response)
|
259
|
+
response['transaction'] && response['transaction']['id']
|
260
|
+
end
|
261
|
+
|
262
|
+
def card_authorization_from(response)
|
263
|
+
response['card'] && response['card']['token']
|
264
|
+
end
|
265
|
+
|
266
|
+
def extract_previous_card_token(response)
|
267
|
+
match = /Card already added: (\d+)/.match(response.message)
|
268
|
+
match && match[1]
|
269
|
+
end
|
270
|
+
|
271
|
+
def post_data(parameters = {})
|
272
|
+
JSON.dump(parameters)
|
273
|
+
end
|
274
|
+
|
275
|
+
def error_code_from(response)
|
276
|
+
return if success_from(response)
|
277
|
+
if response['transaction']
|
278
|
+
detail = response['transaction']['status_detail']
|
279
|
+
if STANDARD_ERROR_CODE_MAPPING.include?(detail)
|
280
|
+
return STANDARD_ERROR_CODE[STANDARD_ERROR_CODE_MAPPING[detail]]
|
281
|
+
end
|
282
|
+
elsif response['error']
|
283
|
+
return STANDARD_ERROR_CODE[:config_error]
|
284
|
+
end
|
285
|
+
STANDARD_ERROR_CODE[:processing_error]
|
286
|
+
end
|
287
|
+
|
288
|
+
def card_error_code_from(response)
|
289
|
+
STANDARD_ERROR_CODE[:processing_error] unless card_success_from(response)
|
290
|
+
end
|
291
|
+
|
292
|
+
def authentication_code
|
293
|
+
timestamp = Time.new.to_i
|
294
|
+
unique_token = Digest::SHA256.hexdigest("#{@options[:app_key]}#{timestamp}")
|
295
|
+
authentication_string = "#{@options[:application_code]};#{timestamp};#{unique_token}"
|
296
|
+
Base64.encode64(authentication_string).delete("\n")
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
@@ -0,0 +1,371 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class PaymillGateway < Gateway
|
4
|
+
self.supported_countries = %w(AD AT BE BG CH CY CZ DE DK EE ES FI FO FR GB
|
5
|
+
GI GR HR HU IE IL IM IS IT LI LT LU LV MC MT
|
6
|
+
NL NO PL PT RO SE SI SK TR VA)
|
7
|
+
|
8
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :discover, :union_pay, :jcb]
|
9
|
+
self.homepage_url = 'https://paymill.com'
|
10
|
+
self.display_name = 'PAYMILL'
|
11
|
+
self.money_format = :cents
|
12
|
+
self.default_currency = 'EUR'
|
13
|
+
self.live_url = 'https://api.paymill.com/v2/'
|
14
|
+
|
15
|
+
def initialize(options = {})
|
16
|
+
requires!(options, :public_key, :private_key)
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def purchase(money, payment_method, options={})
|
21
|
+
action_with_token(:purchase, money, payment_method, options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def authorize(money, payment_method, options = {})
|
25
|
+
action_with_token(:authorize, money, payment_method, options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def capture(money, authorization, options = {})
|
29
|
+
post = {}
|
30
|
+
|
31
|
+
add_amount(post, money, options)
|
32
|
+
post[:preauthorization] = preauth(authorization)
|
33
|
+
post[:description] = options[:order_id]
|
34
|
+
post[:source] = 'active_merchant'
|
35
|
+
commit(:post, 'transactions', post)
|
36
|
+
end
|
37
|
+
|
38
|
+
def refund(money, authorization, options={})
|
39
|
+
post = {}
|
40
|
+
|
41
|
+
post[:amount] = amount(money)
|
42
|
+
post[:description] = options[:order_id]
|
43
|
+
commit(:post, "refunds/#{transaction_id(authorization)}", post)
|
44
|
+
end
|
45
|
+
|
46
|
+
def void(authorization, options={})
|
47
|
+
commit(:delete, "preauthorizations/#{preauth(authorization)}")
|
48
|
+
end
|
49
|
+
|
50
|
+
def store(credit_card, options={})
|
51
|
+
# The store request requires a currency and amount of at least $1 USD.
|
52
|
+
# This is used for an authorization that is handled internally by Paymill.
|
53
|
+
options[:currency] = 'USD'
|
54
|
+
options[:money] = 100
|
55
|
+
|
56
|
+
save_card(credit_card, options)
|
57
|
+
end
|
58
|
+
|
59
|
+
def supports_scrubbing
|
60
|
+
true
|
61
|
+
end
|
62
|
+
|
63
|
+
def scrub(transcript)
|
64
|
+
transcript.
|
65
|
+
gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
|
66
|
+
gsub(/(account.number=)(\d*)/, '\1[FILTERED]').
|
67
|
+
gsub(/(account.verification=)(\d*)/, '\1[FILTERED]')
|
68
|
+
end
|
69
|
+
|
70
|
+
def verify_credentials
|
71
|
+
begin
|
72
|
+
ssl_get(live_url + 'transactions/nonexistent', headers)
|
73
|
+
rescue ResponseError => e
|
74
|
+
return false if e.response.code.to_i == 401
|
75
|
+
end
|
76
|
+
|
77
|
+
true
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def add_credit_card(post, credit_card, options)
|
83
|
+
post['account.holder'] = (credit_card.try(:name) || '')
|
84
|
+
post['account.number'] = credit_card.number
|
85
|
+
post['account.expiry.month'] = sprintf('%.2i', credit_card.month)
|
86
|
+
post['account.expiry.year'] = sprintf('%.4i', credit_card.year)
|
87
|
+
post['account.verification'] = credit_card.verification_value
|
88
|
+
post['account.email'] = (options[:email] || nil)
|
89
|
+
post['presentation.amount3D'] = (options[:money] || nil)
|
90
|
+
post['presentation.currency3D'] = (options[:currency] || currency(options[:money]))
|
91
|
+
end
|
92
|
+
|
93
|
+
def headers
|
94
|
+
{ 'Authorization' => ('Basic ' + Base64.strict_encode64("#{@options[:private_key]}:X").chomp) }
|
95
|
+
end
|
96
|
+
|
97
|
+
def commit(method, action, parameters=nil)
|
98
|
+
begin
|
99
|
+
raw_response = ssl_request(method, live_url + action, post_data(parameters), headers)
|
100
|
+
rescue ResponseError => e
|
101
|
+
begin
|
102
|
+
parsed = JSON.parse(e.response.body)
|
103
|
+
rescue JSON::ParserError
|
104
|
+
return Response.new(false, "Unable to parse error response: '#{e.response.body}'")
|
105
|
+
end
|
106
|
+
return Response.new(false, response_message(parsed), parsed, {})
|
107
|
+
end
|
108
|
+
|
109
|
+
response_from(raw_response)
|
110
|
+
end
|
111
|
+
|
112
|
+
def response_from(raw_response)
|
113
|
+
parsed = JSON.parse(raw_response)
|
114
|
+
options = {
|
115
|
+
:authorization => authorization_from(parsed),
|
116
|
+
:test => (parsed['mode'] == 'test'),
|
117
|
+
}
|
118
|
+
|
119
|
+
succeeded = (parsed['data'] == []) || (parsed['data']['response_code'].to_i == 20000)
|
120
|
+
Response.new(succeeded, response_message(parsed), parsed, options)
|
121
|
+
end
|
122
|
+
|
123
|
+
def authorization_from(parsed_response)
|
124
|
+
parsed_data = parsed_response['data']
|
125
|
+
return '' unless parsed_data.kind_of?(Hash)
|
126
|
+
|
127
|
+
[
|
128
|
+
parsed_data['id'],
|
129
|
+
parsed_data['preauthorization'].try(:[], 'id')
|
130
|
+
].join(';')
|
131
|
+
end
|
132
|
+
|
133
|
+
def action_with_token(action, money, payment_method, options)
|
134
|
+
options[:money] = money
|
135
|
+
case payment_method
|
136
|
+
when String
|
137
|
+
self.send("#{action}_with_token", money, payment_method, options)
|
138
|
+
else
|
139
|
+
MultiResponse.run do |r|
|
140
|
+
r.process { save_card(payment_method, options) }
|
141
|
+
r.process { self.send("#{action}_with_token", money, r.authorization, options) }
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def purchase_with_token(money, card_token, options)
|
147
|
+
post = {}
|
148
|
+
|
149
|
+
add_amount(post, money, options)
|
150
|
+
post[:token] = card_token
|
151
|
+
post[:description] = options[:order_id]
|
152
|
+
post[:source] = 'active_merchant'
|
153
|
+
commit(:post, 'transactions', post)
|
154
|
+
end
|
155
|
+
|
156
|
+
def authorize_with_token(money, card_token, options)
|
157
|
+
post = {}
|
158
|
+
|
159
|
+
add_amount(post, money, options)
|
160
|
+
post[:token] = card_token
|
161
|
+
post[:description] = options[:order_id]
|
162
|
+
post[:source] = 'active_merchant'
|
163
|
+
commit(:post, 'preauthorizations', post)
|
164
|
+
end
|
165
|
+
|
166
|
+
def save_card(credit_card, options)
|
167
|
+
post = {}
|
168
|
+
|
169
|
+
add_credit_card(post, credit_card, options)
|
170
|
+
post['channel.id'] = @options[:public_key]
|
171
|
+
post['jsonPFunction'] = 'jsonPFunction'
|
172
|
+
post['transaction.mode'] = (test? ? 'CONNECTOR_TEST' : 'LIVE')
|
173
|
+
|
174
|
+
begin
|
175
|
+
raw_response = ssl_request(:get, "#{save_card_url}?#{post_data(post)}", nil, {})
|
176
|
+
rescue ResponseError => e
|
177
|
+
return Response.new(false, e.response.body)
|
178
|
+
end
|
179
|
+
|
180
|
+
response_for_save_from(raw_response)
|
181
|
+
end
|
182
|
+
|
183
|
+
def response_for_save_from(raw_response)
|
184
|
+
options = { :test => test? }
|
185
|
+
|
186
|
+
parser = ResponseParser.new(raw_response, options)
|
187
|
+
parser.generate_response
|
188
|
+
end
|
189
|
+
|
190
|
+
def parse_reponse(response)
|
191
|
+
JSON.parse(response.sub(/jsonPFunction\(/, '').sub(/\)\z/, ''))
|
192
|
+
end
|
193
|
+
|
194
|
+
def save_card_url
|
195
|
+
(test? ? 'https://test-token.paymill.com' : 'https://token-v2.paymill.de')
|
196
|
+
end
|
197
|
+
|
198
|
+
def post_data(params)
|
199
|
+
return nil unless params
|
200
|
+
|
201
|
+
no_blanks = params.reject { |key, value| value.blank? }
|
202
|
+
no_blanks.map { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join('&')
|
203
|
+
end
|
204
|
+
|
205
|
+
def add_amount(post, money, options)
|
206
|
+
post[:amount] = amount(money)
|
207
|
+
post[:currency] = (options[:currency] || currency(money))
|
208
|
+
end
|
209
|
+
|
210
|
+
def preauth(authorization)
|
211
|
+
authorization.split(';').last
|
212
|
+
end
|
213
|
+
|
214
|
+
def transaction_id(authorization)
|
215
|
+
authorization.split(';').first
|
216
|
+
end
|
217
|
+
|
218
|
+
RESPONSE_CODES = {
|
219
|
+
10001 => 'Undefined response',
|
220
|
+
10002 => 'Waiting for something',
|
221
|
+
11000 => 'Retry request at a later time',
|
222
|
+
|
223
|
+
20000 => 'Operation successful',
|
224
|
+
20100 => 'Funds held by acquirer',
|
225
|
+
20101 => 'Funds held by acquirer because merchant is new',
|
226
|
+
20200 => 'Transaction reversed',
|
227
|
+
20201 => 'Reversed due to chargeback',
|
228
|
+
20202 => 'Reversed due to money-back guarantee',
|
229
|
+
20203 => 'Reversed due to complaint by buyer',
|
230
|
+
20204 => 'Payment has been refunded',
|
231
|
+
20300 => 'Reversal has been canceled',
|
232
|
+
22000 => 'Initiation of transaction successful',
|
233
|
+
|
234
|
+
30000 => 'Transaction still in progress',
|
235
|
+
30100 => 'Transaction has been accepted',
|
236
|
+
31000 => 'Transaction pending',
|
237
|
+
31100 => 'Pending due to address',
|
238
|
+
31101 => 'Pending due to uncleared eCheck',
|
239
|
+
31102 => 'Pending due to risk review',
|
240
|
+
31103 => 'Pending due regulatory review',
|
241
|
+
31104 => 'Pending due to unregistered/unconfirmed receiver',
|
242
|
+
31200 => 'Pending due to unverified account',
|
243
|
+
31201 => 'Pending due to non-captured funds',
|
244
|
+
31202 => 'Pending due to international account (accept manually)',
|
245
|
+
31203 => 'Pending due to currency conflict (accept manually)',
|
246
|
+
31204 => 'Pending due to fraud filters (accept manually)',
|
247
|
+
|
248
|
+
40000 => 'Problem with transaction data',
|
249
|
+
40001 => 'Problem with payment data',
|
250
|
+
40002 => 'Invalid checksum',
|
251
|
+
40100 => 'Problem with credit card data',
|
252
|
+
40101 => 'Problem with CVV',
|
253
|
+
40102 => 'Card expired or not yet valid',
|
254
|
+
40103 => 'Card limit exceeded',
|
255
|
+
40104 => 'Card is not valid',
|
256
|
+
40105 => 'Expiry date not valid',
|
257
|
+
40106 => 'Credit card brand required',
|
258
|
+
40200 => 'Problem with bank account data',
|
259
|
+
40201 => 'Bank account data combination mismatch',
|
260
|
+
40202 => 'User authentication failed',
|
261
|
+
40300 => 'Problem with 3-D Secure data',
|
262
|
+
40301 => 'Currency/amount mismatch',
|
263
|
+
40400 => 'Problem with input data',
|
264
|
+
40401 => 'Amount too low or zero',
|
265
|
+
40402 => 'Usage field too long',
|
266
|
+
40403 => 'Currency not allowed',
|
267
|
+
40410 => 'Problem with shopping cart data',
|
268
|
+
40420 => 'Problem with address data',
|
269
|
+
40500 => 'Permission error with acquirer API',
|
270
|
+
40510 => 'Rate limit reached for acquirer API',
|
271
|
+
42000 => 'Initiation of transaction failed',
|
272
|
+
42410 => 'Initiation of transaction expired',
|
273
|
+
|
274
|
+
50000 => 'Problem with back end',
|
275
|
+
50001 => 'Country blacklisted',
|
276
|
+
50002 => 'IP address blacklisted',
|
277
|
+
50004 => 'Live mode not allowed',
|
278
|
+
50005 => 'Insufficient permissions (API key)',
|
279
|
+
50100 => 'Technical error with credit card',
|
280
|
+
50101 => 'Error limit exceeded',
|
281
|
+
50102 => 'Card declined',
|
282
|
+
50103 => 'Manipulation or stolen card',
|
283
|
+
50104 => 'Card restricted',
|
284
|
+
50105 => 'Invalid configuration data',
|
285
|
+
50200 => 'Technical error with bank account',
|
286
|
+
50201 => 'Account blacklisted',
|
287
|
+
50300 => 'Technical error with 3-D Secure',
|
288
|
+
50400 => 'Declined because of risk issues',
|
289
|
+
50401 => 'Checksum was wrong',
|
290
|
+
50402 => 'Bank account number was invalid (formal check)',
|
291
|
+
50403 => 'Technical error with risk check',
|
292
|
+
50404 => 'Unknown error with risk check',
|
293
|
+
50405 => 'Unknown bank code',
|
294
|
+
50406 => 'Open chargeback',
|
295
|
+
50407 => 'Historical chargeback',
|
296
|
+
50408 => 'Institution / public bank account (NCA)',
|
297
|
+
50409 => 'KUNO/Fraud',
|
298
|
+
50410 => 'Personal Account Protection (PAP)',
|
299
|
+
50420 => 'Rejected due to acquirer fraud settings',
|
300
|
+
50430 => 'Rejected due to acquirer risk settings',
|
301
|
+
50440 => 'Failed due to restrictions with acquirer account',
|
302
|
+
50450 => 'Failed due to restrictions with user account',
|
303
|
+
50500 => 'General timeout',
|
304
|
+
50501 => 'Timeout on side of the acquirer',
|
305
|
+
50502 => 'Risk management transaction timeout',
|
306
|
+
50600 => 'Duplicate operation',
|
307
|
+
50700 => 'Cancelled by user',
|
308
|
+
50710 => 'Failed due to funding source',
|
309
|
+
50711 => 'Payment method not usable, use other payment method',
|
310
|
+
50712 => 'Limit of funding source was exceeded',
|
311
|
+
50713 => 'Means of payment not reusable (canceled by user)',
|
312
|
+
50714 => 'Means of payment not reusable (expired)',
|
313
|
+
50720 => 'Rejected by acquirer',
|
314
|
+
50730 => 'Transaction denied by merchant',
|
315
|
+
50800 => 'Preauthorisation failed',
|
316
|
+
50810 => 'Authorisation has been voided',
|
317
|
+
50820 => 'Authorisation period expired'
|
318
|
+
}
|
319
|
+
|
320
|
+
def response_message(parsed_response)
|
321
|
+
return parsed_response['error'] if parsed_response['error']
|
322
|
+
return 'Transaction approved.' if parsed_response['data'] == []
|
323
|
+
|
324
|
+
code = parsed_response['data']['response_code'].to_i
|
325
|
+
RESPONSE_CODES[code] || code.to_s
|
326
|
+
end
|
327
|
+
|
328
|
+
class ResponseParser
|
329
|
+
attr_reader :raw_response, :parsed, :succeeded, :message, :options
|
330
|
+
|
331
|
+
def initialize(raw_response='', options={})
|
332
|
+
@raw_response = raw_response
|
333
|
+
@options = options
|
334
|
+
end
|
335
|
+
|
336
|
+
def generate_response
|
337
|
+
parse_response
|
338
|
+
if parsed['error']
|
339
|
+
handle_response_parse_error
|
340
|
+
else
|
341
|
+
handle_response_correct_parsing
|
342
|
+
end
|
343
|
+
|
344
|
+
Response.new(succeeded, message, parsed, options)
|
345
|
+
end
|
346
|
+
|
347
|
+
private
|
348
|
+
|
349
|
+
def parse_response
|
350
|
+
@parsed = JSON.parse(raw_response.sub(/jsonPFunction\(/, '').sub(/\)\z/, ''))
|
351
|
+
end
|
352
|
+
|
353
|
+
def handle_response_parse_error
|
354
|
+
@succeeded = false
|
355
|
+
@message = parsed['error']['message']
|
356
|
+
end
|
357
|
+
|
358
|
+
def handle_response_correct_parsing
|
359
|
+
@message = parsed['transaction']['processing']['return']['message']
|
360
|
+
if @succeeded = is_ack?
|
361
|
+
@options[:authorization] = parsed['transaction']['identification']['uniqueId']
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
def is_ack?
|
366
|
+
parsed['transaction']['processing']['result'] == 'ACK'
|
367
|
+
end
|
368
|
+
end
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|