activemerchant 1.133.0 → 1.138.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +450 -0
  3. data/CONTRIBUTORS +1 -0
  4. data/lib/active_merchant/billing/apple_pay_payment_token.rb +2 -2
  5. data/lib/active_merchant/billing/base.rb +2 -2
  6. data/lib/active_merchant/billing/check.rb +16 -4
  7. data/lib/active_merchant/billing/compatibility.rb +4 -4
  8. data/lib/active_merchant/billing/credit_card.rb +35 -16
  9. data/lib/active_merchant/billing/credit_card_formatting.rb +13 -2
  10. data/lib/active_merchant/billing/credit_card_methods.rb +74 -19
  11. data/lib/active_merchant/billing/gateway.rb +22 -2
  12. data/lib/active_merchant/billing/gateways/adyen.rb +282 -87
  13. data/lib/active_merchant/billing/gateways/airwallex.rb +46 -25
  14. data/lib/active_merchant/billing/gateways/alelo.rb +29 -11
  15. data/lib/active_merchant/billing/gateways/allied_wallet.rb +2 -2
  16. data/lib/active_merchant/billing/gateways/authorize_net.rb +49 -41
  17. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +14 -10
  18. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +3 -5
  19. data/lib/active_merchant/billing/gateways/axcessms.rb +9 -5
  20. data/lib/active_merchant/billing/gateways/balanced.rb +2 -2
  21. data/lib/active_merchant/billing/gateways/bambora_apac.rb +2 -2
  22. data/lib/active_merchant/billing/gateways/bank_frick.rb +2 -2
  23. data/lib/active_merchant/billing/gateways/banwire.rb +6 -4
  24. data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +8 -8
  25. data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +2 -2
  26. data/lib/active_merchant/billing/gateways/be2bill.rb +2 -2
  27. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +12 -8
  28. data/lib/active_merchant/billing/gateways/beanstream.rb +2 -2
  29. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +2 -2
  30. data/lib/active_merchant/billing/gateways/blue_pay.rb +15 -7
  31. data/lib/active_merchant/billing/gateways/blue_snap.rb +5 -5
  32. data/lib/active_merchant/billing/gateways/bogus.rb +2 -2
  33. data/lib/active_merchant/billing/gateways/borgun.rb +2 -2
  34. data/lib/active_merchant/billing/gateways/bpoint.rb +2 -2
  35. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +3 -1
  36. data/lib/active_merchant/billing/gateways/braintree/token_nonce.rb +68 -23
  37. data/lib/active_merchant/billing/gateways/braintree.rb +2 -2
  38. data/lib/active_merchant/billing/gateways/braintree_blue.rb +266 -89
  39. data/lib/active_merchant/billing/gateways/braintree_orange.rb +3 -3
  40. data/lib/active_merchant/billing/gateways/bridge_pay.rb +2 -2
  41. data/lib/active_merchant/billing/gateways/cams.rb +2 -2
  42. data/lib/active_merchant/billing/gateways/card_connect.rb +7 -4
  43. data/lib/active_merchant/billing/gateways/card_save.rb +2 -2
  44. data/lib/active_merchant/billing/gateways/card_stream.rb +12 -13
  45. data/lib/active_merchant/billing/gateways/cardknox.rb +2 -2
  46. data/lib/active_merchant/billing/gateways/cardprocess.rb +2 -2
  47. data/lib/active_merchant/billing/gateways/cashnet.rb +4 -4
  48. data/lib/active_merchant/billing/gateways/cc5.rb +2 -2
  49. data/lib/active_merchant/billing/gateways/cecabank/cecabank_common.rb +36 -0
  50. data/lib/active_merchant/billing/gateways/cecabank/cecabank_json.rb +331 -0
  51. data/lib/active_merchant/billing/gateways/cecabank/cecabank_xml.rb +220 -0
  52. data/lib/active_merchant/billing/gateways/cecabank.rb +9 -242
  53. data/lib/active_merchant/billing/gateways/cenpos.rb +9 -3
  54. data/lib/active_merchant/billing/gateways/checkout.rb +5 -5
  55. data/lib/active_merchant/billing/gateways/checkout_v2.rb +362 -50
  56. data/lib/active_merchant/billing/gateways/clearhaus.rb +2 -2
  57. data/lib/active_merchant/billing/gateways/commerce_hub.rb +117 -35
  58. data/lib/active_merchant/billing/gateways/commercegate.rb +4 -4
  59. data/lib/active_merchant/billing/gateways/conekta.rb +2 -2
  60. data/lib/active_merchant/billing/gateways/creditcall.rb +2 -2
  61. data/lib/active_merchant/billing/gateways/credorax.rb +109 -20
  62. data/lib/active_merchant/billing/gateways/ct_payment.rb +6 -6
  63. data/lib/active_merchant/billing/gateways/culqi.rb +2 -2
  64. data/lib/active_merchant/billing/gateways/cyber_source/cyber_source_common.rb +2 -2
  65. data/lib/active_merchant/billing/gateways/cyber_source.rb +379 -100
  66. data/lib/active_merchant/billing/gateways/cyber_source_rest.rb +147 -76
  67. data/lib/active_merchant/billing/gateways/d_local.rb +45 -22
  68. data/lib/active_merchant/billing/gateways/data_cash.rb +22 -18
  69. data/lib/active_merchant/billing/gateways/datatrans.rb +284 -0
  70. data/lib/active_merchant/billing/gateways/decidir.rb +82 -46
  71. data/lib/active_merchant/billing/gateways/decidir_plus.rb +31 -35
  72. data/lib/active_merchant/billing/gateways/deepstack.rb +382 -0
  73. data/lib/active_merchant/billing/gateways/dibs.rb +3 -3
  74. data/lib/active_merchant/billing/gateways/digitzs.rb +2 -2
  75. data/lib/active_merchant/billing/gateways/ebanx.rb +116 -68
  76. data/lib/active_merchant/billing/gateways/efsnet.rb +13 -8
  77. data/lib/active_merchant/billing/gateways/elavon.rb +80 -47
  78. data/lib/active_merchant/billing/gateways/element.rb +39 -10
  79. data/lib/active_merchant/billing/gateways/epay.rb +8 -4
  80. data/lib/active_merchant/billing/gateways/evo_ca.rb +8 -4
  81. data/lib/active_merchant/billing/gateways/eway.rb +6 -4
  82. data/lib/active_merchant/billing/gateways/eway_managed.rb +8 -4
  83. data/lib/active_merchant/billing/gateways/eway_rapid.rb +3 -3
  84. data/lib/active_merchant/billing/gateways/exact.rb +8 -4
  85. data/lib/active_merchant/billing/gateways/fat_zebra.rb +37 -7
  86. data/lib/active_merchant/billing/gateways/federated_canada.rb +8 -4
  87. data/lib/active_merchant/billing/gateways/finansbank.rb +2 -2
  88. data/lib/active_merchant/billing/gateways/first_giving.rb +2 -2
  89. data/lib/active_merchant/billing/gateways/first_pay/first_pay_common.rb +15 -0
  90. data/lib/active_merchant/billing/gateways/first_pay/first_pay_json.rb +190 -0
  91. data/lib/active_merchant/billing/gateways/first_pay/first_pay_xml.rb +183 -0
  92. data/lib/active_merchant/billing/gateways/first_pay.rb +8 -174
  93. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +8 -4
  94. data/lib/active_merchant/billing/gateways/firstdata_e4_v27.rb +9 -5
  95. data/lib/active_merchant/billing/gateways/flex_charge.rb +359 -0
  96. data/lib/active_merchant/billing/gateways/flo2cash.rb +4 -2
  97. data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +2 -2
  98. data/lib/active_merchant/billing/gateways/forte.rb +6 -4
  99. data/lib/active_merchant/billing/gateways/fortis.rb +347 -0
  100. data/lib/active_merchant/billing/gateways/garanti.rb +6 -4
  101. data/lib/active_merchant/billing/gateways/global_collect.rb +69 -50
  102. data/lib/active_merchant/billing/gateways/global_transport.rb +2 -2
  103. data/lib/active_merchant/billing/gateways/hdfc.rb +2 -2
  104. data/lib/active_merchant/billing/gateways/hi_pay.rb +287 -0
  105. data/lib/active_merchant/billing/gateways/hps.rb +40 -47
  106. data/lib/active_merchant/billing/gateways/iats_payments.rb +9 -4
  107. data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +2 -2
  108. data/lib/active_merchant/billing/gateways/inspire.rb +8 -6
  109. data/lib/active_merchant/billing/gateways/instapay.rb +9 -6
  110. data/lib/active_merchant/billing/gateways/ipg.rb +14 -10
  111. data/lib/active_merchant/billing/gateways/ipp.rb +2 -2
  112. data/lib/active_merchant/billing/gateways/iridium.rb +18 -8
  113. data/lib/active_merchant/billing/gateways/itransact.rb +8 -4
  114. data/lib/active_merchant/billing/gateways/iveri.rb +12 -9
  115. data/lib/active_merchant/billing/gateways/ixopay.rb +4 -4
  116. data/lib/active_merchant/billing/gateways/jetpay.rb +6 -4
  117. data/lib/active_merchant/billing/gateways/jetpay_v2.rb +9 -6
  118. data/lib/active_merchant/billing/gateways/komoju.rb +2 -2
  119. data/lib/active_merchant/billing/gateways/kushki.rb +79 -16
  120. data/lib/active_merchant/billing/gateways/latitude19.rb +2 -2
  121. data/lib/active_merchant/billing/gateways/linkpoint.rb +8 -4
  122. data/lib/active_merchant/billing/gateways/litle.rb +37 -54
  123. data/lib/active_merchant/billing/gateways/loan_payment_pro.rb +267 -0
  124. data/lib/active_merchant/billing/gateways/loan_payment_pro_ach.rb +93 -0
  125. data/lib/active_merchant/billing/gateways/mastercard.rb +4 -4
  126. data/lib/active_merchant/billing/gateways/maxipago.rb +4 -4
  127. data/lib/active_merchant/billing/gateways/mercado_pago.rb +32 -11
  128. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +10 -7
  129. data/lib/active_merchant/billing/gateways/merchant_one.rb +2 -2
  130. data/lib/active_merchant/billing/gateways/merchant_partners.rb +2 -2
  131. data/lib/active_merchant/billing/gateways/merchant_ware.rb +13 -6
  132. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +13 -6
  133. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +21 -5
  134. data/lib/active_merchant/billing/gateways/mercury.rb +11 -5
  135. data/lib/active_merchant/billing/gateways/metrics_global.rb +10 -8
  136. data/lib/active_merchant/billing/gateways/micropayment.rb +2 -2
  137. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +7 -6
  138. data/lib/active_merchant/billing/gateways/migs.rb +8 -4
  139. data/lib/active_merchant/billing/gateways/mit.rb +10 -5
  140. data/lib/active_merchant/billing/gateways/modern_payments.rb +2 -2
  141. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +21 -13
  142. data/lib/active_merchant/billing/gateways/moka.rb +2 -2
  143. data/lib/active_merchant/billing/gateways/monei.rb +3 -3
  144. data/lib/active_merchant/billing/gateways/moneris.rb +11 -5
  145. data/lib/active_merchant/billing/gateways/money_movers.rb +8 -4
  146. data/lib/active_merchant/billing/gateways/multi_pay.rb +267 -0
  147. data/lib/active_merchant/billing/gateways/mundipagg.rb +5 -3
  148. data/lib/active_merchant/billing/gateways/nab_transact.rb +18 -10
  149. data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +2 -2
  150. data/lib/active_merchant/billing/gateways/net_registry.rb +6 -2
  151. data/lib/active_merchant/billing/gateways/netaxept.rb +4 -4
  152. data/lib/active_merchant/billing/gateways/netbanx.rb +4 -6
  153. data/lib/active_merchant/billing/gateways/netbilling.rb +8 -4
  154. data/lib/active_merchant/billing/gateways/netpay.rb +2 -2
  155. data/lib/active_merchant/billing/gateways/network_merchants.rb +9 -5
  156. data/lib/active_merchant/billing/gateways/nmi.rb +29 -8
  157. data/lib/active_merchant/billing/gateways/nuvei.rb +573 -0
  158. data/lib/active_merchant/billing/gateways/ogone.rb +8 -4
  159. data/lib/active_merchant/billing/gateways/omise.rb +2 -2
  160. data/lib/active_merchant/billing/gateways/openpay.rb +6 -4
  161. data/lib/active_merchant/billing/gateways/opp.rb +3 -4
  162. data/lib/active_merchant/billing/gateways/optimal_payment.rb +12 -6
  163. data/lib/active_merchant/billing/gateways/orbital/orbital_codes.rb +273 -0
  164. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +3 -5
  165. data/lib/active_merchant/billing/gateways/orbital.rb +114 -94
  166. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +9 -6
  167. data/lib/active_merchant/billing/gateways/pagarme.rb +2 -2
  168. data/lib/active_merchant/billing/gateways/pago_facil.rb +2 -2
  169. data/lib/active_merchant/billing/gateways/pay_arc.rb +9 -7
  170. data/lib/active_merchant/billing/gateways/pay_conex.rb +6 -4
  171. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +8 -4
  172. data/lib/active_merchant/billing/gateways/pay_hub.rb +7 -5
  173. data/lib/active_merchant/billing/gateways/pay_junction.rb +8 -4
  174. data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +2 -2
  175. data/lib/active_merchant/billing/gateways/pay_secure.rb +8 -4
  176. data/lib/active_merchant/billing/gateways/pay_trace.rb +36 -22
  177. data/lib/active_merchant/billing/gateways/paybox_direct.rb +14 -14
  178. data/lib/active_merchant/billing/gateways/payeezy.rb +26 -13
  179. data/lib/active_merchant/billing/gateways/payex.rb +8 -6
  180. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +3 -3
  181. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +2 -2
  182. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +2 -2
  183. data/lib/active_merchant/billing/gateways/payflow.rb +12 -11
  184. data/lib/active_merchant/billing/gateways/payflow_express.rb +2 -2
  185. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +2 -2
  186. data/lib/active_merchant/billing/gateways/payflow_uk.rb +2 -2
  187. data/lib/active_merchant/billing/gateways/payment_express.rb +10 -6
  188. data/lib/active_merchant/billing/gateways/paymentez.rb +30 -16
  189. data/lib/active_merchant/billing/gateways/paymill.rb +6 -4
  190. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +17 -12
  191. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +2 -2
  192. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +2 -2
  193. data/lib/active_merchant/billing/gateways/paypal.rb +4 -2
  194. data/lib/active_merchant/billing/gateways/paypal_ca.rb +2 -2
  195. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +2 -2
  196. data/lib/active_merchant/billing/gateways/paypal_express.rb +4 -2
  197. data/lib/active_merchant/billing/gateways/paysafe.rb +48 -24
  198. data/lib/active_merchant/billing/gateways/payscout.rb +9 -6
  199. data/lib/active_merchant/billing/gateways/paystation.rb +9 -5
  200. data/lib/active_merchant/billing/gateways/payu_in.rb +2 -2
  201. data/lib/active_merchant/billing/gateways/payu_latam.rb +7 -5
  202. data/lib/active_merchant/billing/gateways/payway.rb +6 -2
  203. data/lib/active_merchant/billing/gateways/payway_dot_com.rb +6 -6
  204. data/lib/active_merchant/billing/gateways/pin.rb +126 -41
  205. data/lib/active_merchant/billing/gateways/plexo.rb +71 -20
  206. data/lib/active_merchant/billing/gateways/plugnpay.rb +6 -2
  207. data/lib/active_merchant/billing/gateways/priority.rb +29 -24
  208. data/lib/active_merchant/billing/gateways/pro_pay.rb +2 -2
  209. data/lib/active_merchant/billing/gateways/psigate.rb +8 -4
  210. data/lib/active_merchant/billing/gateways/psl_card.rb +6 -2
  211. data/lib/active_merchant/billing/gateways/qbms.rb +9 -5
  212. data/lib/active_merchant/billing/gateways/quantum.rb +9 -5
  213. data/lib/active_merchant/billing/gateways/quickbooks.rb +27 -17
  214. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +7 -4
  215. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +8 -4
  216. data/lib/active_merchant/billing/gateways/quickpay.rb +2 -2
  217. data/lib/active_merchant/billing/gateways/qvalent.rb +2 -2
  218. data/lib/active_merchant/billing/gateways/rapyd.rb +172 -53
  219. data/lib/active_merchant/billing/gateways/reach.rb +16 -9
  220. data/lib/active_merchant/billing/gateways/redsys.rb +7 -15
  221. data/lib/active_merchant/billing/gateways/redsys_rest.rb +545 -0
  222. data/lib/active_merchant/billing/gateways/s5.rb +5 -5
  223. data/lib/active_merchant/billing/gateways/safe_charge.rb +47 -24
  224. data/lib/active_merchant/billing/gateways/sage.rb +14 -6
  225. data/lib/active_merchant/billing/gateways/sage_pay.rb +81 -7
  226. data/lib/active_merchant/billing/gateways/sallie_mae.rb +8 -4
  227. data/lib/active_merchant/billing/gateways/secure_net.rb +9 -5
  228. data/lib/active_merchant/billing/gateways/secure_pay.rb +10 -8
  229. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +25 -15
  230. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +8 -4
  231. data/lib/active_merchant/billing/gateways/securion_pay.rb +26 -12
  232. data/lib/active_merchant/billing/gateways/shift4.rb +34 -26
  233. data/lib/active_merchant/billing/gateways/shift4_v2.rb +117 -0
  234. data/lib/active_merchant/billing/gateways/simetrik.rb +26 -17
  235. data/lib/active_merchant/billing/gateways/skip_jack.rb +8 -4
  236. data/lib/active_merchant/billing/gateways/smart_ps.rb +10 -7
  237. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +6 -4
  238. data/lib/active_merchant/billing/gateways/spreedly_core.rb +4 -6
  239. data/lib/active_merchant/billing/gateways/stripe.rb +88 -84
  240. data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +388 -77
  241. data/lib/active_merchant/billing/gateways/sum_up.rb +224 -0
  242. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +6 -4
  243. data/lib/active_merchant/billing/gateways/telr.rb +6 -7
  244. data/lib/active_merchant/billing/gateways/trans_first.rb +6 -4
  245. data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +10 -18
  246. data/lib/active_merchant/billing/gateways/transact_pro.rb +3 -3
  247. data/lib/active_merchant/billing/gateways/transax.rb +2 -2
  248. data/lib/active_merchant/billing/gateways/transnational.rb +2 -2
  249. data/lib/active_merchant/billing/gateways/trexle.rb +2 -2
  250. data/lib/active_merchant/billing/gateways/trust_commerce.rb +9 -5
  251. data/lib/active_merchant/billing/gateways/usa_epay.rb +2 -2
  252. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +32 -31
  253. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +8 -4
  254. data/lib/active_merchant/billing/gateways/vanco.rb +2 -4
  255. data/lib/active_merchant/billing/gateways/vantiv_express.rb +668 -0
  256. data/lib/active_merchant/billing/gateways/verifi.rb +12 -8
  257. data/lib/active_merchant/billing/gateways/versa_pay.rb +307 -0
  258. data/lib/active_merchant/billing/gateways/viaklix.rb +8 -4
  259. data/lib/active_merchant/billing/gateways/visanet_peru.rb +5 -5
  260. data/lib/active_merchant/billing/gateways/vpos.rb +25 -13
  261. data/lib/active_merchant/billing/gateways/webpay.rb +3 -3
  262. data/lib/active_merchant/billing/gateways/wepay.rb +6 -4
  263. data/lib/active_merchant/billing/gateways/wirecard.rb +10 -6
  264. data/lib/active_merchant/billing/gateways/wompi.rb +14 -7
  265. data/lib/active_merchant/billing/gateways/world_net.rb +2 -2
  266. data/lib/active_merchant/billing/gateways/worldpay.rb +297 -113
  267. data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +16 -13
  268. data/lib/active_merchant/billing/gateways/worldpay_us.rb +2 -2
  269. data/lib/active_merchant/billing/gateways/xpay.rb +244 -0
  270. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +15 -3
  271. data/lib/active_merchant/billing/payment_token.rb +2 -2
  272. data/lib/active_merchant/billing/response.rb +7 -6
  273. data/lib/active_merchant/billing.rb +1 -0
  274. data/lib/active_merchant/connection.rb +8 -20
  275. data/lib/active_merchant/country.rb +3 -1
  276. data/lib/active_merchant/errors.rb +12 -2
  277. data/lib/active_merchant/net_http_ssl_connection.rb +35 -0
  278. data/lib/active_merchant/posts_data.rb +19 -4
  279. data/lib/active_merchant/version.rb +1 -1
  280. data/lib/active_merchant/versionable.rb +29 -0
  281. data/lib/certs/cacert.pem +1326 -1491
  282. data/lib/support/gateway_support.rb +3 -3
  283. data/lib/support/ssl_verify.rb +6 -6
  284. data/lib/support/ssl_version.rb +8 -8
  285. metadata +35 -9
