activemerchant 1.79.2 → 1.129.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (279) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG +1391 -0
  3. data/README.md +29 -14
  4. data/lib/active_merchant/billing/avs_result.rb +25 -28
  5. data/lib/active_merchant/billing/base.rb +0 -13
  6. data/lib/active_merchant/billing/check.rb +55 -22
  7. data/lib/active_merchant/billing/compatibility.rb +10 -12
  8. data/lib/active_merchant/billing/credit_card.rb +82 -62
  9. data/lib/active_merchant/billing/credit_card_formatting.rb +4 -4
  10. data/lib/active_merchant/billing/credit_card_methods.rb +328 -58
  11. data/lib/active_merchant/billing/cvv_result.rb +0 -1
  12. data/lib/active_merchant/billing/gateway.rb +61 -56
  13. data/lib/active_merchant/billing/gateways/adyen.rb +562 -87
  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 +35 -36
  17. data/lib/active_merchant/billing/gateways/authorize_net.rb +297 -196
  18. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +31 -24
  19. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +94 -98
  20. data/lib/active_merchant/billing/gateways/axcessms.rb +64 -66
  21. data/lib/active_merchant/billing/gateways/balanced.rb +72 -65
  22. data/lib/active_merchant/billing/gateways/bambora_apac.rb +222 -0
  23. data/lib/active_merchant/billing/gateways/bank_frick.rb +16 -16
  24. data/lib/active_merchant/billing/gateways/banwire.rb +12 -12
  25. data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +140 -69
  26. data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +7 -7
  27. data/lib/active_merchant/billing/gateways/be2bill.rb +7 -7
  28. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +115 -115
  29. data/lib/active_merchant/billing/gateways/beanstream.rb +39 -13
  30. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +1 -2
  31. data/lib/active_merchant/billing/gateways/blue_pay.rb +87 -58
  32. data/lib/active_merchant/billing/gateways/blue_snap.rb +405 -104
  33. data/lib/active_merchant/billing/gateways/bogus.rb +34 -30
  34. data/lib/active_merchant/billing/gateways/borgun.rb +97 -47
  35. data/lib/active_merchant/billing/gateways/bpoint.rb +20 -20
  36. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -3
  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 +561 -259
  40. data/lib/active_merchant/billing/gateways/braintree_orange.rb +1 -1
  41. data/lib/active_merchant/billing/gateways/bridge_pay.rb +53 -54
  42. data/lib/active_merchant/billing/gateways/cams.rb +31 -31
  43. data/lib/active_merchant/billing/gateways/card_connect.rb +85 -33
  44. data/lib/active_merchant/billing/gateways/card_save.rb +7 -9
  45. data/lib/active_merchant/billing/gateways/card_stream.rb +187 -169
  46. data/lib/active_merchant/billing/gateways/cardknox.rb +24 -25
  47. data/lib/active_merchant/billing/gateways/cardprocess.rb +9 -7
  48. data/lib/active_merchant/billing/gateways/cashnet.rb +43 -27
  49. data/lib/active_merchant/billing/gateways/cc5.rb +14 -17
  50. data/lib/active_merchant/billing/gateways/cecabank.rb +62 -52
  51. data/lib/active_merchant/billing/gateways/cenpos.rb +63 -62
  52. data/lib/active_merchant/billing/gateways/checkout.rb +21 -23
  53. data/lib/active_merchant/billing/gateways/checkout_v2.rb +391 -113
  54. data/lib/active_merchant/billing/gateways/citrus_pay.rb +1 -3
  55. data/lib/active_merchant/billing/gateways/clearhaus.rb +40 -41
  56. data/lib/active_merchant/billing/gateways/commerce_hub.rb +361 -0
  57. data/lib/active_merchant/billing/gateways/commercegate.rb +11 -12
  58. data/lib/active_merchant/billing/gateways/conekta.rb +35 -30
  59. data/lib/active_merchant/billing/gateways/creditcall.rb +59 -59
  60. data/lib/active_merchant/billing/gateways/credorax.rb +326 -145
  61. data/lib/active_merchant/billing/gateways/ct_payment.rb +269 -0
  62. data/lib/active_merchant/billing/gateways/culqi.rb +53 -53
  63. data/lib/active_merchant/billing/gateways/cyber_source/cyber_source_common.rb +36 -0
  64. data/lib/active_merchant/billing/gateways/cyber_source.rb +566 -208
  65. data/lib/active_merchant/billing/gateways/cyber_source_rest.rb +456 -0
  66. data/lib/active_merchant/billing/gateways/d_local.rb +342 -0
  67. data/lib/active_merchant/billing/gateways/data_cash.rb +40 -56
  68. data/lib/active_merchant/billing/gateways/decidir.rb +358 -0
  69. data/lib/active_merchant/billing/gateways/decidir_plus.rb +344 -0
  70. data/lib/active_merchant/billing/gateways/dibs.rb +34 -40
  71. data/lib/active_merchant/billing/gateways/digitzs.rb +48 -45
  72. data/lib/active_merchant/billing/gateways/ebanx.rb +110 -60
  73. data/lib/active_merchant/billing/gateways/efsnet.rb +46 -50
  74. data/lib/active_merchant/billing/gateways/elavon.rb +351 -189
  75. data/lib/active_merchant/billing/gateways/element.rb +106 -56
  76. data/lib/active_merchant/billing/gateways/epay.rb +74 -64
  77. data/lib/active_merchant/billing/gateways/evo_ca.rb +13 -14
  78. data/lib/active_merchant/billing/gateways/eway.rb +74 -73
  79. data/lib/active_merchant/billing/gateways/eway_managed.rb +85 -87
  80. data/lib/active_merchant/billing/gateways/eway_rapid.rb +105 -60
  81. data/lib/active_merchant/billing/gateways/exact.rb +29 -37
  82. data/lib/active_merchant/billing/gateways/ezic.rb +21 -22
  83. data/lib/active_merchant/billing/gateways/fat_zebra.rb +70 -48
  84. data/lib/active_merchant/billing/gateways/federated_canada.rb +11 -13
  85. data/lib/active_merchant/billing/gateways/finansbank.rb +3 -4
  86. data/lib/active_merchant/billing/gateways/first_giving.rb +23 -23
  87. data/lib/active_merchant/billing/gateways/first_pay.rb +33 -13
  88. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +106 -105
  89. data/lib/active_merchant/billing/gateways/firstdata_e4_v27.rb +505 -0
  90. data/lib/active_merchant/billing/gateways/flo2cash.rb +36 -36
  91. data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +2 -2
  92. data/lib/active_merchant/billing/gateways/forte.rb +70 -40
  93. data/lib/active_merchant/billing/gateways/garanti.rb +24 -31
  94. data/lib/active_merchant/billing/gateways/global_collect.rb +378 -154
  95. data/lib/active_merchant/billing/gateways/global_transport.rb +12 -13
  96. data/lib/active_merchant/billing/gateways/hdfc.rb +55 -57
  97. data/lib/active_merchant/billing/gateways/hps.rb +236 -69
  98. data/lib/active_merchant/billing/gateways/iats_payments.rb +61 -39
  99. data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +1 -1
  100. data/lib/active_merchant/billing/gateways/inspire.rb +41 -47
  101. data/lib/active_merchant/billing/gateways/instapay.rb +10 -14
  102. data/lib/active_merchant/billing/gateways/ipg.rb +420 -0
  103. data/lib/active_merchant/billing/gateways/ipp.rb +25 -24
  104. data/lib/active_merchant/billing/gateways/iridium.rb +243 -244
  105. data/lib/active_merchant/billing/gateways/itransact.rb +14 -14
  106. data/lib/active_merchant/billing/gateways/iveri.rb +73 -34
  107. data/lib/active_merchant/billing/gateways/ixopay.rb +320 -0
  108. data/lib/active_merchant/billing/gateways/jetpay.rb +145 -152
  109. data/lib/active_merchant/billing/gateways/jetpay_v2.rb +154 -159
  110. data/lib/active_merchant/billing/gateways/komoju.rb +16 -16
  111. data/lib/active_merchant/billing/gateways/kushki.rb +127 -57
  112. data/lib/active_merchant/billing/gateways/latitude19.rb +111 -115
  113. data/lib/active_merchant/billing/gateways/linkpoint.rb +82 -85
  114. data/lib/active_merchant/billing/gateways/litle.rb +247 -53
  115. data/lib/active_merchant/billing/gateways/mastercard.rb +41 -23
  116. data/lib/active_merchant/billing/gateways/maxipago.rb +5 -5
  117. data/lib/active_merchant/billing/gateways/mercado_pago.rb +135 -49
  118. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +62 -29
  119. data/lib/active_merchant/billing/gateways/merchant_one.rb +16 -20
  120. data/lib/active_merchant/billing/gateways/merchant_partners.rb +40 -40
  121. data/lib/active_merchant/billing/gateways/merchant_ware.rb +54 -60
  122. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +42 -44
  123. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +52 -14
  124. data/lib/active_merchant/billing/gateways/mercury.rb +47 -51
  125. data/lib/active_merchant/billing/gateways/metrics_global.rb +32 -42
  126. data/lib/active_merchant/billing/gateways/micropayment.rb +42 -45
  127. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +7 -7
  128. data/lib/active_merchant/billing/gateways/migs.rb +45 -40
  129. data/lib/active_merchant/billing/gateways/mit.rb +260 -0
  130. data/lib/active_merchant/billing/gateways/modern_payments.rb +2 -2
  131. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +29 -31
  132. data/lib/active_merchant/billing/gateways/moka.rb +290 -0
  133. data/lib/active_merchant/billing/gateways/monei.rb +255 -138
  134. data/lib/active_merchant/billing/gateways/moneris.rb +226 -88
  135. data/lib/active_merchant/billing/gateways/money_movers.rb +11 -13
  136. data/lib/active_merchant/billing/gateways/mundipagg.rb +117 -43
  137. data/lib/active_merchant/billing/gateways/nab_transact.rb +28 -31
  138. data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +13 -15
  139. data/lib/active_merchant/billing/gateways/net_registry.rb +12 -12
  140. data/lib/active_merchant/billing/gateways/netaxept.rb +33 -34
  141. data/lib/active_merchant/billing/gateways/netbanx.rb +167 -80
  142. data/lib/active_merchant/billing/gateways/netbilling.rb +27 -30
  143. data/lib/active_merchant/billing/gateways/netpay.rb +10 -10
  144. data/lib/active_merchant/billing/gateways/network_merchants.rb +7 -11
  145. data/lib/active_merchant/billing/gateways/nmi.rb +134 -48
  146. data/lib/active_merchant/billing/gateways/ogone.rb +88 -58
  147. data/lib/active_merchant/billing/gateways/omise.rb +30 -31
  148. data/lib/active_merchant/billing/gateways/openpay.rb +45 -26
  149. data/lib/active_merchant/billing/gateways/opp.rb +166 -144
  150. data/lib/active_merchant/billing/gateways/optimal_payment.rb +67 -64
  151. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +5 -7
  152. data/lib/active_merchant/billing/gateways/orbital.rb +726 -382
  153. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +26 -27
  154. data/lib/active_merchant/billing/gateways/pagarme.rb +47 -56
  155. data/lib/active_merchant/billing/gateways/pago_facil.rb +12 -14
  156. data/lib/active_merchant/billing/gateways/pay_arc.rb +392 -0
  157. data/lib/active_merchant/billing/gateways/pay_conex.rb +39 -40
  158. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +65 -65
  159. data/lib/active_merchant/billing/gateways/pay_hub.rb +39 -39
  160. data/lib/active_merchant/billing/gateways/pay_junction.rb +37 -37
  161. data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +70 -54
  162. data/lib/active_merchant/billing/gateways/pay_secure.rb +15 -17
  163. data/lib/active_merchant/billing/gateways/pay_trace.rb +450 -0
  164. data/lib/active_merchant/billing/gateways/paybox_direct.rb +71 -47
  165. data/lib/active_merchant/billing/gateways/payeezy.rb +159 -32
  166. data/lib/active_merchant/billing/gateways/payex.rb +39 -42
  167. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +41 -36
  168. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +11 -8
  169. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +3 -3
  170. data/lib/active_merchant/billing/gateways/payflow.rb +178 -54
  171. data/lib/active_merchant/billing/gateways/payflow_express.rb +61 -65
  172. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +0 -1
  173. data/lib/active_merchant/billing/gateways/payflow_uk.rb +1 -2
  174. data/lib/active_merchant/billing/gateways/payment_express.rb +66 -58
  175. data/lib/active_merchant/billing/gateways/paymentez.rb +114 -25
  176. data/lib/active_merchant/billing/gateways/paymill.rb +134 -133
  177. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +2 -1
  178. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +4 -0
  179. data/lib/active_merchant/billing/gateways/paypal.rb +27 -14
  180. data/lib/active_merchant/billing/gateways/paypal_ca.rb +1 -1
  181. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +2 -2
  182. data/lib/active_merchant/billing/gateways/paypal_express.rb +5 -2
  183. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +1 -1
  184. data/lib/active_merchant/billing/gateways/paysafe.rb +420 -0
  185. data/lib/active_merchant/billing/gateways/payscout.rb +10 -13
  186. data/lib/active_merchant/billing/gateways/paystation.rb +79 -82
  187. data/lib/active_merchant/billing/gateways/payu_in.rb +59 -58
  188. data/lib/active_merchant/billing/gateways/payu_latam.rb +139 -97
  189. data/lib/active_merchant/billing/gateways/payway.rb +27 -27
  190. data/lib/active_merchant/billing/gateways/payway_dot_com.rb +253 -0
  191. data/lib/active_merchant/billing/gateways/pin.rb +87 -34
  192. data/lib/active_merchant/billing/gateways/plexo.rb +308 -0
  193. data/lib/active_merchant/billing/gateways/plugnpay.rb +82 -82
  194. data/lib/active_merchant/billing/gateways/priority.rb +392 -0
  195. data/lib/active_merchant/billing/gateways/pro_pay.rb +139 -140
  196. data/lib/active_merchant/billing/gateways/psigate.rb +44 -44
  197. data/lib/active_merchant/billing/gateways/psl_card.rb +29 -37
  198. data/lib/active_merchant/billing/gateways/qbms.rb +75 -76
  199. data/lib/active_merchant/billing/gateways/quantum.rb +21 -23
  200. data/lib/active_merchant/billing/gateways/quickbooks.rb +142 -55
  201. data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +103 -107
  202. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +156 -158
  203. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +7 -8
  204. data/lib/active_merchant/billing/gateways/quickpay.rb +1 -3
  205. data/lib/active_merchant/billing/gateways/qvalent.rb +137 -68
  206. data/lib/active_merchant/billing/gateways/rapyd.rb +319 -0
  207. data/lib/active_merchant/billing/gateways/reach.rb +277 -0
  208. data/lib/active_merchant/billing/gateways/realex.rb +132 -50
  209. data/lib/active_merchant/billing/gateways/redsys.rb +382 -186
  210. data/lib/active_merchant/billing/gateways/s5.rb +16 -16
  211. data/lib/active_merchant/billing/gateways/safe_charge.rb +83 -47
  212. data/lib/active_merchant/billing/gateways/sage.rb +49 -48
  213. data/lib/active_merchant/billing/gateways/sage_pay.rb +76 -83
  214. data/lib/active_merchant/billing/gateways/sallie_mae.rb +13 -15
  215. data/lib/active_merchant/billing/gateways/secure_net.rb +32 -40
  216. data/lib/active_merchant/billing/gateways/secure_pay.rb +30 -40
  217. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +23 -26
  218. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +14 -16
  219. data/lib/active_merchant/billing/gateways/securion_pay.rb +69 -31
  220. data/lib/active_merchant/billing/gateways/shift4.rb +342 -0
  221. data/lib/active_merchant/billing/gateways/simetrik.rb +368 -0
  222. data/lib/active_merchant/billing/gateways/skip_jack.rb +52 -53
  223. data/lib/active_merchant/billing/gateways/smart_ps.rb +51 -60
  224. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +29 -29
  225. data/lib/active_merchant/billing/gateways/spreedly_core.rb +66 -47
  226. data/lib/active_merchant/billing/gateways/stripe.rb +309 -148
  227. data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +556 -0
  228. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +18 -23
  229. data/lib/active_merchant/billing/gateways/telr.rb +46 -48
  230. data/lib/active_merchant/billing/gateways/tns.rb +8 -7
  231. data/lib/active_merchant/billing/gateways/trans_first.rb +37 -37
  232. data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +249 -245
  233. data/lib/active_merchant/billing/gateways/transact_pro.rb +25 -27
  234. data/lib/active_merchant/billing/gateways/transax.rb +6 -8
  235. data/lib/active_merchant/billing/gateways/transnational.rb +1 -2
  236. data/lib/active_merchant/billing/gateways/trexle.rb +22 -18
  237. data/lib/active_merchant/billing/gateways/trust_commerce.rb +161 -88
  238. data/lib/active_merchant/billing/gateways/usa_epay.rb +5 -6
  239. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +231 -238
  240. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +129 -55
  241. data/lib/active_merchant/billing/gateways/vanco.rb +42 -33
  242. data/lib/active_merchant/billing/gateways/verifi.rb +52 -53
  243. data/lib/active_merchant/billing/gateways/viaklix.rb +18 -22
  244. data/lib/active_merchant/billing/gateways/visanet_peru.rb +115 -74
  245. data/lib/active_merchant/billing/gateways/vpos.rb +223 -0
  246. data/lib/active_merchant/billing/gateways/webpay.rb +9 -9
  247. data/lib/active_merchant/billing/gateways/wepay.rb +38 -41
  248. data/lib/active_merchant/billing/gateways/wirecard.rb +36 -37
  249. data/lib/active_merchant/billing/gateways/wompi.rb +197 -0
  250. data/lib/active_merchant/billing/gateways/world_net.rb +39 -38
  251. data/lib/active_merchant/billing/gateways/worldpay.rb +756 -142
  252. data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +73 -83
  253. data/lib/active_merchant/billing/gateways/worldpay_us.rb +31 -31
  254. data/lib/active_merchant/billing/model.rb +2 -2
  255. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +3 -3
  256. data/lib/active_merchant/billing/rails.rb +1 -1
  257. data/lib/active_merchant/billing/response.rb +32 -13
  258. data/lib/active_merchant/billing/three_d_secure_eci_mapper.rb +27 -0
  259. data/lib/active_merchant/billing.rb +1 -0
  260. data/lib/active_merchant/connection.rb +24 -38
  261. data/lib/active_merchant/country.rb +9 -5
  262. data/lib/active_merchant/errors.rb +4 -1
  263. data/lib/active_merchant/net_http_ssl_connection.rb +2 -0
  264. data/lib/active_merchant/network_connection_retries.rb +28 -31
  265. data/lib/active_merchant/post_data.rb +5 -3
  266. data/lib/active_merchant/posts_data.rb +5 -7
  267. data/lib/active_merchant/version.rb +1 -1
  268. data/lib/active_merchant.rb +3 -3
  269. data/lib/activemerchant.rb +1 -1
  270. data/lib/certs/cacert.pem +1592 -2329
  271. data/lib/support/gateway_support.rb +8 -10
  272. data/lib/support/ssl_verify.rb +9 -14
  273. data/lib/support/ssl_version.rb +9 -10
  274. metadata +98 -37
  275. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +0 -246
  276. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +0 -13
  277. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +0 -29
  278. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +0 -66
  279. data/lib/active_merchant/billing/gateways/moneris_us.rb +0 -309
