activemerchant 1.100.0 → 1.133.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +1057 -0
  3. data/README.md +11 -9
  4. data/lib/active_merchant/billing/avs_result.rb +9 -9
  5. data/lib/active_merchant/billing/base.rb +0 -13
  6. data/lib/active_merchant/billing/check.rb +49 -17
  7. data/lib/active_merchant/billing/compatibility.rb +5 -4
  8. data/lib/active_merchant/billing/credit_card.rb +55 -8
  9. data/lib/active_merchant/billing/credit_card_formatting.rb +1 -0
  10. data/lib/active_merchant/billing/credit_card_methods.rb +209 -36
  11. data/lib/active_merchant/billing/cvv_result.rb +0 -1
  12. data/lib/active_merchant/billing/gateway.rb +38 -36
  13. data/lib/active_merchant/billing/gateways/adyen.rb +399 -78
  14. data/lib/active_merchant/billing/gateways/airwallex.rb +370 -0
  15. data/lib/active_merchant/billing/gateways/alelo.rb +256 -0
  16. data/lib/active_merchant/billing/gateways/allied_wallet.rb +14 -14
  17. data/lib/active_merchant/billing/gateways/authorize_net.rb +200 -130
  18. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +27 -20
  19. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +48 -51
  20. data/lib/active_merchant/billing/gateways/axcessms.rb +13 -15
  21. data/lib/active_merchant/billing/gateways/balanced.rb +43 -36
  22. data/lib/active_merchant/billing/gateways/bambora_apac.rb +16 -20
  23. data/lib/active_merchant/billing/gateways/bank_frick.rb +13 -13
  24. data/lib/active_merchant/billing/gateways/banwire.rb +5 -5
  25. data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +43 -30
  26. data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +1 -1
  27. data/lib/active_merchant/billing/gateways/be2bill.rb +5 -5
  28. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +37 -36
  29. data/lib/active_merchant/billing/gateways/beanstream.rb +21 -3
  30. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +1 -1
  31. data/lib/active_merchant/billing/gateways/blue_pay.rb +53 -28
  32. data/lib/active_merchant/billing/gateways/blue_snap.rb +176 -54
  33. data/lib/active_merchant/billing/gateways/bogus.rb +24 -20
  34. data/lib/active_merchant/billing/gateways/borgun.rb +92 -38
  35. data/lib/active_merchant/billing/gateways/bpoint.rb +15 -15
  36. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +8 -2
  37. data/lib/active_merchant/billing/gateways/braintree/token_nonce.rb +113 -0
  38. data/lib/active_merchant/billing/gateways/braintree.rb +1 -1
  39. data/lib/active_merchant/billing/gateways/braintree_blue.rb +387 -175
  40. data/lib/active_merchant/billing/gateways/bridge_pay.rb +13 -13
  41. data/lib/active_merchant/billing/gateways/cams.rb +10 -10
  42. data/lib/active_merchant/billing/gateways/card_connect.rb +33 -14
  43. data/lib/active_merchant/billing/gateways/card_save.rb +3 -4
  44. data/lib/active_merchant/billing/gateways/card_stream.rb +67 -40
  45. data/lib/active_merchant/billing/gateways/cardknox.rb +13 -13
  46. data/lib/active_merchant/billing/gateways/cardprocess.rb +4 -2
  47. data/lib/active_merchant/billing/gateways/cashnet.rb +28 -12
  48. data/lib/active_merchant/billing/gateways/cc5.rb +9 -9
  49. data/lib/active_merchant/billing/gateways/cecabank.rb +38 -38
  50. data/lib/active_merchant/billing/gateways/cenpos.rb +29 -28
  51. data/lib/active_merchant/billing/gateways/checkout.rb +7 -9
  52. data/lib/active_merchant/billing/gateways/checkout_v2.rb +316 -68
  53. data/lib/active_merchant/billing/gateways/citrus_pay.rb +1 -2
  54. data/lib/active_merchant/billing/gateways/clearhaus.rb +32 -33
  55. data/lib/active_merchant/billing/gateways/commerce_hub.rb +370 -0
  56. data/lib/active_merchant/billing/gateways/commercegate.rb +4 -4
  57. data/lib/active_merchant/billing/gateways/conekta.rb +8 -6
  58. data/lib/active_merchant/billing/gateways/creditcall.rb +18 -17
  59. data/lib/active_merchant/billing/gateways/credorax.rb +152 -63
  60. data/lib/active_merchant/billing/gateways/ct_payment.rb +15 -14
  61. data/lib/active_merchant/billing/gateways/culqi.rb +30 -28
  62. data/lib/active_merchant/billing/gateways/cyber_source/cyber_source_common.rb +36 -0
  63. data/lib/active_merchant/billing/gateways/cyber_source.rb +496 -187
  64. data/lib/active_merchant/billing/gateways/cyber_source_rest.rb +454 -0
  65. data/lib/active_merchant/billing/gateways/d_local.rb +148 -31
  66. data/lib/active_merchant/billing/gateways/data_cash.rb +34 -37
  67. data/lib/active_merchant/billing/gateways/decidir.rb +134 -21
  68. data/lib/active_merchant/billing/gateways/decidir_plus.rb +344 -0
  69. data/lib/active_merchant/billing/gateways/dibs.rb +10 -10
  70. data/lib/active_merchant/billing/gateways/digitzs.rb +11 -8
  71. data/lib/active_merchant/billing/gateways/ebanx.rb +90 -40
  72. data/lib/active_merchant/billing/gateways/efsnet.rb +36 -36
  73. data/lib/active_merchant/billing/gateways/elavon.rb +349 -194
  74. data/lib/active_merchant/billing/gateways/element.rb +71 -21
  75. data/lib/active_merchant/billing/gateways/epay.rb +43 -43
  76. data/lib/active_merchant/billing/gateways/evo_ca.rb +12 -13
  77. data/lib/active_merchant/billing/gateways/eway.rb +9 -9
  78. data/lib/active_merchant/billing/gateways/eway_managed.rb +55 -56
  79. data/lib/active_merchant/billing/gateways/eway_rapid.rb +37 -22
  80. data/lib/active_merchant/billing/gateways/exact.rb +19 -20
  81. data/lib/active_merchant/billing/gateways/ezic.rb +9 -9
  82. data/lib/active_merchant/billing/gateways/fat_zebra.rb +24 -19
  83. data/lib/active_merchant/billing/gateways/federated_canada.rb +6 -7
  84. data/lib/active_merchant/billing/gateways/finansbank.rb +3 -3
  85. data/lib/active_merchant/billing/gateways/first_giving.rb +5 -4
  86. data/lib/active_merchant/billing/gateways/first_pay.rb +7 -7
  87. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +39 -38
  88. data/lib/active_merchant/billing/gateways/firstdata_e4_v27.rb +51 -31
  89. data/lib/active_merchant/billing/gateways/flo2cash.rb +24 -24
  90. data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +1 -1
  91. data/lib/active_merchant/billing/gateways/forte.rb +38 -22
  92. data/lib/active_merchant/billing/gateways/garanti.rb +12 -15
  93. data/lib/active_merchant/billing/gateways/global_collect.rb +333 -89
  94. data/lib/active_merchant/billing/gateways/global_transport.rb +8 -9
  95. data/lib/active_merchant/billing/gateways/hdfc.rb +22 -23
  96. data/lib/active_merchant/billing/gateways/hps.rb +171 -50
  97. data/lib/active_merchant/billing/gateways/iats_payments.rb +47 -25
  98. data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +1 -1
  99. data/lib/active_merchant/billing/gateways/inspire.rb +22 -27
  100. data/lib/active_merchant/billing/gateways/instapay.rb +5 -8
  101. data/lib/active_merchant/billing/gateways/ipg.rb +420 -0
  102. data/lib/active_merchant/billing/gateways/ipp.rb +9 -9
  103. data/lib/active_merchant/billing/gateways/iridium.rb +30 -31
  104. data/lib/active_merchant/billing/gateways/itransact.rb +11 -10
  105. data/lib/active_merchant/billing/gateways/iveri.rb +62 -23
  106. data/lib/active_merchant/billing/gateways/ixopay.rb +320 -0
  107. data/lib/active_merchant/billing/gateways/jetpay.rb +10 -17
  108. data/lib/active_merchant/billing/gateways/jetpay_v2.rb +13 -18
  109. data/lib/active_merchant/billing/gateways/komoju.rb +1 -1
  110. data/lib/active_merchant/billing/gateways/kushki.rb +100 -22
  111. data/lib/active_merchant/billing/gateways/latitude19.rb +20 -19
  112. data/lib/active_merchant/billing/gateways/linkpoint.rb +71 -72
  113. data/lib/active_merchant/billing/gateways/litle.rb +181 -45
  114. data/lib/active_merchant/billing/gateways/mastercard.rb +16 -22
  115. data/lib/active_merchant/billing/gateways/maxipago.rb +2 -2
  116. data/lib/active_merchant/billing/gateways/mercado_pago.rb +89 -18
  117. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +58 -24
  118. data/lib/active_merchant/billing/gateways/merchant_one.rb +7 -10
  119. data/lib/active_merchant/billing/gateways/merchant_partners.rb +19 -19
  120. data/lib/active_merchant/billing/gateways/merchant_ware.rb +18 -22
  121. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +15 -17
  122. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +46 -8
  123. data/lib/active_merchant/billing/gateways/mercury.rb +19 -23
  124. data/lib/active_merchant/billing/gateways/metrics_global.rb +24 -33
  125. data/lib/active_merchant/billing/gateways/micropayment.rb +11 -12
  126. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +7 -7
  127. data/lib/active_merchant/billing/gateways/migs.rb +18 -21
  128. data/lib/active_merchant/billing/gateways/mit.rb +260 -0
  129. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +10 -12
  130. data/lib/active_merchant/billing/gateways/moka.rb +290 -0
  131. data/lib/active_merchant/billing/gateways/monei.rb +236 -150
  132. data/lib/active_merchant/billing/gateways/moneris.rb +122 -53
  133. data/lib/active_merchant/billing/gateways/money_movers.rb +6 -7
  134. data/lib/active_merchant/billing/gateways/mundipagg.rb +69 -23
  135. data/lib/active_merchant/billing/gateways/nab_transact.rb +18 -20
  136. data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +10 -12
  137. data/lib/active_merchant/billing/gateways/net_registry.rb +8 -9
  138. data/lib/active_merchant/billing/gateways/netaxept.rb +12 -12
  139. data/lib/active_merchant/billing/gateways/netbanx.rb +128 -46
  140. data/lib/active_merchant/billing/gateways/netbilling.rb +18 -21
  141. data/lib/active_merchant/billing/gateways/netpay.rb +5 -4
  142. data/lib/active_merchant/billing/gateways/network_merchants.rb +7 -10
  143. data/lib/active_merchant/billing/gateways/nmi.rb +69 -27
  144. data/lib/active_merchant/billing/gateways/ogone.rb +62 -31
  145. data/lib/active_merchant/billing/gateways/omise.rb +15 -16
  146. data/lib/active_merchant/billing/gateways/openpay.rb +33 -15
  147. data/lib/active_merchant/billing/gateways/opp.rb +39 -33
  148. data/lib/active_merchant/billing/gateways/optimal_payment.rb +43 -42
  149. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +3 -5
  150. data/lib/active_merchant/billing/gateways/orbital.rb +623 -362
  151. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +20 -20
  152. data/lib/active_merchant/billing/gateways/pagarme.rb +16 -23
  153. data/lib/active_merchant/billing/gateways/pago_facil.rb +4 -6
  154. data/lib/active_merchant/billing/gateways/pay_arc.rb +392 -0
  155. data/lib/active_merchant/billing/gateways/pay_conex.rb +17 -17
  156. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +30 -33
  157. data/lib/active_merchant/billing/gateways/pay_hub.rb +10 -10
  158. data/lib/active_merchant/billing/gateways/pay_junction.rb +31 -31
  159. data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +36 -18
  160. data/lib/active_merchant/billing/gateways/pay_secure.rb +10 -11
  161. data/lib/active_merchant/billing/gateways/pay_trace.rb +450 -0
  162. data/lib/active_merchant/billing/gateways/paybox_direct.rb +64 -40
  163. data/lib/active_merchant/billing/gateways/payeezy.rb +130 -27
  164. data/lib/active_merchant/billing/gateways/payex.rb +24 -25
  165. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +17 -17
  166. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +1 -1
  167. data/lib/active_merchant/billing/gateways/payflow.rb +103 -25
  168. data/lib/active_merchant/billing/gateways/payflow_express.rb +4 -4
  169. data/lib/active_merchant/billing/gateways/payflow_uk.rb +1 -1
  170. data/lib/active_merchant/billing/gateways/payment_express.rb +22 -18
  171. data/lib/active_merchant/billing/gateways/paymentez.rb +89 -24
  172. data/lib/active_merchant/billing/gateways/paymill.rb +14 -16
  173. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +2 -1
  174. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +4 -0
  175. data/lib/active_merchant/billing/gateways/paypal.rb +13 -5
  176. data/lib/active_merchant/billing/gateways/paypal_ca.rb +1 -1
  177. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +1 -1
  178. data/lib/active_merchant/billing/gateways/paypal_express.rb +4 -1
  179. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +1 -1
  180. data/lib/active_merchant/billing/gateways/paysafe.rb +420 -0
  181. data/lib/active_merchant/billing/gateways/payscout.rb +8 -9
  182. data/lib/active_merchant/billing/gateways/paystation.rb +6 -9
  183. data/lib/active_merchant/billing/gateways/payu_in.rb +20 -19
  184. data/lib/active_merchant/billing/gateways/payu_latam.rb +70 -37
  185. data/lib/active_merchant/billing/gateways/payway.rb +22 -22
  186. data/lib/active_merchant/billing/gateways/payway_dot_com.rb +253 -0
  187. data/lib/active_merchant/billing/gateways/pin.rb +60 -21
  188. data/lib/active_merchant/billing/gateways/plexo.rb +308 -0
  189. data/lib/active_merchant/billing/gateways/plugnpay.rb +20 -21
  190. data/lib/active_merchant/billing/gateways/priority.rb +392 -0
  191. data/lib/active_merchant/billing/gateways/pro_pay.rb +13 -14
  192. data/lib/active_merchant/billing/gateways/psigate.rb +29 -29
  193. data/lib/active_merchant/billing/gateways/psl_card.rb +7 -8
  194. data/lib/active_merchant/billing/gateways/qbms.rb +25 -26
  195. data/lib/active_merchant/billing/gateways/quantum.rb +9 -11
  196. data/lib/active_merchant/billing/gateways/quickbooks.rb +126 -39
  197. data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +98 -98
  198. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +19 -23
  199. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +3 -3
  200. data/lib/active_merchant/billing/gateways/quickpay.rb +0 -1
  201. data/lib/active_merchant/billing/gateways/qvalent.rb +36 -20
  202. data/lib/active_merchant/billing/gateways/rapyd.rb +319 -0
  203. data/lib/active_merchant/billing/gateways/reach.rb +277 -0
  204. data/lib/active_merchant/billing/gateways/realex.rb +42 -16
  205. data/lib/active_merchant/billing/gateways/redsys.rb +191 -86
  206. data/lib/active_merchant/billing/gateways/s5.rb +10 -9
  207. data/lib/active_merchant/billing/gateways/safe_charge.rb +70 -33
  208. data/lib/active_merchant/billing/gateways/sage.rb +19 -21
  209. data/lib/active_merchant/billing/gateways/sage_pay.rb +57 -57
  210. data/lib/active_merchant/billing/gateways/sallie_mae.rb +3 -4
  211. data/lib/active_merchant/billing/gateways/secure_net.rb +19 -26
  212. data/lib/active_merchant/billing/gateways/secure_pay.rb +24 -33
  213. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +18 -20
  214. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +4 -5
  215. data/lib/active_merchant/billing/gateways/securion_pay.rb +48 -7
  216. data/lib/active_merchant/billing/gateways/shift4.rb +345 -0
  217. data/lib/active_merchant/billing/gateways/simetrik.rb +368 -0
  218. data/lib/active_merchant/billing/gateways/skip_jack.rb +19 -19
  219. data/lib/active_merchant/billing/gateways/smart_ps.rb +26 -32
  220. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +24 -25
  221. data/lib/active_merchant/billing/gateways/spreedly_core.rb +27 -21
  222. data/lib/active_merchant/billing/gateways/stripe.rb +126 -53
  223. data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +441 -113
  224. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +7 -8
  225. data/lib/active_merchant/billing/gateways/telr.rb +17 -18
  226. data/lib/active_merchant/billing/gateways/tns.rb +3 -7
  227. data/lib/active_merchant/billing/gateways/trans_first.rb +10 -9
  228. data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +28 -24
  229. data/lib/active_merchant/billing/gateways/transact_pro.rb +13 -15
  230. data/lib/active_merchant/billing/gateways/transax.rb +1 -2
  231. data/lib/active_merchant/billing/gateways/trexle.rb +5 -2
  232. data/lib/active_merchant/billing/gateways/trust_commerce.rb +57 -47
  233. data/lib/active_merchant/billing/gateways/usa_epay.rb +1 -2
  234. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +176 -184
  235. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +60 -48
  236. data/lib/active_merchant/billing/gateways/vanco.rb +17 -8
  237. data/lib/active_merchant/billing/gateways/verifi.rb +13 -14
  238. data/lib/active_merchant/billing/gateways/viaklix.rb +9 -14
  239. data/lib/active_merchant/billing/gateways/visanet_peru.rb +26 -21
  240. data/lib/active_merchant/billing/gateways/vpos.rb +223 -0
  241. data/lib/active_merchant/billing/gateways/webpay.rb +4 -4
  242. data/lib/active_merchant/billing/gateways/wepay.rb +14 -16
  243. data/lib/active_merchant/billing/gateways/wirecard.rb +14 -16
  244. data/lib/active_merchant/billing/gateways/wompi.rb +197 -0
  245. data/lib/active_merchant/billing/gateways/world_net.rb +36 -35
  246. data/lib/active_merchant/billing/gateways/worldpay.rb +556 -190
  247. data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +47 -54
  248. data/lib/active_merchant/billing/gateways/worldpay_us.rb +16 -16
  249. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +2 -2
  250. data/lib/active_merchant/billing/response.rb +25 -6
  251. data/lib/active_merchant/billing/three_d_secure_eci_mapper.rb +27 -0
  252. data/lib/active_merchant/billing.rb +1 -0
  253. data/lib/active_merchant/connection.rb +14 -15
  254. data/lib/active_merchant/country.rb +3 -1
  255. data/lib/active_merchant/errors.rb +4 -1
  256. data/lib/active_merchant/net_http_ssl_connection.rb +1 -0
  257. data/lib/active_merchant/network_connection_retries.rb +15 -17
  258. data/lib/active_merchant/post_data.rb +3 -2
  259. data/lib/active_merchant/posts_data.rb +2 -2
  260. data/lib/active_merchant/version.rb +1 -1
  261. data/lib/active_merchant.rb +2 -2
  262. data/lib/certs/cacert.pem +1587 -2361
  263. data/lib/support/gateway_support.rb +1 -1
  264. data/lib/support/ssl_verify.rb +3 -7
  265. data/lib/support/ssl_version.rb +2 -3
  266. metadata +86 -34
  267. data/lib/active_merchant/billing/gateways/moneris_us.rb +0 -352