@@ -1,5 +1,5 @@
1
- module ActiveMerchant #:nodoc:
2
- module Billing #:nodoc:
1
+ module ActiveMerchant # :nodoc:
2
+ module Billing # :nodoc:
3
3
  class CheckoutV2Gateway < Gateway
4
4
  self.display_name = 'Checkout.com Unified Payments'
5
5
  self.homepage_url = 'https://www.checkout.com/'
@@ -9,7 +9,7 @@ module ActiveMerchant #:nodoc:
9
9
  self.supported_countries = %w[AD AE AR AT AU BE BG BH BR CH CL CN CO CY CZ DE DK EE EG ES FI FR GB GR HK HR HU IE IS IT JO JP KW LI LT LU LV MC MT MX MY NL NO NZ OM PE PL PT QA RO SA SE SG SI SK SM TR US]
10
10
  self.default_currency = 'USD'
11
11
  self.money_format = :cents
12
- self.supported_cardtypes = %i[visa master american_express diners_club maestro discover jcb mada bp_plus]
12
+ self.supported_cardtypes = %i[visa master american_express diners_club maestro discover jcb mada bp_plus patagonia_365 tarjeta_sol]
13
13
  self.currencies_without_fractions = %w(BIF DJF GNF ISK KMF XAF CLF XPF JPY PYG RWF KRW VUV VND XOF)