@@ -0,0 +1,342 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class Shift4Gateway < Gateway
4
+ self.test_url = 'https://utgapi.shift4test.com/api/rest/v1/'
5
+ self.live_url = 'https://utg.shift4api.net/api/rest/v1/'
6
+
7
+ self.supported_countries = %w(US CA CU HT DO PR JM TT GP MQ BS BB LC CW AW VC VI GD AG DM KY KN SX TC MF VG BQ AI BL MS)
8
+ self.default_currency = 'USD'
9
+ self.supported_cardtypes = %i[visa master american_express discover]
10
+
11
+ self.homepage_url = 'https://shift4.com'
12
+ self.display_name = 'Shift4'
13
+
14
+ RECURRING_TYPE_TRANSACTIONS = %w(recurring installment)
15
+ TRANSACTIONS_WITHOUT_RESPONSE_CODE = %w(accesstoken add)
16
+ SUCCESS_TRANSACTION_STATUS = %w(A)
17
+ DISALLOWED_ENTRY_MODE_ACTIONS = %w(capture refund add verify)
18
+ URL_POSTFIX_MAPPING = {
19
+ 'accesstoken' => 'credentials',
20
+ 'add' => 'tokens',
21
+ 'verify' => 'cards'
22
+ }
23
+ STANDARD_ERROR_CODE_MAPPING = {
24
+ 'incorrect_number' => STANDARD_ERROR_CODE[:incorrect_number],
25
+ 'invalid_number' => STANDARD_ERROR_CODE[:invalid_number],
26
+ 'invalid_expiry_month' => STANDARD_ERROR_CODE[:invalid_expiry_date],
27
+ 'invalid_expiry_year' => STANDARD_ERROR_CODE[:invalid_expiry_date],
28
+ 'invalid_cvc' => STANDARD_ERROR_CODE[:invalid_cvc],
29
+ 'expired_card' => STANDARD_ERROR_CODE[:expired_card],
30
+ 'insufficient_funds' => STANDARD_ERROR_CODE[:card_declined],
31
+ 'incorrect_cvc' => STANDARD_ERROR_CODE[:incorrect_cvc],
32
+ 'incorrect_zip' => STANDARD_ERROR_CODE[:incorrect_zip],
33
+ 'card_declined' => STANDARD_ERROR_CODE[:card_declined],
34
+ 'processing_error' => STANDARD_ERROR_CODE[:processing_error],
35
+ 'lost_or_stolen' => STANDARD_ERROR_CODE[:card_declined],
36
+ 'suspected_fraud' => STANDARD_ERROR_CODE[:card_declined],
37
+ 'expired_token' => STANDARD_ERROR_CODE[:card_declined]
38
+ }
39
+
40
+ def initialize(options = {})
41
+ requires!(options, :client_guid, :auth_token)
42
+ @client_guid = options[:client_guid]
43
+ @auth_token = options[:auth_token]
44
+ @access_token = options[:access_token]
45
+ super
46
+ end
47
+
48
+ def purchase(money, payment_method, options = {})
49
+ post = {}
50
+ action = 'sale'
51
+
52
+ payment_method = get_card_token(payment_method) if payment_method.is_a?(String)
53
+ add_datetime(post, options)
54
+ add_invoice(post, money, options)
55
+ add_clerk(post, options)
56
+ add_transaction(post, options)
57
+ add_card(action, post, payment_method, options)
58
+ add_card_present(post, options)
59
+ add_customer(post, payment_method, options)
60
+
61
+ commit(action, post, options)
62
+ end
63
+
64
+ def authorize(money, payment_method, options = {})
65
+ post = {}
66
+ action = 'authorization'
67
+
68
+ payment_method = get_card_token(payment_method) if payment_method.is_a?(String)
69
+ add_datetime(post, options)
70
+ add_invoice(post, money, options)
71
+ add_clerk(post, options)
72
+ add_transaction(post, options)
73
+ add_card(action, post, payment_method, options)
74
+ add_card_present(post, options)
75
+ add_customer(post, payment_method, options)
76
+
77
+ commit(action, post, options)
78
+ end
79
+
80
+ def capture(money, authorization, options = {})
81
+ post = {}
82
+ action = 'capture'
83
+ options[:invoice] = get_invoice(authorization)
84
+
85
+ add_datetime(post, options)
86
+ add_invoice(post, money, options)
87
+ add_clerk(post, options)
88
+ add_transaction(post, options)
89
+ add_card(action, post, get_card_token(authorization), options)
90
+
91
+ commit(action, post, options)
92
+ end
93
+
94
+ def refund(money, authorization, options = {})
95
+ post = {}
96
+ action = 'refund'
97
+
98
+ add_datetime(post, options)
99
+ add_invoice(post, money, options)
100
+ add_clerk(post, options)
101
+ add_transaction(post, options)
102
+ add_card(action, post, get_card_token(authorization), options)
103
+ add_card_present(post, options)
104
+
105
+ commit(action, post, options)
106
+ end
107
+
108
+ def void(authorization, options = {})
109
+ options[:invoice] = get_invoice(authorization)
110
+ commit('invoice', {}, options)
111
+ end
112
+
113
+ def verify(credit_card, options = {})
114
+ post = {}
115
+ action = 'verify'
116
+ post[:transaction] = {}
117
+
118
+ add_datetime(post, options)
119
+ add_card(action, post, credit_card, options)
120
+ add_customer(post, credit_card, options)
121
+ add_card_on_file(post[:transaction], options)
122
+
123
+ commit(action, post, options)
124
+ end
125
+
126
+ def store(credit_card, options = {})
127
+ post = {}
128
+ action = 'add'
129
+
130
+ add_datetime(post, options)
131
+ add_card(action, post, credit_card, options)
132
+ add_customer(post, credit_card, options)
133
+
134
+ commit(action, post, options)
135
+ end
136
+
137
+ def supports_scrubbing?
138
+ true
139
+ end
140
+
141
+ def scrub(transcript)
142
+ transcript.
143
+ gsub(%r(("Number\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
144
+ gsub(%r(("expirationDate\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
145
+ gsub(%r(("FirstName\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
146
+ gsub(%r(("LastName\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
147
+ gsub(%r(("securityCode\\?":{\\?"[\w]+\\?":[\d]+,\\?"value\\?":\\?")[\d]*)i, '\1[FILTERED]')
148
+ end
149
+
150
+ def setup_access_token
151
+ post = {}
152
+ add_credentials(post, options)
153
+ add_datetime(post, options)
154
+
155
+ response = commit('accesstoken', post, request_headers('accesstoken', options))
156
+ raise OAuthResponseError.new(response, response.params.fetch('result', [{}]).first.dig('error', 'longText')) unless response.success?
157
+
158
+ response.params['result'].first['credential']['accessToken']
159
+ end
160
+
161
+ private
162
+
163
+ def add_credentials(post, options)
164
+ post[:credential] = {}
165
+ post[:credential][:clientGuid] = @client_guid
166
+ post[:credential][:authToken] = @auth_token
167
+ end
168
+
169
+ def add_clerk(post, options)
170
+ post[:clerk] = {}
171
+ post[:clerk][:numericId] = options[:clerk_id] || '1'
172
+ end
173
+
174
+ def add_invoice(post, money, options)
175
+ post[:amount] = {}
176
+ post[:amount][:total] = amount(money.to_f)
177
+ post[:amount][:tax] = options[:tax].to_f || 0.0
178
+ end
179
+
180
+ def add_datetime(post, options)
181
+ post[:dateTime] = options[:date_time] || current_date_time(options)
182
+ end
183
+
184
+ def add_transaction(post, options)
185
+ post[:transaction] = {}
186
+ post[:transaction][:invoice] = options[:invoice] || Time.new.to_i.to_s[1..3] + rand.to_s[2..7]
187
+ post[:transaction][:notes] = options[:notes] if options[:notes].present?
188
+ post[:transaction][:vendorReference] = options[:order_id]
189
+
190
+ add_purchase_card(post[:transaction], options)
191
+ add_card_on_file(post[:transaction], options)
192
+ end
193
+
194
+ def add_card(action, post, payment_method, options)
195
+ post[:card] = {}
196
+ post[:card][:entryMode] = options[:entry_mode] || 'M' unless DISALLOWED_ENTRY_MODE_ACTIONS.include?(action)
197
+ if payment_method.is_a?(CreditCard)
198
+ post[:card][:expirationDate] = "#{format(payment_method.month, :two_digits)}#{format(payment_method.year, :two_digits)}"
199
+ post[:card][:number] = payment_method.number
200
+ post[:card][:securityCode] = {}
201
+ post[:card][:securityCode][:indicator] = 1
202
+ post[:card][:securityCode][:value] = payment_method.verification_value
203
+ else
204
+ post[:card] = {} if post[:card].nil?
205
+ post[:card][:token] = {}
206
+ post[:card][:token][:value] = payment_method
207
+ post[:card][:expirationDate] = options[:expiration_date] if options[:expiration_date]
208
+ end
209
+ end
210
+
211
+ def add_card_present(post, options)
212
+ post[:card] = {} unless post[:card].present?
213
+
214
+ post[:card][:present] = options[:card_present] || 'N'
215
+ end
216
+
217
+ def add_customer(post, card, options)
218
+ address = options[:billing_address] || {}
219
+
220
+ post[:customer] = {}
221
+ post[:customer][:addressLine1] = address[:address1] if address[:address1]
222
+ post[:customer][:postalCode] = address[:zip] if address[:zip] && !address[:zip]&.to_s&.empty?
223
+ post[:customer][:firstName] = card.first_name if card.is_a?(CreditCard) && card.first_name
224
+ post[:customer][:lastName] = card.last_name if card.is_a?(CreditCard) && card.last_name
225
+ post[:customer][:emailAddress] = options[:email] if options[:email]
226
+ post[:customer][:ipAddress] = options[:ip] if options[:ip]
227
+ end
228
+
229
+ def add_purchase_card(post, options)
230
+ return unless options[:customer_reference] || options[:destination_postal_code] || options[:product_descriptors]
231
+
232
+ post[:purchaseCard] = {}
233
+ post[:purchaseCard][:customerReference] = options[:customer_reference] if options[:customer_reference]
234
+ post[:purchaseCard][:destinationPostalCode] = options[:destination_postal_code] if options[:destination_postal_code]
235
+ post[:purchaseCard][:productDescriptors] = options[:product_descriptors] if options[:product_descriptors]
236
+ end
237
+
238
+ def add_card_on_file(post, options)
239
+ return unless options[:stored_credential] || options[:usage_indicator] || options[:indicator] || options[:scheduled_indicator] || options[:transaction_id]
240
+
241
+ stored_credential = options[:stored_credential] || {}
242
+ post[:cardOnFile] = {}
243
+ post[:cardOnFile][:usageIndicator] = options[:usage_indicator] || (stored_credential[:initial_transaction] ? '01' : '02')
244
+ post[:cardOnFile][:indicator] = options[:indicator] || '01'
245
+ post[:cardOnFile][:scheduledIndicator] = options[:scheduled_indicator] || (RECURRING_TYPE_TRANSACTIONS.include?(stored_credential[:reason_type]) ? '01' : '02')
246
+ post[:cardOnFile][:transactionId] = options[:transaction_id] || stored_credential[:network_transaction_id] if options[:transaction_id] || stored_credential[:network_transaction_id]
247
+ end
248
+
249
+ def commit(action, parameters, option)
250
+ url_postfix = URL_POSTFIX_MAPPING[action] || 'transactions'
251
+ url = (test? ? "#{test_url}#{url_postfix}/#{action}" : "#{live_url}#{url_postfix}/#{action}")
252
+ if action == 'invoice'
253
+ response = parse(ssl_request(:delete, url, parameters.to_json, request_headers(action, option)))
254
+ else
255
+ response = parse(ssl_post(url, parameters.to_json, request_headers(action, option)))
256
+ end
257
+
258
+ Response.new(
259
+ success_from(action, response),
260
+ message_from(action, response),
261
+ response,
262
+ authorization: authorization_from(action, response),
263
+ test: test?,
264
+ error_code: error_code_from(action, response)
265
+ )
266
+ end
267
+
268
+ def handle_response(response)
269
+ case response.code.to_i
270
+ when 200...300, 400, 401, 500
271
+ response.body
272
+ else
273
+ raise ResponseError.new(response)
274
+ end
275
+ end
276
+
277
+ def parse(body)
278
+ return {} if body == ''
279
+
280
+ JSON.parse(body)
281
+ end
282
+
283
+ def message_from(action, response)
284
+ success_from(action, response) ? 'Transaction successful' : (error(response)&.dig('longText') || 'Transaction declined')
285
+ end
286
+
287
+ def error_code_from(action, response)
288
+ return unless success_from(action, response)
289
+
290
+ STANDARD_ERROR_CODE_MAPPING[response['primaryCode']]
291
+ end
292
+
293
+ def authorization_from(action, response)
294
+ return unless success_from(action, response)
295
+
296
+ authorization = response.dig('result', 0, 'card', 'token', 'value').to_s
297
+ invoice = response.dig('result', 0, 'transaction', 'invoice')
298
+ authorization += "|#{invoice}" if invoice
299
+ authorization
300
+ end
301
+
302
+ def get_card_token(authorization)
303
+ authorization.is_a?(CreditCard) ? authorization : authorization.split('|')[0]
304
+ end
305
+
306
+ def get_invoice(authorization)
307
+ authorization.is_a?(CreditCard) ? authorization : authorization.split('|')[1]
308
+ end
309
+
310
+ def request_headers(action, options)
311
+ headers = {
312
+ 'Content-Type' => 'application/json'
313
+ }
314
+ headers['AccessToken'] = @access_token
315
+ headers['Invoice'] = options[:invoice] if action != 'capture' && options[:invoice].present?
316
+ headers['InterfaceVersion'] = '1'
317
+ headers['InterfaceName'] = 'Spreedly'
318
+ headers['CompanyName'] = 'Spreedly'
319
+ headers
320
+ end
321
+
322
+ def success_from(action, response)
323
+ success = error(response).nil?
324
+ success &&= SUCCESS_TRANSACTION_STATUS.include?(response['result'].first['transaction']['responseCode']) unless TRANSACTIONS_WITHOUT_RESPONSE_CODE.include?(action)
325
+ success
326
+ end
327
+
328
+ def error(response)
329
+ server_error = { 'longText' => response['error'] } if response['error']
330
+ server_error || response['result'].first['error']
331
+ end
332
+
333
+ def current_date_time(options = {})
334
+ time_zone = options[:merchant_time_zone] || 'Pacific Time (US & Canada)'
335
+ time = Time.now.in_time_zone(time_zone)
336
+ offset = Time.now.in_time_zone(time_zone).formatted_offset
337
+
338
+ time.strftime('%Y-%m-%dT%H:%M:%S.%3N') + offset
339
+ end
340
+ end
341
+ end
342
+ end