@@ -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
@@ -0,0 +1,277 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class ReachGateway < Gateway
4
+ self.test_url = 'https://checkout.rch.how/'
5
+ self.live_url = 'https://checkout.rch.io/'
6
+
7
+ self.supported_countries = ['US']
8
+ self.default_currency = 'USD'
9
+ self.supported_cardtypes = %i[visa diners_club american_express jcb master discover maestro]
10
+
11
+ self.homepage_url = 'https://www.withreach.com/'
12
+ self.display_name = 'Reach'
13
+ self.currencies_without_fractions = %w(BIF BYR CLF CLP CVE DJF GNF ISK JPY KMF KRW PYG RWF UGX UYI VND VUV XAF XOF XPF IDR MGA MRO)
14
+
15
+ API_VERSION = 'v2.22'.freeze
16
+ STANDARD_ERROR_CODE_MAPPING = {}
17
+ PAYMENT_METHOD_MAP = {
18
+ american_express: 'AMEX',
19
+ cabal: 'CABAL',
20
+ check: 'ACH',
21
+ dankort: 'DANKORT',
22
+ diners_club: 'DINERS',
23
+ discover: 'DISC',
24
+ elo: 'ELO',
25
+ jcb: 'JCB',
26
+ maestro: 'MAESTRO',
27
+ master: 'MC',
28
+ naranja: 'NARANJA',
29
+ union_pay: 'UNIONPAY',
30
+ visa: 'VISA'
31
+ }
32
+
33
+ def initialize(options = {})
34
+ requires!(options, :merchant_id, :secret)
35
+ super
36
+ end
37
+
38
+ def authorize(money, payment, options = {})
39
+ request = build_checkout_request(money, payment, options)
40
+ add_custom_fields_data(request, options)
41
+ add_customer_data(request, options, payment)
42
+ add_stored_credentials(request, options)
43
+ post = { request: request, card: add_payment(payment, options) }
44
+ if options[:stored_credential]
45
+ MultiResponse.run(:use_first_response) do |r|
46
+ r.process { commit('checkout', post) }
47
+ r.process do
48
+ r2 = get_network_payment_reference(r.responses[0])
49
+ r.params[:network_transaction_id] = r2.message
50
+ r2
51
+ end
52
+ end
53
+ else
54
+ commit('checkout', post)
55
+ end
56
+ end
57
+
58
+ def purchase(money, payment, options = {})
59
+ options[:capture] = true
60
+ authorize(money, payment, options)
61
+ end
62
+
63
+ def capture(money, authorization, options = {})
64
+ post = { request: { MerchantId: @options[:merchant_id], OrderId: authorization } }
65
+ commit('capture', post)
66
+ end
67
+
68
+ def supports_scrubbing?
69
+ true
70
+ end
71
+
72
+ def scrub(transcript)
73
+ transcript.
74
+ gsub(%r(((MerchantId)[% \w]+[%]\d{2})[\w -]+), '\1[FILTERED]').
75
+ gsub(%r((signature=)[\w%]+), '\1[FILTERED]\2').
76
+ gsub(%r((Number%22%3A%22)[\d]+), '\1[FILTERED]\2').
77
+ gsub(%r((VerificationCode%22%3A)[\d]+), '\1[FILTERED]\2')
78
+ end
79
+
80
+ def refund(amount, authorization, options = {})
81
+ currency = options[:currency] || currency(options[:amount])
82
+ post = {
83
+ request: {
84
+ MerchantId: @options[:merchant_id],
85
+ OrderId: authorization,
86
+ ReferenceId: options[:order_id] || options[:reference_id],
87
+ Amount: localized_amount(amount, currency)
88
+ }
89
+ }
90
+ commit('refund', post)
91
+ end
92
+
93
+ def void(authorization, options = {})
94
+ post = {
95
+ request: {
96
+ MerchantId: @options[:merchant_id],
97
+ OrderId: authorization
98
+ }
99
+ }
100
+
101
+ commit('cancel', post)
102
+ end
103
+
104
+ def verify(credit_card, options = {})
105
+ MultiResponse.run(:use_first_response) do |r|
106
+ r.process { authorize(100, credit_card, options) }
107
+ r.process(:ignore_result) { void(r.authorization, options) }
108
+ end
109
+ end
110
+
111
+ private
112
+
113
+ def build_checkout_request(amount, payment, options)
114
+ currency = options[:currency] || currency(options[:amount])
115
+ {
116
+ MerchantId: @options[:merchant_id],
117
+ ReferenceId: options[:order_id],
118
+ ConsumerCurrency: currency,
119
+ Capture: options[:capture] || false,
120
+ PaymentMethod: PAYMENT_METHOD_MAP.fetch(payment.brand.to_sym, 'unsupported'),
121
+ Items: [
122
+ Sku: options[:item_sku] || SecureRandom.alphanumeric,
123
+ ConsumerPrice: localized_amount(amount, currency),
124
+ Quantity: (options[:item_quantity] || 1)
125
+ ]
126
+ }
127
+ end
128
+
129
+ def add_payment(payment, options)
130
+ ntid = options.dig(:stored_credential, :network_transaction_id)
131
+ cvv_or_previos_reference = (ntid ? { PreviousNetworkPaymentReference: ntid } : { VerificationCode: payment.verification_value })
132
+ {
133
+ Name: payment.name,
134
+ Number: payment.number,
135
+ Expiry: { Month: payment.month, Year: payment.year }
136
+ }.merge!(cvv_or_previos_reference)
137
+ end
138
+
139
+ def add_customer_data(request, options, payment)
140
+ address = options[:billing_address] || options[:address]
141
+
142
+ return if address.blank?
143
+
144
+ request[:Consumer] = {
145
+ Name: payment.respond_to?(:name) ? payment.name : address[:name],
146
+ Email: options[:email],
147
+ Address: address[:address1],
148
+ City: address[:city],
149
+ Country: address[:country]
150
+ }.compact
151
+ end
152
+
153
+ def add_stored_credentials(request, options)
154
+ request[:PaymentModel] = payment_model(options) || ''
155
+ request[:DeviceFingerprint] = options[:device_fingerprint] if options[:device_fingerprint]
156
+ end
157
+
158
+ def payment_model(options)
159
+ stored_credential = options[:stored_credential]
160
+ return options[:payment_model] if options[:payment_model]
161
+ return 'CIT-One-Time' unless stored_credential
162
+
163
+ payment_model_options = {
164
+ initial_transaction: {
165
+ 'cardholder' => {
166
+ 'installment' => 'CIT-Setup-Scheduled',
167
+ 'unscheduled' => 'CIT-Setup-Unscheduled-MIT',
168
+ 'recurring' => 'CIT-Setup-Unscheduled'
169
+ }
170
+ },
171
+ no_initial_transaction: {
172
+ 'cardholder' => {
173
+ 'unscheduled' => 'CIT-Subsequent-Unscheduled'
174
+ },
175
+ 'merchant' => {
176
+ 'recurring' => 'MIT-Subsequent-Scheduled',
177
+ 'unscheduled' => 'MIT-Subsequent-Unscheduled'
178
+ }
179
+ }
180
+ }
181
+ initial = stored_credential[:initial_transaction] ? :initial_transaction : :no_initial_transaction
182
+ payment_model_options[initial].dig(stored_credential[:initiator], stored_credential[:reason_type])
183
+ end
184
+
185
+ def add_custom_fields_data(request, options)
186
+ add_shipping_data(request, options) if options[:taxes].present?
187
+ request[:RateOfferId] = options[:rate_offer_id] if options[:rate_offer_id].present?
188
+ request[:Items] = options[:items] if options[:items].present?
189
+ end
190
+
191
+ def add_shipping_data(request, options)
192
+ request[:Shipping] = {
193
+ ConsumerPrice: options[:price],
194
+ ConsumerTaxes: options[:taxes],
195
+ ConsumerDuty: options[:duty]
196
+ }
197
+ request[:Consignee] = {
198
+ Name: options[:consignee_name],
199
+ Address: options[:consignee_address],
200
+ City: options[:consignee_city],
201
+ Country: options[:consignee_country]
202
+ }
203
+ end
204
+
205
+ def sign_body(body)
206
+ Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', @options[:secret].encode('utf-8'), body.encode('utf-8')))
207
+ end
208
+
209
+ def parse(body)
210
+ hash_response = URI.decode_www_form(body).to_h
211
+ hash_response['response'] = JSON.parse(hash_response['response'])
212
+
213
+ hash_response
214
+ end
215
+
216
+ def format_and_sign(post)
217
+ post[:request] = post[:request].to_json
218
+ post[:card] = post[:card].to_json if post[:card].present?
219
+ post[:signature] = sign_body(post[:request])
220
+ post
221
+ end
222
+
223
+ def get_network_payment_reference(response)
224
+ parameters = { request: { MerchantId: @options[:merchant_id], OrderId: response.params['response']['OrderId'] } }
225
+ body = post_data format_and_sign(parameters)
226
+
227
+ raw_response = ssl_request :post, url('query'), body, {}
228
+ response = parse(raw_response)
229
+ message = response.dig('response', 'Payment', 'NetworkPaymentReference')
230
+ Response.new(true, message, {})
231
+ end
232
+
233
+ def commit(action, parameters)
234
+ body = post_data format_and_sign(parameters)
235
+ raw_response = ssl_post url(action), body
236
+ response = parse(raw_response)
237
+
238
+ Response.new(
239
+ success_from(response),
240
+ message_from(response) || '',
241
+ response,
242
+ authorization: authorization_from(response['response']),
243
+ # avs_result: AVSResult.new(code: response['some_avs_response_key']),
244
+ # cvv_result: CVVResult.new(response['some_cvv_response_key']),
245
+ test: test?,
246
+ error_code: error_code_from(response)
247
+ )
248
+ rescue ActiveMerchant::ResponseError => e
249
+ Response.new(false, (e.response.body.present? ? e.response.body : e.response.msg), {}, test: test?)
250
+ end
251
+
252
+ def success_from(response)
253
+ response.dig('response', 'Error').blank?
254
+ end
255
+
256
+ def message_from(response)
257
+ success_from(response) ? '' : response.dig('response', 'Error', 'ReasonCode')
258
+ end
259
+
260
+ def authorization_from(response)
261
+ response['OrderId']
262
+ end
263
+
264
+ def post_data(params)
265
+ params.map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&')
266
+ end
267
+
268
+ def error_code_from(response)
269
+ response['response']['Error']['Code'] unless success_from(response)
270
+ end
271
+
272
+ def url(action)
273
+ "#{test? ? test_url : live_url}#{API_VERSION}/#{action}"
274
+ end
275
+ end
276
+ end
277
+ end