14
14
  self.currencies_with_three_decimal_places = %w(BHD LYD JOD KWD OMR TND)
15
15
 
@@ -17,15 +17,7 @@ module ActiveMerchant #:nodoc:
17
17
  TEST_ACCESS_TOKEN_URL = 'https://access.sandbox.checkout.com/connect/token'
18
18
 
19
19
  def initialize(options = {})
20
- @options = options
21
- @access_token = nil
22
-
23
- if options.has_key?(:secret_key)
24
- requires!(options, :secret_key)
25
- else
26
- requires!(options, :client_id, :client_secret)
27
- @access_token = setup_access_token
28
- end
20
+ options.has_key?(:secret_key) ? requires!(options, :secret_key) : requires!(options, :client_id, :client_secret)
29
21
 
30
22
  super
31
23
  end
@@ -41,6 +33,7 @@ module ActiveMerchant #:nodoc:
41
33
  post = {}
42
34
  post[:capture] = false
43
35
  build_auth_or_purchase(post, amount, payment_method, options)
36
+
44
37
  options[:incremental_authorization] ? commit(:incremental_authorize, post, options, options[:incremental_authorization]) : commit(:authorize, post, options)
45
38
  end
46
39
 
@@ -51,23 +44,26 @@ module ActiveMerchant #:nodoc:
51
44
  add_customer_data(post, options)
