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,151 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class MoneyMoversGateway < Gateway
|
4
|
+
self.live_url = self.test_url = 'https://secure.mmoagateway.com/api/transact.php'
|
5
|
+
|
6
|
+
APPROVED, DECLINED, ERROR = 1, 2, 3
|
7
|
+
|
8
|
+
self.homepage_url = 'http://mmoa.us/'
|
9
|
+
self.display_name = 'MoneyMovers'
|
10
|
+
self.supported_countries = ['US']
|
11
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :discover]
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
requires!(options, :login, :password)
|
15
|
+
@options = options
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def purchase(money, creditcard, options = {})
|
20
|
+
post = {}
|
21
|
+
add_invoice(post, options)
|
22
|
+
add_creditcard(post, creditcard)
|
23
|
+
add_address(post, options)
|
24
|
+
add_customer_data(post, options)
|
25
|
+
commit('sale', money, post)
|
26
|
+
end
|
27
|
+
|
28
|
+
def authorize(money, creditcard, options = {})
|
29
|
+
post = {}
|
30
|
+
add_invoice(post, options)
|
31
|
+
add_creditcard(post, creditcard)
|
32
|
+
add_address(post, options)
|
33
|
+
add_customer_data(post, options)
|
34
|
+
commit('auth', money, post)
|
35
|
+
end
|
36
|
+
|
37
|
+
def capture(money, authorization, options = {})
|
38
|
+
options[:transactionid] = authorization
|
39
|
+
commit('capture', money, options)
|
40
|
+
end
|
41
|
+
|
42
|
+
def void(authorization, options = {})
|
43
|
+
options[:transactionid] = authorization
|
44
|
+
commit('void', nil, options)
|
45
|
+
end
|
46
|
+
|
47
|
+
def refund(money, authorization, options = {})
|
48
|
+
commit('refund', money, options.merge(:transactionid => authorization))
|
49
|
+
end
|
50
|
+
|
51
|
+
def credit(money, authorization, options = {})
|
52
|
+
ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
|
53
|
+
refund(money, authorization, options)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def add_customer_data(post, options)
|
59
|
+
post[:firstname] = options[:first_name]
|
60
|
+
post[:lastname] = options[:last_name]
|
61
|
+
|
62
|
+
post[:email] = options[:email]
|
63
|
+
end
|
64
|
+
|
65
|
+
def add_address(post, options)
|
66
|
+
if address = (options[:billing_address] || options[:address])
|
67
|
+
post[:company] = address[:company]
|
68
|
+
post[:address1] = address[:address1]
|
69
|
+
post[:address2] = address[:address2]
|
70
|
+
post[:city] = address[:city]
|
71
|
+
post[:state] = address[:state]
|
72
|
+
post[:zip] = address[:zip]
|
73
|
+
post[:country] = address[:country]
|
74
|
+
post[:phone] = address[:phone]
|
75
|
+
end
|
76
|
+
if address = options[:shipping_address]
|
77
|
+
post[:shipping_firstname] = address[:first_name]
|
78
|
+
post[:shipping_lastname] = address[:last_name]
|
79
|
+
post[:shipping_company] = address[:company]
|
80
|
+
post[:shipping_address1] = address[:address1]
|
81
|
+
post[:shipping_address2] = address[:address2]
|
82
|
+
post[:shipping_city] = address[:city]
|
83
|
+
post[:shipping_state] = address[:state]
|
84
|
+
post[:shipping_zip] = address[:zip]
|
85
|
+
post[:shipping_country] = address[:country]
|
86
|
+
post[:shipping_email] = address[:email]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def add_invoice(post, options)
|
91
|
+
post[:orderid] = options[:order_id]
|
92
|
+
post[:orderdescription] = options[:description]
|
93
|
+
end
|
94
|
+
|
95
|
+
def add_creditcard(post, creditcard)
|
96
|
+
post[:ccnumber] = creditcard.number
|
97
|
+
post[:ccexp] = expdate(creditcard)
|
98
|
+
post[:cvv] = creditcard.verification_value
|
99
|
+
end
|
100
|
+
|
101
|
+
def parse(body)
|
102
|
+
body.split('&').inject({}) do |memo, x|
|
103
|
+
k, v = x.split('=')
|
104
|
+
memo[k] = v
|
105
|
+
memo
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def commit(action, money, parameters)
|
110
|
+
parameters[:amount] = amount(money)
|
111
|
+
|
112
|
+
data = ssl_post(self.live_url, post_data(action, parameters))
|
113
|
+
response = parse(data)
|
114
|
+
message = message_from(response)
|
115
|
+
|
116
|
+
Response.new(success?(response), message, response,
|
117
|
+
:test => test?,
|
118
|
+
:authorization => response['transactionid'],
|
119
|
+
:avs_result => {:code => response['avsresponse']},
|
120
|
+
:cvv_result => response['cvvresponse']
|
121
|
+
)
|
122
|
+
end
|
123
|
+
|
124
|
+
def success?(response)
|
125
|
+
response['response'] == '1'
|
126
|
+
end
|
127
|
+
|
128
|
+
def test?
|
129
|
+
@options[:login].eql?('demo') && @options[:password].eql?('password')
|
130
|
+
end
|
131
|
+
|
132
|
+
def message_from(response)
|
133
|
+
case response['response'].to_i
|
134
|
+
when APPROVED
|
135
|
+
'Transaction Approved'
|
136
|
+
when DECLINED
|
137
|
+
'Transaction Declined'
|
138
|
+
else
|
139
|
+
'Error in transaction data or system error'
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def post_data(action, parameters = {})
|
144
|
+
parameters[:type] = action
|
145
|
+
parameters[:username] = @options[:login]
|
146
|
+
parameters[:password] = @options[:password]
|
147
|
+
parameters.map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&')
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,293 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class MundipaggGateway < Gateway
|
4
|
+
self.live_url = 'https://api.mundipagg.com/core/v1'
|
5
|
+
|
6
|
+
self.supported_countries = ['US']
|
7
|
+
self.default_currency = 'USD'
|
8
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :discover, :alelo]
|
9
|
+
|
10
|
+
self.homepage_url = 'https://www.mundipagg.com/'
|
11
|
+
self.display_name = 'Mundipagg'
|
12
|
+
|
13
|
+
STANDARD_ERROR_CODE_MAPPING = {
|
14
|
+
'400' => STANDARD_ERROR_CODE[:processing_error],
|
15
|
+
'401' => STANDARD_ERROR_CODE[:config_error],
|
16
|
+
'404' => STANDARD_ERROR_CODE[:processing_error],
|
17
|
+
'412' => STANDARD_ERROR_CODE[:processing_error],
|
18
|
+
'422' => STANDARD_ERROR_CODE[:processing_error],
|
19
|
+
'500' => STANDARD_ERROR_CODE[:processing_error]
|
20
|
+
}
|
21
|
+
|
22
|
+
STANDARD_ERROR_MESSAGE_MAPPING = {
|
23
|
+
'400' => 'Invalid request;',
|
24
|
+
'401' => 'Invalid API key;',
|
25
|
+
'404' => 'The requested resource does not exist;',
|
26
|
+
'412' => 'Valid parameters but request failed;',
|
27
|
+
'422' => 'Invalid parameters;',
|
28
|
+
'500' => 'An internal error occurred;'
|
29
|
+
}
|
30
|
+
|
31
|
+
def initialize(options={})
|
32
|
+
requires!(options, :api_key)
|
33
|
+
super
|
34
|
+
end
|
35
|
+
|
36
|
+
def purchase(money, payment, options={})
|
37
|
+
post = {}
|
38
|
+
add_invoice(post, money, options)
|
39
|
+
add_customer_data(post, options) unless payment.is_a?(String)
|
40
|
+
add_shipping_address(post, options)
|
41
|
+
add_payment(post, payment, options)
|
42
|
+
|
43
|
+
commit('sale', post)
|
44
|
+
end
|
45
|
+
|
46
|
+
def authorize(money, payment, options={})
|
47
|
+
post = {}
|
48
|
+
add_invoice(post, money, options)
|
49
|
+
add_customer_data(post, options) unless payment.is_a?(String)
|
50
|
+
add_shipping_address(post, options)
|
51
|
+
add_payment(post, payment, options)
|
52
|
+
add_capture_flag(post, payment)
|
53
|
+
commit('authonly', post)
|
54
|
+
end
|
55
|
+
|
56
|
+
def capture(money, authorization, options={})
|
57
|
+
post = {}
|
58
|
+
post[:code] = authorization
|
59
|
+
add_invoice(post, money, options)
|
60
|
+
commit('capture', post, authorization)
|
61
|
+
end
|
62
|
+
|
63
|
+
def refund(money, authorization, options={})
|
64
|
+
add_invoice(post={}, money, options)
|
65
|
+
commit('refund', post, authorization)
|
66
|
+
end
|
67
|
+
|
68
|
+
def void(authorization, options={})
|
69
|
+
commit('void', nil, authorization)
|
70
|
+
end
|
71
|
+
|
72
|
+
def store(payment, options={})
|
73
|
+
post = {}
|
74
|
+
options.update(name: payment.name)
|
75
|
+
options = add_customer(options) unless options[:customer_id]
|
76
|
+
add_payment(post, payment, options)
|
77
|
+
commit('store', post, options[:customer_id])
|
78
|
+
end
|
79
|
+
|
80
|
+
def verify(credit_card, options={})
|
81
|
+
MultiResponse.run(:use_first_response) do |r|
|
82
|
+
r.process { authorize(100, credit_card, options) }
|
83
|
+
r.process(:ignore_result) { void(r.authorization, options) }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def supports_scrubbing?
|
88
|
+
true
|
89
|
+
end
|
90
|
+
|
91
|
+
def scrub(transcript)
|
92
|
+
transcript.
|
93
|
+
gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
|
94
|
+
gsub(%r(("cvv\\":\\")\d*), '\1[FILTERED]').
|
95
|
+
gsub(%r((card\\":{\\"number\\":\\")\d*), '\1[FILTERED]')
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def add_customer(options)
|
101
|
+
post = {}
|
102
|
+
post[:name] = options[:name]
|
103
|
+
customer = commit('customer', post)
|
104
|
+
options.update(customer_id: customer.authorization)
|
105
|
+
end
|
106
|
+
|
107
|
+
def add_customer_data(post, options)
|
108
|
+
post[:customer] = {}
|
109
|
+
post[:customer][:email] = options[:email]
|
110
|
+
end
|
111
|
+
|
112
|
+
def add_billing_address(post, type, options)
|
113
|
+
if address = (options[:billing_address] || options[:address])
|
114
|
+
billing = {}
|
115
|
+
address = options[:billing_address] || options[:address]
|
116
|
+
billing[:street] = address[:address1].match(/\D+/)[0].strip if address[:address1]
|
117
|
+
billing[:number] = address[:address1].match(/\d+/)[0] if address[:address1]
|
118
|
+
billing[:compliment] = address[:address2] if address[:address2]
|
119
|
+
billing[:city] = address[:city] if address[:city]
|
120
|
+
billing[:state] = address[:state] if address[:state]
|
121
|
+
billing[:country] = address[:country] if address[:country]
|
122
|
+
billing[:zip_code] = address[:zip] if address[:zip]
|
123
|
+
billing[:neighborhood] = address[:neighborhood]
|
124
|
+
post[:payment][type.to_sym][:card][:billing_address] = billing
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def add_shipping_address(post, options)
|
129
|
+
if address = options[:shipping_address]
|
130
|
+
post[:address] = {}
|
131
|
+
post[:address][:street] = address[:address1].match(/\D+/)[0].strip if address[:address1]&.match(/\D+/)
|
132
|
+
post[:address][:number] = address[:address1].match(/\d+/)[0] if address[:address1]&.match(/\d+/)
|
133
|
+
post[:address][:compliment] = address[:address2] if address[:address2]
|
134
|
+
post[:address][:city] = address[:city] if address[:city]
|
135
|
+
post[:address][:state] = address[:state] if address[:state]
|
136
|
+
post[:address][:country] = address[:country] if address[:country]
|
137
|
+
post[:address][:zip_code] = address[:zip] if address[:zip]
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def add_invoice(post, money, options)
|
142
|
+
post[:amount] = money
|
143
|
+
post[:currency] = (options[:currency] || currency(money))
|
144
|
+
end
|
145
|
+
|
146
|
+
def add_capture_flag(post, payment)
|
147
|
+
if voucher?(payment)
|
148
|
+
post[:payment][:voucher][:capture] = false
|
149
|
+
else
|
150
|
+
post[:payment][:credit_card][:capture] = false
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def add_payment(post, payment, options)
|
155
|
+
post[:customer][:name] = payment.name if post[:customer]
|
156
|
+
post[:customer_id] = parse_auth(payment)[0] if payment.is_a?(String)
|
157
|
+
post[:payment] = {}
|
158
|
+
affiliation = options[:gateway_affiliation_id] || @options[:gateway_id]
|
159
|
+
post[:payment][:gateway_affiliation_id] = affiliation if affiliation
|
160
|
+
post[:payment][:metadata] = { mundipagg_payment_method_code: '1' } if test?
|
161
|
+
if voucher?(payment)
|
162
|
+
add_voucher(post, payment, options)
|
163
|
+
else
|
164
|
+
add_credit_card(post, payment, options)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def add_credit_card(post, payment, options)
|
169
|
+
post[:payment][:payment_method] = 'credit_card'
|
170
|
+
post[:payment][:credit_card] = {}
|
171
|
+
if payment.is_a?(String)
|
172
|
+
post[:payment][:credit_card][:card_id] = parse_auth(payment)[1]
|
173
|
+
else
|
174
|
+
post[:payment][:credit_card][:card] = {}
|
175
|
+
post[:payment][:credit_card][:card][:number] = payment.number
|
176
|
+
post[:payment][:credit_card][:card][:holder_name] = payment.name
|
177
|
+
post[:payment][:credit_card][:card][:exp_month] = payment.month
|
178
|
+
post[:payment][:credit_card][:card][:exp_year] = payment.year
|
179
|
+
post[:payment][:credit_card][:card][:cvv] = payment.verification_value
|
180
|
+
post[:payment][:credit_card][:card][:holder_document] = options[:holder_document] if options[:holder_document]
|
181
|
+
add_billing_address(post, 'credit_card', options)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def add_voucher(post, payment, options)
|
186
|
+
post[:currency] = 'BRL'
|
187
|
+
post[:payment][:payment_method] = 'voucher'
|
188
|
+
post[:payment][:voucher] = {}
|
189
|
+
post[:payment][:voucher][:card] = {}
|
190
|
+
post[:payment][:voucher][:card][:number] = payment.number
|
191
|
+
post[:payment][:voucher][:card][:holder_name] = payment.name
|
192
|
+
post[:payment][:voucher][:card][:holder_document] = options[:holder_document]
|
193
|
+
post[:payment][:voucher][:card][:exp_month] = payment.month
|
194
|
+
post[:payment][:voucher][:card][:exp_year] = payment.year
|
195
|
+
post[:payment][:voucher][:card][:cvv] = payment.verification_value
|
196
|
+
add_billing_address(post, 'voucher', options)
|
197
|
+
end
|
198
|
+
|
199
|
+
def voucher?(payment)
|
200
|
+
return false if payment.is_a?(String)
|
201
|
+
%w[sodexo vr].include? card_brand(payment)
|
202
|
+
end
|
203
|
+
|
204
|
+
def headers
|
205
|
+
{
|
206
|
+
'Authorization' => 'Basic ' + Base64.strict_encode64("#{@options[:api_key]}:"),
|
207
|
+
'Content-Type' => 'application/json',
|
208
|
+
'Accept' => 'application/json'
|
209
|
+
}
|
210
|
+
end
|
211
|
+
|
212
|
+
def parse(body)
|
213
|
+
JSON.parse(body)
|
214
|
+
end
|
215
|
+
|
216
|
+
def url_for(action, auth = nil)
|
217
|
+
url = live_url
|
218
|
+
case action
|
219
|
+
when 'store'
|
220
|
+
"#{url}/customers/#{auth}/cards/"
|
221
|
+
when 'customer'
|
222
|
+
"#{url}/customers/"
|
223
|
+
when 'refund', 'void'
|
224
|
+
"#{url}/charges/#{auth}/"
|
225
|
+
when 'capture'
|
226
|
+
"#{url}/charges/#{auth}/capture/"
|
227
|
+
else
|
228
|
+
"#{url}/charges/"
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def commit(action, parameters, auth = nil)
|
233
|
+
url = url_for(action, auth)
|
234
|
+
parameters.merge!(parameters[:payment][:credit_card].delete(:card)).delete(:payment) if action == 'store'
|
235
|
+
response = if %w[refund void].include? action
|
236
|
+
parse(ssl_request(:delete, url, post_data(parameters), headers))
|
237
|
+
else
|
238
|
+
parse(ssl_post(url, post_data(parameters), headers))
|
239
|
+
end
|
240
|
+
|
241
|
+
Response.new(
|
242
|
+
success_from(response),
|
243
|
+
message_from(response),
|
244
|
+
response,
|
245
|
+
authorization: authorization_from(response, action),
|
246
|
+
avs_result: AVSResult.new(code: response['some_avs_response_key']),
|
247
|
+
cvv_result: CVVResult.new(response['some_cvv_response_key']),
|
248
|
+
test: test?,
|
249
|
+
error_code: error_code_from(response)
|
250
|
+
)
|
251
|
+
rescue ResponseError => e
|
252
|
+
message = get_error_message(e)
|
253
|
+
return Response.new(
|
254
|
+
false,
|
255
|
+
"#{STANDARD_ERROR_MESSAGE_MAPPING[e.response.code]} #{message}",
|
256
|
+
parse(e.response.body),
|
257
|
+
test: test?,
|
258
|
+
error_code: STANDARD_ERROR_CODE_MAPPING[e.response.code]
|
259
|
+
)
|
260
|
+
end
|
261
|
+
|
262
|
+
def success_from(response)
|
263
|
+
%w[pending paid processing canceled active].include? response['status']
|
264
|
+
end
|
265
|
+
|
266
|
+
def get_error_message(error)
|
267
|
+
JSON.parse(error.response.body)['message']
|
268
|
+
end
|
269
|
+
|
270
|
+
def message_from(response)
|
271
|
+
return response['message'] if response['message']
|
272
|
+
return response['last_transaction']['acquirer_message'] if response['last_transaction']
|
273
|
+
end
|
274
|
+
|
275
|
+
def authorization_from(response, action)
|
276
|
+
return "#{response['customer']['id']}|#{response['id']}" if action == 'store'
|
277
|
+
response['id']
|
278
|
+
end
|
279
|
+
|
280
|
+
def parse_auth(auth)
|
281
|
+
auth.split('|')
|
282
|
+
end
|
283
|
+
|
284
|
+
def post_data(parameters = {})
|
285
|
+
parameters.to_json
|
286
|
+
end
|
287
|
+
|
288
|
+
def error_code_from(response)
|
289
|
+
STANDARD_ERROR_CODE[:processing_error] unless success_from(response)
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
@@ -0,0 +1,301 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
module ActiveMerchant #:nodoc:
|
4
|
+
module Billing #:nodoc:
|
5
|
+
# The National Australia Bank provide a payment gateway that seems to
|
6
|
+
# be a rebadged Securepay Australia service, though some differences exist.
|
7
|
+
class NabTransactGateway < Gateway
|
8
|
+
API_VERSION = 'xml-4.2'
|
9
|
+
PERIODIC_API_VERSION = 'spxml-4.2'
|
10
|
+
|
11
|
+
class_attribute :test_periodic_url, :live_periodic_url
|
12
|
+
|
13
|
+
self.test_url = 'https://demo.transact.nab.com.au/xmlapi/payment'
|
14
|
+
self.live_url = 'https://transact.nab.com.au/live/xmlapi/payment'
|
15
|
+
self.test_periodic_url = 'https://demo.transact.nab.com.au/xmlapi/periodic'
|
16
|
+
self.live_periodic_url = 'https://transact.nab.com.au/xmlapi/periodic'
|
17
|
+
|
18
|
+
self.supported_countries = ['AU']
|
19
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :jcb]
|
20
|
+
|
21
|
+
self.homepage_url = 'http://transact.nab.com.au'
|
22
|
+
self.display_name = 'NAB Transact'
|
23
|
+
self.money_format = :cents
|
24
|
+
self.default_currency = 'AUD'
|
25
|
+
|
26
|
+
# Transactions currently accepted by NAB Transact XML API
|
27
|
+
TRANSACTIONS = {
|
28
|
+
:purchase => 0, # Standard Payment
|
29
|
+
:refund => 4, # Refund
|
30
|
+
:void => 6, # Client Reversal (Void)
|
31
|
+
:unmatched_refund => 666, # Unmatched Refund
|
32
|
+
:authorization => 10, # Preauthorise
|
33
|
+
:capture => 11 # Preauthorise Complete (Advice)
|
34
|
+
}
|
35
|
+
|
36
|
+
PERIODIC_TYPES = {
|
37
|
+
:addcrn => 5,
|
38
|
+
:deletecrn => 5,
|
39
|
+
:trigger => 8
|
40
|
+
}
|
41
|
+
|
42
|
+
SUCCESS_CODES = [ '00', '08', '11', '16', '77' ]
|
43
|
+
|
44
|
+
def initialize(options = {})
|
45
|
+
requires!(options, :login, :password)
|
46
|
+
super
|
47
|
+
end
|
48
|
+
|
49
|
+
def purchase(money, credit_card_or_stored_id, options = {})
|
50
|
+
if credit_card_or_stored_id.respond_to?(:number)
|
51
|
+
commit :purchase, build_purchase_request(money, credit_card_or_stored_id, options)
|
52
|
+
else
|
53
|
+
commit_periodic(:trigger, build_purchase_using_stored_card_request(money, credit_card_or_stored_id, options))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def credit(money, credit_card, options = {})
|
58
|
+
commit :unmatched_refund, build_purchase_request(money, credit_card, options)
|
59
|
+
end
|
60
|
+
|
61
|
+
def refund(money, authorization, options = {})
|
62
|
+
commit :refund, build_reference_request(money, authorization, options)
|
63
|
+
end
|
64
|
+
|
65
|
+
def authorize(money, credit_card, options = {})
|
66
|
+
commit :authorization, build_purchase_request(money, credit_card, options)
|
67
|
+
end
|
68
|
+
|
69
|
+
def capture(money, authorization, options = {})
|
70
|
+
commit :capture, build_reference_request(money, authorization, options)
|
71
|
+
end
|
72
|
+
|
73
|
+
def store(credit_card, options = {})
|
74
|
+
commit_periodic(:addcrn, build_store_request(credit_card, options))
|
75
|
+
end
|
76
|
+
|
77
|
+
def unstore(identification, options = {})
|
78
|
+
commit_periodic(:deletecrn, build_unstore_request(identification, options))
|
79
|
+
end
|
80
|
+
|
81
|
+
def supports_scrubbing?
|
82
|
+
true
|
83
|
+
end
|
84
|
+
|
85
|
+
def scrub(transcript)
|
86
|
+
return '' if transcript.blank?
|
87
|
+
transcript.
|
88
|
+
gsub(%r((<cardNumber>)[^<]+(<))i, '\1[FILTERED]\2').
|
89
|
+
gsub(%r((<cvv>)[^<]+(<))i, '\1[FILTERED]\2').
|
90
|
+
gsub(%r((<password>)[^<]+(<))i, '\1[FILTERED]\2')
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def add_metadata(xml, options)
|
96
|
+
if options[:merchant_name] || options[:merchant_location]
|
97
|
+
xml.tag! 'metadata' do
|
98
|
+
xml.tag! 'meta', :name => 'ca_name', :value => options[:merchant_name] if options[:merchant_name]
|
99
|
+
xml.tag! 'meta', :name => 'ca_location', :value => options[:merchant_location] if options[:merchant_location]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def build_purchase_request(money, credit_card, options)
|
105
|
+
xml = Builder::XmlMarkup.new
|
106
|
+
xml.tag! 'amount', localized_amount(money, options[:currency] || currency(money))
|
107
|
+
xml.tag! 'currency', options[:currency] || currency(money)
|
108
|
+
xml.tag! 'purchaseOrderNo', options[:order_id].to_s.gsub(/[ ']/, '')
|
109
|
+
|
110
|
+
xml.tag! 'CreditCardInfo' do
|
111
|
+
xml.tag! 'cardNumber', credit_card.number
|
112
|
+
xml.tag! 'expiryDate', expdate(credit_card)
|
113
|
+
xml.tag! 'cvv', credit_card.verification_value if credit_card.verification_value?
|
114
|
+
end
|
115
|
+
|
116
|
+
add_metadata(xml, options)
|
117
|
+
|
118
|
+
xml.target!
|
119
|
+
end
|
120
|
+
|
121
|
+
def build_reference_request(money, reference, options)
|
122
|
+
xml = Builder::XmlMarkup.new
|
123
|
+
|
124
|
+
transaction_id, order_id, preauth_id, original_amount = reference.split('*')
|
125
|
+
|
126
|
+
xml.tag! 'amount', (money ? localized_amount(money, options[:currency] || currency(money)) : original_amount)
|
127
|
+
xml.tag! 'currency', options[:currency] || currency(money)
|
128
|
+
xml.tag! 'txnID', transaction_id
|
129
|
+
xml.tag! 'purchaseOrderNo', order_id
|
130
|
+
xml.tag! 'preauthID', preauth_id
|
131
|
+
|
132
|
+
add_metadata(xml, options)
|
133
|
+
|
134
|
+
xml.target!
|
135
|
+
end
|
136
|
+
|
137
|
+
# Generate payment request XML
|
138
|
+
# - API is set to allow multiple Txn's but currently only allows one
|
139
|
+
# - txnSource = 23 - (XML)
|
140
|
+
def build_request(action, body)
|
141
|
+
xml = Builder::XmlMarkup.new
|
142
|
+
xml.instruct!
|
143
|
+
xml.tag! 'NABTransactMessage' do
|
144
|
+
xml.tag! 'MessageInfo' do
|
145
|
+
xml.tag! 'messageID', SecureRandom.hex(15)
|
146
|
+
xml.tag! 'messageTimestamp', generate_timestamp
|
147
|
+
xml.tag! 'timeoutValue', request_timeout
|
148
|
+
xml.tag! 'apiVersion', API_VERSION
|
149
|
+
end
|
150
|
+
|
151
|
+
xml.tag! 'MerchantInfo' do
|
152
|
+
xml.tag! 'merchantID', @options[:login]
|
153
|
+
xml.tag! 'password', @options[:password]
|
154
|
+
end
|
155
|
+
|
156
|
+
xml.tag! 'RequestType', 'Payment'
|
157
|
+
xml.tag! 'Payment' do
|
158
|
+
xml.tag! 'TxnList', 'count' => 1 do
|
159
|
+
xml.tag! 'Txn', 'ID' => 1 do
|
160
|
+
xml.tag! 'txnType', TRANSACTIONS[action]
|
161
|
+
xml.tag! 'txnSource', 23
|
162
|
+
xml << body
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
xml.target!
|
169
|
+
end
|
170
|
+
|
171
|
+
def build_periodic_request(action, body)
|
172
|
+
xml = Builder::XmlMarkup.new
|
173
|
+
xml.instruct!
|
174
|
+
xml.tag! 'NABTransactMessage' do
|
175
|
+
xml.tag! 'MessageInfo' do
|
176
|
+
xml.tag! 'messageID', SecureRandom.hex(15)
|
177
|
+
xml.tag! 'messageTimestamp', generate_timestamp
|
178
|
+
xml.tag! 'timeoutValue', request_timeout
|
179
|
+
xml.tag! 'apiVersion', PERIODIC_API_VERSION
|
180
|
+
end
|
181
|
+
|
182
|
+
xml.tag! 'MerchantInfo' do
|
183
|
+
xml.tag! 'merchantID', @options[:login]
|
184
|
+
xml.tag! 'password', @options[:password]
|
185
|
+
end
|
186
|
+
|
187
|
+
xml.tag! 'RequestType', 'Periodic'
|
188
|
+
xml.tag! 'Periodic' do
|
189
|
+
xml.tag! 'PeriodicList', 'count' => 1 do
|
190
|
+
xml.tag! 'PeriodicItem', 'ID' => 1 do
|
191
|
+
xml.tag! 'actionType', action.to_s
|
192
|
+
xml.tag! 'periodicType', PERIODIC_TYPES[action] if PERIODIC_TYPES[action]
|
193
|
+
xml << body
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
xml.target!
|
200
|
+
end
|
201
|
+
|
202
|
+
def build_purchase_using_stored_card_request(money, identification, options)
|
203
|
+
xml = Builder::XmlMarkup.new
|
204
|
+
|
205
|
+
xml.tag! 'crn', identification
|
206
|
+
xml.tag! 'currency', options[:currency] || currency(money)
|
207
|
+
xml.tag! 'amount', localized_amount(money, options[:currency] || currency(money))
|
208
|
+
|
209
|
+
xml.target!
|
210
|
+
end
|
211
|
+
|
212
|
+
def build_store_request(credit_card, options)
|
213
|
+
xml = Builder::XmlMarkup.new
|
214
|
+
|
215
|
+
xml.tag! 'crn', options[:billing_id] || SecureRandom.hex(10)
|
216
|
+
xml.tag! 'CreditCardInfo' do
|
217
|
+
xml.tag! 'cardNumber', credit_card.number
|
218
|
+
xml.tag! 'expiryDate', expdate(credit_card)
|
219
|
+
xml.tag! 'cvv', credit_card.verification_value if credit_card.verification_value?
|
220
|
+
end
|
221
|
+
|
222
|
+
xml.target!
|
223
|
+
end
|
224
|
+
|
225
|
+
def build_unstore_request(identification, options)
|
226
|
+
xml = Builder::XmlMarkup.new
|
227
|
+
|
228
|
+
xml.tag! 'crn', identification
|
229
|
+
xml.target!
|
230
|
+
end
|
231
|
+
|
232
|
+
def commit(action, request)
|
233
|
+
response = parse(ssl_post(test? ? self.test_url : self.live_url, build_request(action, request)))
|
234
|
+
|
235
|
+
Response.new(success?(response), message_from(response), response,
|
236
|
+
:test => test?,
|
237
|
+
:authorization => authorization_from(action, response)
|
238
|
+
)
|
239
|
+
end
|
240
|
+
|
241
|
+
def commit_periodic(action, request)
|
242
|
+
response = parse(ssl_post(test? ? self.test_periodic_url : self.live_periodic_url, build_periodic_request(action, request)))
|
243
|
+
Response.new(success?(response), message_from(response), response,
|
244
|
+
:test => test?,
|
245
|
+
:authorization => authorization_from(action, response)
|
246
|
+
)
|
247
|
+
end
|
248
|
+
|
249
|
+
def success?(response)
|
250
|
+
SUCCESS_CODES.include?(response[:response_code])
|
251
|
+
end
|
252
|
+
|
253
|
+
def authorization_from(action, response)
|
254
|
+
if action == :addcrn
|
255
|
+
response[:crn]
|
256
|
+
else
|
257
|
+
[response[:txn_id], response[:purchase_order_no], response[:preauth_id], response[:amount]].join('*')
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
def message_from(response)
|
262
|
+
response[:response_text] || response[:status_description]
|
263
|
+
end
|
264
|
+
|
265
|
+
def expdate(credit_card)
|
266
|
+
"#{format(credit_card.month, :two_digits)}/#{format(credit_card.year, :two_digits)}"
|
267
|
+
end
|
268
|
+
|
269
|
+
def parse(body)
|
270
|
+
xml = REXML::Document.new(body)
|
271
|
+
|
272
|
+
response = {}
|
273
|
+
|
274
|
+
xml.root.elements.to_a.each do |node|
|
275
|
+
parse_element(response, node)
|
276
|
+
end
|
277
|
+
|
278
|
+
response
|
279
|
+
end
|
280
|
+
|
281
|
+
def parse_element(response, node)
|
282
|
+
if node.has_elements?
|
283
|
+
node.elements.each { |element| parse_element(response, element) }
|
284
|
+
else
|
285
|
+
response[node.name.underscore.to_sym] = node.text
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
# YYYYDDMMHHNNSSKKK000sOOO
|
290
|
+
def generate_timestamp
|
291
|
+
time = Time.now.utc
|
292
|
+
time.strftime("%Y%d%m%H%M%S#{time.usec}+000")
|
293
|
+
end
|
294
|
+
|
295
|
+
def request_timeout
|
296
|
+
@options[:request_timeout] || 60
|
297
|
+
end
|
298
|
+
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|