52
45
  add_shipping_address(post, options)
53
46
  add_metadata(post, options)
47
+ add_level_two_three_data(post, options)
54
48
 
55
49
  commit(:capture, post, options, authorization)
56
50
  end
57
51
 
58
52
  def credit(amount, payment, options = {})
59
53
  post = {}
60
- post[:instruction] = {}
61
- post[:instruction][:funds_transfer_type] = options[:funds_transfer_type] || 'FD'
62
54
  add_processing_channel(post, options)
63
55
  add_invoice(post, amount, options)
64
56
  add_payment_method(post, payment, options, :destination)
65
57
  add_source(post, options)
58
+ add_instruction_data(post, options)
59
+ add_payout_sender_data(post, options)
60
+ add_payout_destination_data(post, options)
61
+ add_metadata(post, options)
66
62
 
67
63
  commit(:credit, post, options)
68
64
  end
69
65
 
70
- def void(authorization, _options = {})
66
+ def void(authorization, options = {})
71
67
  post = {}
72
68
  add_metadata(post, options)
73
69
 
@@ -87,7 +83,11 @@ module ActiveMerchant #:nodoc:
87
83
  authorize(0, credit_card, options)
88
84
  end
89
85
 
90
- def verify_payment(authorization, option = {})
86
+ def inquire(authorization, options = {})
87
+ verify_payment(authorization, {})
88
+ end
89
+
90
+ def verify_payment(authorization, options = {})
91
91
  commit(:verify_payment, nil, options, authorization, :get)
92
92
  end
93
93
 
@@ -102,7 +102,8 @@ module ActiveMerchant #:nodoc:
102
102
  gsub(/("cvv\\":\\")\d+/, '\1[FILTERED]').
103
103
  gsub(/("cryptogram\\":\\")\w+/, '\1[FILTERED]').
104
104
  gsub(/(source\\":\{.*\\"token\\":\\")\d+/, '\1[FILTERED]').
105
- gsub(/("token\\":\\")\w+/, '\1[FILTERED]')
105
+ gsub(/("token\\":\\")\w+/, '\1[FILTERED]').
106
+ gsub(/("access_token\\?"\s*:\s*\\?")[^"]*\w+/, '\1[FILTERED]')
106
107
  end
107
108
 
108
109
  def store(payment_method, options = {})
@@ -123,6 +124,7 @@ module ActiveMerchant #:nodoc:
123
124
  post.merge!(post.delete(:source))
124
125
  add_customer_data(post, options)
125
126
  add_shipping_address(post, options)
127
+ add_metadata(post, options)
126
128
  r.process { commit(:store, post, options) }
127
129
  end
128
130
  end
@@ -147,6 +149,14 @@ module ActiveMerchant #:nodoc:
147
149
  add_metadata(post, options, payment_method)
148
150
  add_processing_channel(post, options)
149
151
  add_marketplace_data(post, options)
152
+ add_account_name_inquiry(post, options)
153
+ add_recipient_data(post, options)
154
+ add_processing_data(post, options)
155
+ add_payment_sender_data(post, options)
156
+ add_risk_data(post, options)
157
+ add_level_two_three_data(post, options)
158
+ truncate_amex_reference_id(post, options, payment_method)
159
+ add_partial_authorization(post, options)
150
160
  end
151
161
 
152
162
  def add_invoice(post, money, options)
@@ -158,8 +168,111 @@ module ActiveMerchant #:nodoc:
158
168
  post[:billing_descriptor][:name] = options[:descriptor_name] if options[:descriptor_name]
159
169
  post[:billing_descriptor][:city] = options[:descriptor_city] if options[:descriptor_city]
160
170
  end
161
- post[:metadata] = {}
162
- post[:metadata][:udf5] = application_id || 'ActiveMerchant'
171
+ end
172
+
173
+ def truncate_amex_reference_id(post, options, payment_method)
174
+ post[:reference] = truncate(options[:order_id], 30) if payment_method.respond_to?(:brand) && payment_method.brand == 'american_express'
175
+ end
176
+
177
+ def add_account_name_inquiry(post, options)
178
+ return unless options[:account_name_inquiry] && options[:account_holder]&.is_a?(Hash)
179
+
180
+ account_holder = options[:account_holder]
181
+
182
+ post[:source][:account_holder] = {}
183
+ %i[first_name middle_name last_name type company_name].each do |key|
184
+ post[:source][:account_holder][key] = account_holder[key] if account_holder[key]
185
+ end
186
+ post[:source][:account_holder][:account_name_inquiry] = true
187
+ end
188
+
189
+ def add_recipient_data(post, options)
190
+ return unless options[:recipient].is_a?(Hash)
191
+
192
+ recipient = options[:recipient]
193
+
194
+ post[:recipient] = {}
195
+ post[:recipient][:dob] = recipient[:dob] if recipient[:dob]
196
+ post[:recipient][:zip] = recipient[:zip] if recipient[:zip]
197
+ post[:recipient][:account_number] = recipient[:account_number] if recipient[:account_number]
198
+ post[:recipient][:first_name] = recipient[:first_name] if recipient[:first_name]
199
+ post[:recipient][:last_name] = recipient[:last_name] if recipient[:last_name]
200
+
201
+ if address = recipient[:address]
202
+ address1 = address[:address1] || address[:address_line1]
203
+ address2 = address[:address2] || address[:address_line2]
204
+
205
+ post[:recipient][:address] = {}
206
+ post[:recipient][:address][:address_line1] = address1 if address1
207
+ post[:recipient][:address][:address_line2] = address2 if address2
208
+ post[:recipient][:address][:city] = address[:city] if address[:city]
209
+ post[:recipient][:address][:state] = address[:state] if address[:state]
210
+ post[:recipient][:address][:zip] = address[:zip] if address[:zip]
211
+ post[:recipient][:address][:country] = address[:country] if address[:country]
212
+ end
213
+ end
214
+
215
+ def add_processing_data(post, options)
216
+ return unless options[:processing].is_a?(Hash)
217
+
218
+ post[:processing] = options[:processing]
219
+ end
220
+
221
+ def add_partial_authorization(post, options)
222
+ return unless options[:partial_authorization]
223
+
224
+ post[:partial_authorization] = {}
225
+ post[:partial_authorization][:enabled] = options[:partial_authorization] if options[:partial_authorization]
226
+ end
227
+
228
+ def add_risk_data(post, options)
229
+ return unless options[:risk].is_a?(Hash)
230
+
231
+ risk = options[:risk]
232
+ post[:risk] = {} unless risk.empty?
233
+
234
+ if risk[:enabled].to_s == 'true'
235
+ post[:risk][:enabled] = true
236
+ post[:risk][:device_session_id] = risk[:device_session_id] if risk[:device_session_id]
237
+ elsif risk[:enabled].to_s == 'false'
238
+ post[:risk][:enabled] = false
239
+ end
240
+ end
241
+
242
+ def add_payment_sender_data(post, options)
243
+ return unless options[:sender].is_a?(Hash)
244
+
245
+ sender = options[:sender]
246
+
247
+ birthdate = sender[:dob] || sender[:date_of_birth]
248
+
249
+ post[:sender] = {}
250
+ post[:sender][:type] = sender[:type] if sender[:type]
251
+ post[:sender][:first_name] = sender[:first_name] if sender[:first_name]
252
+ post[:sender][:last_name] = sender[:last_name] if sender[:last_name]
253
+ post[:sender][:date_of_birth] = birthdate if birthdate
254
+ post[:sender][:reference] = sender[:reference] if sender[:reference]
255
+ post[:sender][:company_name] = sender[:company_name] if sender[:company_name]
256
+
257
+ if address = sender[:address]
258
+ address1 = address[:address1] || address[:address_line1]
259
+ address2 = address[:address2] || address[:address_line2]
260
+
261
+ post[:sender][:address] = {}
262
+ post[:sender][:address][:address_line1] = address1 if address1
263
+ post[:sender][:address][:address_line2] = address2 if address2
264
+ post[:sender][:address][:city] = address[:city] if address[:city]
265
+ post[:sender][:address][:state] = address[:state] if address[:state]
266
+ post[:sender][:address][:zip] = address[:zip] if address[:zip]
267
+ post[:sender][:address][:country] = address[:country] if address[:country]
268
+ end
269
+
270
+ if identification = sender[:identification]
271
+ post[:sender][:identification] = {}
272
+ post[:sender][:identification][:type] = identification[:type] if identification[:type]
273
+ post[:sender][:identification][:number] = identification[:number] if identification[:number]
274
+ post[:sender][:identification][:issuing_country] = identification[:issuing_country] if identification[:issuing_country]
275
+ end
163
276
  end
164
277
 
165
278
  def add_authorization_type(post, options)
@@ -170,9 +283,11 @@ module ActiveMerchant #:nodoc:
170
283
  post[:metadata] = {} unless post[:metadata]
171
284
  post[:metadata].merge!(options[:metadata]) if options[:metadata]
172
285
  post[:metadata][:udf1] = 'mada' if payment_method.try(:brand) == 'mada'
286
+ post[:metadata][:udf5] = application_id || 'ActiveMerchant'
173
287
  end
174
288
 
175
289
  def add_payment_method(post, payment_method, options, key = :source)
290
+ # the key = :destination when this method is called in def credit
176
291
  post[key] = {}
177
292
  case payment_method
178
293
  when NetworkTokenizationCreditCard
@@ -190,13 +305,23 @@ module ActiveMerchant #:nodoc:
190
305
  post[key][:type] = 'card'
191
306
  post[key][:name] = payment_method.name
192
307
  post[key][:number] = payment_method.number
193
- post[key][:cvv] = payment_method.verification_value
308
+ post[key][:cvv] = payment_method.verification_value unless options[:funds_transfer_type]
194
309
  post[key][:stored] = 'true' if options[:card_on_file] == true
310
+
311
+ # because of the way the key = is implemented in the method signature, some of the destination
312
+ # data will be added here, some in the destination specific method below.
313
+ # at first i was going to move this, but since this data is coming from the payment method
314
+ # i think it makes sense to leave it
195
315
  if options[:account_holder_type]
196
316
  post[key][:account_holder] = {}
197
317
  post[key][:account_holder][:type] = options[:account_holder_type]
198
- post[key][:account_holder][:first_name] = payment_method.first_name if payment_method.first_name
199
- post[key][:account_holder][:last_name] = payment_method.last_name if payment_method.last_name
318
+
319
+ if options[:account_holder_type] == 'corporate' || options[:account_holder_type] == 'government'
320
+ post[key][:account_holder][:company_name] = payment_method.name if payment_method.respond_to?(:name)
321
+ else
322
+ post[key][:account_holder][:first_name] = payment_method.first_name if payment_method.first_name
323
+ post[key][:account_holder][:last_name] = payment_method.last_name if payment_method.last_name
324
+ end
200
325
  else
201
326
  post[key][:first_name] = payment_method.first_name if payment_method.first_name
202
327
  post[key][:last_name] = payment_method.last_name if payment_method.last_name
@@ -270,13 +395,14 @@ module ActiveMerchant #:nodoc:
270
395
  end
271
396
 
272
397
  def merchant_initiated_override(post, options)
398
+ post[:payment_type] ||= 'Regular'
273
399
  post[:merchant_initiated] = true
274
400
  post[:source][:stored] = true
275
401
  post[:previous_payment_id] = options[:merchant_initiated_transaction_id]
276
402
  end
277
403
 
278
404
  def add_stored_credentials_using_normalized_fields(post, options)
279
- if options[:stored_credential][:initial_transaction] == true
405
+ if options[:stored_credential][:initiator] == 'cardholder'
280
406
  post[:merchant_initiated] = false
281
407
  else
282
408
  post[:source][:stored] = true
@@ -288,7 +414,8 @@ module ActiveMerchant #:nodoc:
288
414
  def add_stored_credential_options(post, options = {})
289
415
  return unless options[:stored_credential]
290
416
 
291
- post[:payment_type] = 'Recurring' if %w(recurring installment).include? options[:stored_credential][:reason_type]
417
+ post[:payment_type] = options[:stored_credential][:reason_type]&.capitalize
418
+ post[:payment_type] = 'Regular' if options[:stored_credential][:initiator] == 'cardholder' && post[:payment_type] == 'Unscheduled'
292
419
 
293
420
  if options[:merchant_initiated_transaction_id]
294
421
  merchant_initiated_override(post, options)
@@ -321,6 +448,82 @@ module ActiveMerchant #:nodoc:
321
448
  post[:processing_channel_id] = options[:processing_channel_id] if options[:processing_channel_id]
322
449
  end
323
450
 
451
+ def add_instruction_data(post, options)
452
+ post[:instruction] = {}
453
+ post[:instruction][:funds_transfer_type] = options[:funds_transfer_type] || 'FD'
454
+ post[:instruction][:purpose] = options[:instruction_purpose] if options[:instruction_purpose]
455
+ end
456
+
457
+ def add_payout_sender_data(post, options)
458
+ return unless options[:payout] == true && options[:sender].is_a?(Hash)
459
+
460
+ post[:sender] = {
461
+ # options for type are individual, corporate, or government
462
+ type: options[:sender][:type],
463
+ # first and last name required if sent by type: individual
464
+ first_name: options[:sender][:first_name],
465
+ middle_name: options[:sender][:middle_name],
466
+ last_name: options[:sender][:last_name],
467
+ # company name required if sent by type: corporate or government
468
+ company_name: options[:sender][:company_name],
469
+ # these are required fields for payout, may not work if address is blank or different than cardholder(option for sender to be a company or government).
470
+ # may need to still include in GSF hash.
471
+
472
+ address: {
473
+ address_line1: options.dig(:sender, :address, :address1),
474
+ address_line2: options.dig(:sender, :address, :address2),
475
+ city: options.dig(:sender, :address, :city),
476
+ state: options.dig(:sender, :address, :state),
477
+ country: options.dig(:sender, :address, :country),
478
+ zip: options.dig(:sender, :address, :zip)
479
+ }.compact,
480
+ reference: options[:sender][:reference],
481
+ reference_type: options[:sender][:reference_type],
482
+ source_of_funds: options[:sender][:source_of_funds],
483
+ # identification object is conditional. required when card metadata issuer_country = AR, BR, CO, or PR
484
+ # checkout docs say PR (Peru), but PR is puerto rico and PE is Peru so yikes
485
+ identification: {
486
+ type: options.dig(:sender, :identification, :type),
487
+ number: options.dig(:sender, :identification, :number),
488
+ issuing_country: options.dig(:sender, :identification, :issuing_country),
489
+ date_of_expiry: options.dig(:sender, :identification, :date_of_expiry)
490
+ }.compact,
491
+ date_of_birth: options[:sender][:date_of_birth],
492
+ country_of_birth: options[:sender][:country_of_birth],
493
+ nationality: options[:sender][:nationality]
494
+ }.compact
495
+ end
496
+
497
+ def add_payout_destination_data(post, options)
498
+ return unless options[:payout] == true && options[:destination].is_a?(Hash)
499
+
500
+ post[:destination] ||= {}
501
+ post[:destination][:account_holder] ||= {}
502
+ post[:destination][:account_holder][:email] = options[:destination][:account_holder][:email] if options[:destination][:account_holder][:email]
503
+ post[:destination][:account_holder][:date_of_birth] = options[:destination][:account_holder][:date_of_birth] if options[:destination][:account_holder][:date_of_birth]
504
+ post[:destination][:account_holder][:country_of_birth] = options[:destination][:account_holder][:country_of_birth] if options[:destination][:account_holder][:country_of_birth]
505
+ # below fields only required during a card to card payout
506
+ post[:destination][:account_holder][:phone] = {}
507
+ post[:destination][:account_holder][:phone][:country_code] = options.dig(:destination, :account_holder, :phone, :country_code) if options.dig(:destination, :account_holder, :phone, :country_code)
508
+ post[:destination][:account_holder][:phone][:number] = options.dig(:destination, :account_holder, :phone, :number) if options.dig(:destination, :account_holder, :phone, :number)
509
+
510
+ post[:destination][:account_holder][:identification] = {}
511
+ post[:destination][:account_holder][:identification][:type] = options.dig(:destination, :account_holder, :identification, :type) if options.dig(:destination, :account_holder, :identification, :type)
512
+ post[:destination][:account_holder][:identification][:number] = options.dig(:destination, :account_holder, :identification, :number) if options.dig(:destination, :account_holder, :identification, :number)
513
+ post[:destination][:account_holder][:identification][:issuing_country] = options.dig(:destination, :account_holder, :identification, :issuing_country) if options.dig(:destination, :account_holder, :identification, :issuing_country)
514
+ post[:destination][:account_holder][:identification][:date_of_expiry] = options.dig(:destination, :account_holder, :identification, :date_of_expiry) if options.dig(:destination, :account_holder, :identification, :date_of_expiry)
515
+
516
+ if address = options[:billing_address] || options[:address] # destination address will come from the tokenized card billing address
517
+ post[:destination][:account_holder][:billing_address] = {}
518
+ post[:destination][:account_holder][:billing_address][:address_line1] = address[:address1] unless address[:address1].blank?
519
+ post[:destination][:account_holder][:billing_address][:address_line2] = address[:address2] unless address[:address2].blank?
520
+ post[:destination][:account_holder][:billing_address][:city] = address[:city] unless address[:city].blank?
521
+ post[:destination][:account_holder][:billing_address][:state] = address[:state] unless address[:state].blank?
522
+ post[:destination][:account_holder][:billing_address][:country] = address[:country] unless address[:country].blank?
523
+ post[:destination][:account_holder][:billing_address][:zip] = address[:zip] unless address[:zip].blank?
524
+ end
525
+ end
526
+
324
527
  def add_marketplace_data(post, options)
325
528
  if options[:marketplace]
326
529
  post[:marketplace] = {}
@@ -328,6 +531,67 @@ module ActiveMerchant #:nodoc:
328
531
  end
329
532
  end
330
533
 
534
+ def add_level_two_three_data(post, options)
535
+ post[:processing] ||= {}
536
+ post[:customer] ||= {}
537
+
538
+ # American Express only supports Level 2 data.
539
+ # Only is required add items info in lvl2 data for amex
540
+ add_items(post, options)
541
+ add_level_two_data(post, options)
542
+ add_level_three_data(post, options)
543
+ add_shipping_data(post, options)
544
+ end
545
+
546
+ def add_items(post, options)
547
+ items = build_items(options[:line_items] || [])
548
+ post[:items] = items unless items.empty?
549
+ end
550
+
551
+ def add_level_two_data(post, options)
552
+ post[:customer][:tax_number] = options[:tax_number] # field no require for amex
553
+
554
+ post[:processing].merge!(
555
+ {
556
+ order_id: options[:invoice_id],
557
+ tax_amount: options[:tax_amount]
558
+ }.compact
559
+ )
560
+ end
561
+
562
+ def add_level_three_data(post, options)
563
+ post[:processing].merge!(
564
+ {
565
+ discount_amount: options[:discount_amount],
566
+ shipping_amount: options[:shipping_amount],
567
+ duty_amount: options[:duty_amount]
568
+ }.compact
569
+ )
570
+ end
571
+
572
+ def add_shipping_data(post, options)
573
+ post[:shipping] ||= {}
574
+ post[:shipping][:from_address_zip] = options[:from_address_zip]
575
+ end
576
+
577
+ def build_items(line_items = [])
578
+ line_items.map do |item|
579
+ {
580
+ # for lvl 2 amex and lvl 3 visa/master
581
+ name: item[:name],
582
+ quantity: item[:quantity],
583
+ unit_price: item[:unit_price],
584
+ # for lvl3 visa/master
585
+ reference: item[:reference],
586
+ tax_amount: item[:tax_amount],
587
+ discount_amount: item[:discount_amount],
588
+ total_amount: item[:total_amount],
589
+ commodity_code: item[:commodity_code],
590
+ unit_of_measure: item[:unit_of_measure]
591
+ }.compact
592
+ end
593
+ end
594
+
331
595
  def access_token_header
332
596
  {
333
597
  'Authorization' => "Basic #{Base64.encode64("#{@options[:client_id]}:#{@options[:client_secret]}").delete("\n")}",
@@ -339,19 +603,43 @@ module ActiveMerchant #:nodoc:
339
603
  test? ? TEST_ACCESS_TOKEN_URL : LIVE_ACCESS_TOKEN_URL
340
604
  end
341
605
 
606
+ def expires_date_with_extra_range(expires_in)
607
+ # Two minutes are subtracted from the expires_in time to generate the expires date
608
+ # in order to prevent any transaction from failing due to using an access_token
609
+ # that is very close to expiring.
610
+ # e.g. the access_token has one second left to expire and the lag when the transaction
611
+ # use an already expired access_token
612
+ (DateTime.now + (expires_in - 120).seconds).strftime('%Q').to_i
613
+ end
614
+
342
615
  def setup_access_token
343
- request = 'grant_type=client_credentials'
344
- response = parse(ssl_post(access_token_url, request, access_token_header))
345
- response['access_token']
616
+ response = parse(ssl_post(access_token_url, 'grant_type=client_credentials', access_token_header))
617
+ @options[:access_token] = response['access_token']
618
+ @options[:expires] = expires_date_with_extra_range(response['expires_in']) if response['expires_in'] && response['expires_in'] > 0
619
+
620
+ Response.new(
621
+ access_token_valid?,
622
+ message_from(access_token_valid?, response, {}),
623
+ response.merge({ expires: @options[:expires] }),
624
+ test: test?,
625
+ error_code: error_code_from(access_token_valid?, response, {})
626
+ )
627
+ rescue ResponseError => e
628
+ raise OAuthResponseError.new(e)
346
629
  end
347
630
 
348
- def commit(action, post, options, authorization = nil, method = :post)
631
+ def access_token_valid?
632
+ @options[:access_token].present? && @options[:expires].to_i > DateTime.now.strftime('%Q').to_i
633
+ end
634
+
635
+ def perform_request(action, post, options, authorization = nil, method = :post)
349
636
  begin
350
637
  raw_response = ssl_request(method, url(action, authorization), post.nil? || post.empty? ? nil : post.to_json, headers(action, options))
351
638
  response = parse(raw_response)
352
639
  response['id'] = response['_links']['payment']['href'].split('/')[-1] if action == :capture && response.key?('_links')
353
- source_id = authorization if action == :unstore
354
640
  rescue ResponseError => e
641
+ @options[:access_token] = '' if e.response.code == '401' && !@options[:secret_key]
642
+
355
643
  raise unless e.response.code.to_s =~ /4\d\d/
356
644
 
357
645
  response = parse(e.response.body, error: e.response)
@@ -359,35 +647,55 @@ module ActiveMerchant #:nodoc:
359
647
 
360
648
  succeeded = success_from(action, response)
361
649
 
362
- response(action, succeeded, response, source_id)
650
+ response(action, succeeded, response, options)
651
+ end
652
+
653
+ def commit(action, post, options, authorization = nil, method = :post)
654
+ MultiResponse.run do |r|
655
+ r.process { setup_access_token } unless @options[:secret_key] || access_token_valid?
656
+ r.process { perform_request(action, post, options, authorization, method) }
657
+ end
363
658
  end
364
659
 
365
- def response(action, succeeded, response, source_id = nil)
660
+ def response(action, succeeded, response, options = {}, source_id = nil)
366
661
  authorization = authorization_from(response) unless action == :unstore
367
662
  body = action == :unstore ? { response_code: response.to_s } : response
368
663
  Response.new(
369
664
  succeeded,
370
- message_from(succeeded, response),
665
+ message_from(succeeded, response, options),
371
666
  body,
372
- authorization: authorization,
373
- error_code: error_code_from(succeeded, body),
667
+ authorization:,
668
+ error_code: error_code_from(succeeded, body, options),
374
669
  test: test?,
375
670
  avs_result: avs_result(response),
376
- cvv_result: cvv_result(response)
671
+ cvv_result: cvv_result(response),
672
+ pending: pending_result(response, action)
377
673
  )
378
674
  end
379
675
 
676
+ def pending_result(response, action)
677
+ return unless action == :credit
678
+
679
+ response['status'] == 'Pending'
680
+ end
681
+
380
682
  def headers(action, options)
381
- auth_token = @access_token ? "Bearer #{@access_token}" : @options[:secret_key]
382
- auth_token = @options[:public_key] if action == :tokens
383
- headers = {
384
- 'Authorization' => auth_token,
385
- 'Content-Type' => 'application/json;charset=UTF-8'
386
- }
683
+ headers = { 'Authorization' => auth_token(action), 'Content-Type' => 'application/json;charset=UTF-8' }
387
684
  headers['Cko-Idempotency-Key'] = options[:idempotency_key] if options[:idempotency_key]
685
+
388
686
  headers
389
687
  end
390
688
 
689
+ def auth_token(action)
690
+ return @options[:public_key] if action == :tokens
691
+
692
+ token = @options[:access_token] || @options[:secret_key]
693
+
694
+ return token if token.include?('Bearer')
695
+
696
+ "Bearer #{token}"
697
+ end
698
+
391
699
  def tokenize(payment_method, options = {})
392
700
  post = {}
393
701
  add_authorization_type(post, options)
@@ -448,19 +756,21 @@ module ActiveMerchant #:nodoc:
448
756
  return true if action == :unstore && response == 204
449
757
 
450
758
  store_response = response['token'] || response['id']
451
- if store_response
452
- return true if (action == :tokens && store_response.match(/tok/)) || (action == :store && store_response.match(/src_/))
453
- end
454
- response['response_summary'] == 'Approved' || response['approved'] == true || !response.key?('response_summary') && response.key?('action_id')
759
+ return true if store_response && ((action == :tokens && store_response.match(/tok/)) || (action == :store && store_response.match(/src_/)))
760
+
761
+ response['response_summary'] == 'Approved' || response['approved'] == true || (!response.key?('response_summary') && response.key?('action_id'))
455
762
  end
456
763
 
457
- def message_from(succeeded, response)
764
+ def message_from(succeeded, response, options)
458
765
  if succeeded
459
766
  'Succeeded'
460
767
  elsif response['error_type']
461
- response['error_type'] + ': ' + response['error_codes'].first
768
+ return response['error_type'] unless response['error_codes']
769
+
770
+ "#{response['error_type']}: #{response['error_codes'].first}"
462
771
  else
463
- response['response_summary'] || response['response_code'] || response['status'] || response['message'] || 'Unable to read error message'
772
+ response_summary = response['response_summary'] || response.dig('actions', 0, 'response_summary')
773
+ response_summary || response['response_code'] || response['status'] || response['message'] || 'Unable to read error message'
464
774
  end
465
775
  end
466
776
 
@@ -481,7 +791,7 @@ module ActiveMerchant #:nodoc:
481
791
  raw['id']
482
792
  end
483
793
 
484
- def error_code_from(succeeded, response)
794
+ def error_code_from(succeeded, response, options)
485
795
  return if succeeded
486
796
 
487
797
  if response['error_type'] && response['error_codes']
@@ -489,7 +799,9 @@ module ActiveMerchant #:nodoc:
489
799
  elsif response['error_type']
490
800
  response['error_type']
491
801
  else
492
- STANDARD_ERROR_CODE_MAPPING[response['response_code']]
802
+ response_code = response['response_code'] || response.dig('actions', 0, 'response_code')
803
+
804
+ STANDARD_ERROR_CODE_MAPPING[response_code]
493
805
  end
494
806
  end
495
807
 
@@ -1,5 +1,5 @@
1
- module ActiveMerchant #:nodoc:
2
- module Billing #:nodoc:
1
+ module ActiveMerchant # :nodoc:
2
+ module Billing # :nodoc:
3
3
  class ClearhausGateway < Gateway
4
4
  self.test_url = 'https://gateway.test.clearhaus.com'
5
5
  self.live_url = 'https://gateway.clearhaus.com'