activemerchant 1.45.0 → 1.126.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (288) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG +2167 -2
  3. data/CONTRIBUTORS +57 -0
  4. data/README.md +62 -41
  5. data/lib/active_merchant/billing/avs_result.rb +25 -28
  6. data/lib/active_merchant/billing/base.rb +11 -35
  7. data/lib/active_merchant/billing/check.rb +28 -24
  8. data/lib/active_merchant/billing/compatibility.rb +10 -12
  9. data/lib/active_merchant/billing/credit_card.rb +141 -69
  10. data/lib/active_merchant/billing/credit_card_formatting.rb +4 -4
  11. data/lib/active_merchant/billing/credit_card_methods.rb +348 -52
  12. data/lib/active_merchant/billing/cvv_result.rb +0 -1
  13. data/lib/active_merchant/billing/gateway.rb +125 -61
  14. data/lib/active_merchant/billing/gateways/adyen.rb +633 -127
  15. data/lib/active_merchant/billing/gateways/airwallex.rb +341 -0
  16. data/lib/active_merchant/billing/gateways/allied_wallet.rb +205 -0
  17. data/lib/active_merchant/billing/gateways/authorize_net.rb +883 -195
  18. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +31 -24
  19. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +104 -103
  20. data/lib/active_merchant/billing/gateways/axcessms.rb +179 -0
  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 +24 -13
  25. data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +397 -0
  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 +143 -62
  29. data/lib/active_merchant/billing/gateways/beanstream.rb +45 -13
  30. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +13 -10
  31. data/lib/active_merchant/billing/gateways/blue_pay.rb +549 -506
  32. data/lib/active_merchant/billing/gateways/blue_snap.rb +623 -0
  33. data/lib/active_merchant/billing/gateways/bogus.rb +82 -36
  34. data/lib/active_merchant/billing/gateways/borgun.rb +61 -40
  35. data/lib/active_merchant/billing/gateways/bpoint.rb +277 -0
  36. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +21 -2
  37. data/lib/active_merchant/billing/gateways/braintree/token_nonce.rb +113 -0
  38. data/lib/active_merchant/billing/gateways/braintree.rb +3 -3
  39. data/lib/active_merchant/billing/gateways/braintree_blue.rb +592 -203
  40. data/lib/active_merchant/billing/gateways/braintree_orange.rb +3 -4
  41. data/lib/active_merchant/billing/gateways/bridge_pay.rb +116 -61
  42. data/lib/active_merchant/billing/gateways/cams.rb +230 -0
  43. data/lib/active_merchant/billing/gateways/card_connect.rb +320 -0
  44. data/lib/active_merchant/billing/gateways/card_save.rb +7 -9
  45. data/lib/active_merchant/billing/gateways/card_stream.rb +248 -97
  46. data/lib/active_merchant/billing/gateways/cardknox.rb +327 -0
  47. data/lib/active_merchant/billing/gateways/cardprocess.rb +256 -0
  48. data/lib/active_merchant/billing/gateways/cashnet.rb +70 -26
  49. data/lib/active_merchant/billing/gateways/cc5.rb +14 -17
  50. data/lib/active_merchant/billing/gateways/cecabank.rb +73 -53
  51. data/lib/active_merchant/billing/gateways/cenpos.rb +328 -0
  52. data/lib/active_merchant/billing/gateways/checkout.rb +32 -33
  53. data/lib/active_merchant/billing/gateways/checkout_v2.rb +340 -0
  54. data/lib/active_merchant/billing/gateways/citrus_pay.rb +21 -0
  55. data/lib/active_merchant/billing/gateways/clearhaus.rb +219 -0
  56. data/lib/active_merchant/billing/gateways/commercegate.rb +11 -12
  57. data/lib/active_merchant/billing/gateways/conekta.rb +55 -34
  58. data/lib/active_merchant/billing/gateways/creditcall.rb +272 -0
  59. data/lib/active_merchant/billing/gateways/credorax.rb +506 -0
  60. data/lib/active_merchant/billing/gateways/ct_payment.rb +269 -0
  61. data/lib/active_merchant/billing/gateways/culqi.rb +279 -0
  62. data/lib/active_merchant/billing/gateways/cyber_source.rb +637 -221
  63. data/lib/active_merchant/billing/gateways/d_local.rb +303 -0
  64. data/lib/active_merchant/billing/gateways/data_cash.rb +57 -355
  65. data/lib/active_merchant/billing/gateways/decidir.rb +347 -0
  66. data/lib/active_merchant/billing/gateways/decidir_plus.rb +344 -0
  67. data/lib/active_merchant/billing/gateways/dibs.rb +199 -0
  68. data/lib/active_merchant/billing/gateways/digitzs.rb +295 -0
  69. data/lib/active_merchant/billing/gateways/ebanx.rb +334 -0
  70. data/lib/active_merchant/billing/gateways/efsnet.rb +46 -50
  71. data/lib/active_merchant/billing/gateways/elavon.rb +377 -250
  72. data/lib/active_merchant/billing/gateways/element.rb +386 -0
  73. data/lib/active_merchant/billing/gateways/epay.rb +92 -71
  74. data/lib/active_merchant/billing/gateways/evo_ca.rb +13 -14
  75. data/lib/active_merchant/billing/gateways/eway.rb +85 -73
  76. data/lib/active_merchant/billing/gateways/eway_managed.rb +85 -87
  77. data/lib/active_merchant/billing/gateways/eway_rapid.rb +134 -80
  78. data/lib/active_merchant/billing/gateways/exact.rb +37 -36
  79. data/lib/active_merchant/billing/gateways/ezic.rb +195 -0
  80. data/lib/active_merchant/billing/gateways/fat_zebra.rb +124 -74
  81. data/lib/active_merchant/billing/gateways/federated_canada.rb +11 -13
  82. data/lib/active_merchant/billing/gateways/finansbank.rb +4 -5
  83. data/lib/active_merchant/billing/gateways/first_giving.rb +23 -23
  84. data/lib/active_merchant/billing/gateways/first_pay.rb +45 -23
  85. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +184 -87
  86. data/lib/active_merchant/billing/gateways/firstdata_e4_v27.rb +505 -0
  87. data/lib/active_merchant/billing/gateways/flo2cash.rb +215 -0
  88. data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +20 -0
  89. data/lib/active_merchant/billing/gateways/forte.rb +286 -0
  90. data/lib/active_merchant/billing/gateways/garanti.rb +31 -32
  91. data/lib/active_merchant/billing/gateways/global_collect.rb +507 -0
  92. data/lib/active_merchant/billing/gateways/global_transport.rb +25 -15
  93. data/lib/active_merchant/billing/gateways/hdfc.rb +55 -57
  94. data/lib/active_merchant/billing/gateways/hps.rb +252 -68
  95. data/lib/active_merchant/billing/gateways/iats_payments.rb +99 -38
  96. data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +15 -0
  97. data/lib/active_merchant/billing/gateways/inspire.rb +48 -48
  98. data/lib/active_merchant/billing/gateways/instapay.rb +10 -14
  99. data/lib/active_merchant/billing/gateways/ipg.rb +415 -0
  100. data/lib/active_merchant/billing/gateways/ipp.rb +176 -0
  101. data/lib/active_merchant/billing/gateways/iridium.rb +254 -244
  102. data/lib/active_merchant/billing/gateways/itransact.rb +14 -14
  103. data/lib/active_merchant/billing/gateways/iveri.rb +254 -0
  104. data/lib/active_merchant/billing/gateways/ixopay.rb +320 -0
  105. data/lib/active_merchant/billing/gateways/jetpay.rb +200 -80
  106. data/lib/active_merchant/billing/gateways/jetpay_v2.rb +432 -0
  107. data/lib/active_merchant/billing/gateways/komoju.rb +115 -0
  108. data/lib/active_merchant/billing/gateways/kushki.rb +277 -0
  109. data/lib/active_merchant/billing/gateways/latitude19.rb +412 -0
  110. data/lib/active_merchant/billing/gateways/linkpoint.rb +95 -85
  111. data/lib/active_merchant/billing/gateways/litle.rb +371 -94
  112. data/lib/active_merchant/billing/gateways/mastercard.rb +293 -0
  113. data/lib/active_merchant/billing/gateways/maxipago.rb +146 -123
  114. data/lib/active_merchant/billing/gateways/mercado_pago.rb +331 -0
  115. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +47 -23
  116. data/lib/active_merchant/billing/gateways/merchant_one.rb +16 -20
  117. data/lib/active_merchant/billing/gateways/merchant_partners.rb +245 -0
  118. data/lib/active_merchant/billing/gateways/merchant_ware.rb +54 -60
  119. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +60 -44
  120. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +76 -23
  121. data/lib/active_merchant/billing/gateways/mercury.rb +73 -54
  122. data/lib/active_merchant/billing/gateways/metrics_global.rb +33 -43
  123. data/lib/active_merchant/billing/gateways/micropayment.rb +182 -0
  124. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +7 -7
  125. data/lib/active_merchant/billing/gateways/migs.rb +101 -37
  126. data/lib/active_merchant/billing/gateways/mit.rb +260 -0
  127. data/lib/active_merchant/billing/gateways/modern_payments.rb +3 -3
  128. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +30 -34
  129. data/lib/active_merchant/billing/gateways/moka.rb +290 -0
  130. data/lib/active_merchant/billing/gateways/monei.rb +422 -0
  131. data/lib/active_merchant/billing/gateways/moneris.rb +236 -72
  132. data/lib/active_merchant/billing/gateways/money_movers.rb +11 -13
  133. data/lib/active_merchant/billing/gateways/mundipagg.rb +363 -0
  134. data/lib/active_merchant/billing/gateways/nab_transact.rb +87 -68
  135. data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +163 -0
  136. data/lib/active_merchant/billing/gateways/net_registry.rb +12 -12
  137. data/lib/active_merchant/billing/gateways/netaxept.rb +33 -34
  138. data/lib/active_merchant/billing/gateways/netbanx.rb +376 -0
  139. data/lib/active_merchant/billing/gateways/netbilling.rb +82 -43
  140. data/lib/active_merchant/billing/gateways/netpay.rb +10 -10
  141. data/lib/active_merchant/billing/gateways/network_merchants.rb +7 -11
  142. data/lib/active_merchant/billing/gateways/nmi.rb +279 -174
  143. data/lib/active_merchant/billing/gateways/ogone.rb +96 -50
  144. data/lib/active_merchant/billing/gateways/omise.rb +323 -0
  145. data/lib/active_merchant/billing/gateways/openpay.rb +58 -23
  146. data/lib/active_merchant/billing/gateways/opp.rb +394 -0
  147. data/lib/active_merchant/billing/gateways/optimal_payment.rb +87 -69
  148. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +5 -7
  149. data/lib/active_merchant/billing/gateways/orbital.rb +771 -328
  150. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +31 -32
  151. data/lib/active_merchant/billing/gateways/pagarme.rb +239 -0
  152. data/lib/active_merchant/billing/gateways/pago_facil.rb +12 -14
  153. data/lib/active_merchant/billing/gateways/pay_arc.rb +392 -0
  154. data/lib/active_merchant/billing/gateways/pay_conex.rb +245 -0
  155. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +84 -68
  156. data/lib/active_merchant/billing/gateways/pay_hub.rb +213 -0
  157. data/lib/active_merchant/billing/gateways/pay_junction.rb +37 -37
  158. data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +206 -0
  159. data/lib/active_merchant/billing/gateways/pay_secure.rb +15 -17
  160. data/lib/active_merchant/billing/gateways/pay_trace.rb +404 -0
  161. data/lib/active_merchant/billing/gateways/paybox_direct.rb +85 -49
  162. data/lib/active_merchant/billing/gateways/payeezy.rb +458 -0
  163. data/lib/active_merchant/billing/gateways/payex.rb +39 -42
  164. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +67 -41
  165. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +11 -8
  166. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +3 -3
  167. data/lib/active_merchant/billing/gateways/payflow.rb +215 -46
  168. data/lib/active_merchant/billing/gateways/payflow_express.rb +64 -68
  169. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +2 -3
  170. data/lib/active_merchant/billing/gateways/payflow_uk.rb +5 -6
  171. data/lib/active_merchant/billing/gateways/payment_express.rb +78 -58
  172. data/lib/active_merchant/billing/gateways/paymentez.rb +353 -0
  173. data/lib/active_merchant/billing/gateways/paymill.rb +163 -75
  174. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +55 -7
  175. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +1 -1
  176. data/lib/active_merchant/billing/gateways/paypal.rb +37 -18
  177. data/lib/active_merchant/billing/gateways/paypal_ca.rb +2 -2
  178. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +5 -5
  179. data/lib/active_merchant/billing/gateways/paypal_express.rb +12 -6
  180. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +3 -3
  181. data/lib/active_merchant/billing/gateways/paysafe.rb +412 -0
  182. data/lib/active_merchant/billing/gateways/payscout.rb +10 -13
  183. data/lib/active_merchant/billing/gateways/paystation.rb +96 -91
  184. data/lib/active_merchant/billing/gateways/payu_in.rb +249 -0
  185. data/lib/active_merchant/billing/gateways/payu_latam.rb +479 -0
  186. data/lib/active_merchant/billing/gateways/payway.rb +27 -27
  187. data/lib/active_merchant/billing/gateways/payway_dot_com.rb +253 -0
  188. data/lib/active_merchant/billing/gateways/pin.rb +113 -37
  189. data/lib/active_merchant/billing/gateways/plugnpay.rb +82 -82
  190. data/lib/active_merchant/billing/gateways/priority.rb +369 -0
  191. data/lib/active_merchant/billing/gateways/pro_pay.rb +325 -0
  192. data/lib/active_merchant/billing/gateways/psigate.rb +55 -44
  193. data/lib/active_merchant/billing/gateways/psl_card.rb +32 -40
  194. data/lib/active_merchant/billing/gateways/qbms.rb +86 -76
  195. data/lib/active_merchant/billing/gateways/quantum.rb +21 -23
  196. data/lib/active_merchant/billing/gateways/quickbooks.rb +377 -0
  197. data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +184 -0
  198. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +297 -0
  199. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +226 -0
  200. data/lib/active_merchant/billing/gateways/quickpay.rb +10 -353
  201. data/lib/active_merchant/billing/gateways/qvalent.rb +305 -0
  202. data/lib/active_merchant/billing/gateways/rapyd.rb +258 -0
  203. data/lib/active_merchant/billing/gateways/realex.rb +154 -52
  204. data/lib/active_merchant/billing/gateways/redsys.rb +488 -161
  205. data/lib/active_merchant/billing/gateways/s5.rb +247 -0
  206. data/lib/active_merchant/billing/gateways/safe_charge.rb +298 -0
  207. data/lib/active_merchant/billing/gateways/sage.rb +404 -133
  208. data/lib/active_merchant/billing/gateways/sage_pay.rb +145 -109
  209. data/lib/active_merchant/billing/gateways/sallie_mae.rb +13 -15
  210. data/lib/active_merchant/billing/gateways/secure_net.rb +62 -54
  211. data/lib/active_merchant/billing/gateways/secure_pay.rb +32 -42
  212. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +36 -27
  213. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +14 -16
  214. data/lib/active_merchant/billing/gateways/securion_pay.rb +265 -0
  215. data/lib/active_merchant/billing/gateways/simetrik.rb +362 -0
  216. data/lib/active_merchant/billing/gateways/skip_jack.rb +52 -54
  217. data/lib/active_merchant/billing/gateways/smart_ps.rb +51 -60
  218. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +29 -29
  219. data/lib/active_merchant/billing/gateways/spreedly_core.rb +108 -43
  220. data/lib/active_merchant/billing/gateways/stripe.rb +536 -120
  221. data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +516 -0
  222. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +19 -25
  223. data/lib/active_merchant/billing/gateways/telr.rb +273 -0
  224. data/lib/active_merchant/billing/gateways/tns.rb +16 -217
  225. data/lib/active_merchant/billing/gateways/trans_first.rb +148 -34
  226. data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +612 -0
  227. data/lib/active_merchant/billing/gateways/transact_pro.rb +222 -0
  228. data/lib/active_merchant/billing/gateways/transax.rb +6 -8
  229. data/lib/active_merchant/billing/gateways/transnational.rb +1 -2
  230. data/lib/active_merchant/billing/gateways/trexle.rb +221 -0
  231. data/lib/active_merchant/billing/gateways/trust_commerce.rb +162 -89
  232. data/lib/active_merchant/billing/gateways/usa_epay.rb +5 -6
  233. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +332 -236
  234. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +185 -72
  235. data/lib/active_merchant/billing/gateways/vanco.rb +294 -0
  236. data/lib/active_merchant/billing/gateways/verifi.rb +52 -53
  237. data/lib/active_merchant/billing/gateways/viaklix.rb +19 -31
  238. data/lib/active_merchant/billing/gateways/visanet_peru.rb +250 -0
  239. data/lib/active_merchant/billing/gateways/vpos.rb +220 -0
  240. data/lib/active_merchant/billing/gateways/webpay.rb +9 -9
  241. data/lib/active_merchant/billing/gateways/wepay.rb +108 -62
  242. data/lib/active_merchant/billing/gateways/wirecard.rb +52 -43
  243. data/lib/active_merchant/billing/gateways/wompi.rb +193 -0
  244. data/lib/active_merchant/billing/gateways/world_net.rb +345 -0
  245. data/lib/active_merchant/billing/gateways/worldpay.rb +725 -121
  246. data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +208 -0
  247. data/lib/active_merchant/billing/gateways/worldpay_us.rb +79 -39
  248. data/lib/active_merchant/billing/gateways.rb +8 -11
  249. data/lib/active_merchant/billing/model.rb +2 -2
  250. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +39 -0
  251. data/lib/active_merchant/billing/payment_token.rb +1 -1
  252. data/lib/active_merchant/billing/rails.rb +1 -1
  253. data/lib/active_merchant/billing/response.rb +19 -13
  254. data/lib/active_merchant/billing/three_d_secure_eci_mapper.rb +27 -0
  255. data/lib/active_merchant/billing.rb +3 -0
  256. data/lib/active_merchant/connection.rb +196 -0
  257. data/lib/active_merchant/country.rb +13 -8
  258. data/lib/active_merchant/errors.rb +6 -0
  259. data/lib/active_merchant/net_http_ssl_connection.rb +11 -0
  260. data/lib/active_merchant/network_connection_retries.rb +78 -0
  261. data/lib/active_merchant/post_data.rb +26 -0
  262. data/lib/active_merchant/posts_data.rb +92 -0
  263. data/lib/active_merchant/version.rb +1 -1
  264. data/lib/active_merchant.rb +14 -59
  265. data/lib/activemerchant.rb +1 -1
  266. data/lib/certs/cacert.pem +3214 -0
  267. data/lib/support/gateway_support.rb +8 -10
  268. data/lib/support/outbound_hosts.rb +13 -10
  269. data/lib/support/ssl_verify.rb +9 -14
  270. data/lib/support/ssl_version.rb +86 -0
  271. metadata +136 -94
  272. checksums.yaml.gz.sig +0 -1
  273. data/lib/active_merchant/billing/gateways/app55.rb +0 -176
  274. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +0 -314
  275. data/lib/active_merchant/billing/gateways/certo_direct.rb +0 -278
  276. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +0 -246
  277. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +0 -13
  278. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +0 -29
  279. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +0 -66
  280. data/lib/active_merchant/billing/gateways/moneris_us.rb +0 -291
  281. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +0 -87
  282. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +0 -114
  283. data/lib/active_merchant/billing/gateways/sage/sage_vault.rb +0 -149
  284. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +0 -102
  285. data/lib/active_merchant/billing/gateways/vindicia.rb +0 -385
  286. data/lib/active_merchant/offsite_payments_shim.rb +0 -19
  287. data.tar.gz.sig +0 -0
  288. metadata.gz.sig +0 -0
@@ -0,0 +1,516 @@
1
+ require 'active_support/core_ext/hash/slice'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ # This gateway uses the current Stripe {Payment Intents API}[https://stripe.com/docs/api/payment_intents].
6
+ # For the legacy API, see the Stripe gateway
7
+ class StripePaymentIntentsGateway < StripeGateway
8
+ ALLOWED_METHOD_STATES = %w[automatic manual].freeze
9
+ ALLOWED_CANCELLATION_REASONS = %w[duplicate fraudulent requested_by_customer abandoned].freeze
10
+ CREATE_INTENT_ATTRIBUTES = %i[description statement_descriptor_suffix statement_descriptor receipt_email save_payment_method]
11
+ CONFIRM_INTENT_ATTRIBUTES = %i[receipt_email return_url save_payment_method setup_future_usage off_session]
12
+ UPDATE_INTENT_ATTRIBUTES = %i[description statement_descriptor_suffix statement_descriptor receipt_email setup_future_usage]
13
+ DEFAULT_API_VERSION = '2020-08-27'
14
+
15
+ def create_intent(money, payment_method, options = {})
16
+ MultiResponse.run do |r|
17
+ if payment_method.is_a?(NetworkTokenizationCreditCard)
18
+ r.process { tokenize_apple_google(payment_method, options) }
19
+ payment_method = (r.params['token']['id']) if r.success?
20
+ end
21
+ r.process do
22
+ post = {}
23
+ add_amount(post, money, options, true)
24
+ add_capture_method(post, options)
25
+ add_confirmation_method(post, options)
26
+ add_customer(post, options)
27
+
28
+ result = add_payment_method_token(post, payment_method, options)
29
+ return result if result.is_a?(ActiveMerchant::Billing::Response)
30
+
31
+ add_external_three_d_secure_auth_data(post, options)
32
+ add_metadata(post, options)
33
+ add_return_url(post, options)
34
+ add_connected_account(post, options)
35
+ add_radar_data(post, options)
36
+ add_shipping_address(post, options)
37
+ setup_future_usage(post, options)
38
+ add_exemption(post, options)
39
+ add_stored_credentials(post, options)
40
+ add_ntid(post, options)
41
+ add_claim_without_transaction_id(post, options)
42
+ add_error_on_requires_action(post, options)
43
+ add_fulfillment_date(post, options)
44
+ request_three_d_secure(post, options)
45
+
46
+ CREATE_INTENT_ATTRIBUTES.each do |attribute|
47
+ add_whitelisted_attribute(post, options, attribute)
48
+ end
49
+ commit(:post, 'payment_intents', post, options)
50
+ end
51
+ end
52
+ end
53
+
54
+ def show_intent(intent_id, options)
55
+ commit(:get, "payment_intents/#{intent_id}", nil, options)
56
+ end
57
+
58
+ def confirm_intent(intent_id, payment_method, options = {})
59
+ post = {}
60
+ result = add_payment_method_token(post, payment_method, options)
61
+ return result if result.is_a?(ActiveMerchant::Billing::Response)
62
+
63
+ add_payment_method_types(post, options)
64
+ CONFIRM_INTENT_ATTRIBUTES.each do |attribute|
65
+ add_whitelisted_attribute(post, options, attribute)
66
+ end
67
+
68
+ commit(:post, "payment_intents/#{intent_id}/confirm", post, options)
69
+ end
70
+
71
+ def create_payment_method(payment_method, options = {})
72
+ post_data = add_payment_method_data(payment_method, options)
73
+
74
+ options = format_idempotency_key(options, 'pm')
75
+ commit(:post, 'payment_methods', post_data, options)
76
+ end
77
+
78
+ def add_payment_method_data(payment_method, options = {})
79
+ post_data = {}
80
+ post_data[:type] = 'card'
81
+ post_data[:card] = {}
82
+ post_data[:card][:number] = payment_method.number
83
+ post_data[:card][:exp_month] = payment_method.month
84
+ post_data[:card][:exp_year] = payment_method.year
85
+ post_data[:card][:cvc] = payment_method.verification_value if payment_method.verification_value
86
+ add_billing_address(post_data, options)
87
+ add_name_only(post_data, payment_method) if post_data[:billing_details].nil?
88
+ post_data
89
+ end
90
+
91
+ def add_payment_method_card_data_token(post_data, payment_method)
92
+ post_data.merge!({
93
+ payment_method_types: ['card'],
94
+ payment_method_data: { type: 'card', card: { token: payment_method } }
95
+ })
96
+ end
97
+
98
+ def update_intent(money, intent_id, payment_method, options = {})
99
+ post = {}
100
+ add_amount(post, money, options)
101
+
102
+ result = add_payment_method_token(post, payment_method, options)
103
+ return result if result.is_a?(ActiveMerchant::Billing::Response)
104
+
105
+ add_payment_method_types(post, options)
106
+ add_customer(post, options)
107
+ add_metadata(post, options)
108
+ add_shipping_address(post, options)
109
+ add_connected_account(post, options)
110
+ add_fulfillment_date(post, options)
111
+
112
+ UPDATE_INTENT_ATTRIBUTES.each do |attribute|
113
+ add_whitelisted_attribute(post, options, attribute)
114
+ end
115
+ commit(:post, "payment_intents/#{intent_id}", post, options)
116
+ end
117
+
118
+ def create_setup_intent(payment_method, options = {})
119
+ post = {}
120
+ add_customer(post, options)
121
+ result = add_payment_method_token(post, payment_method, options)
122
+ return result if result.is_a?(ActiveMerchant::Billing::Response)
123
+
124
+ add_metadata(post, options)
125
+ add_return_url(post, options)
126
+ add_fulfillment_date(post, options)
127
+ request_three_d_secure(post, options)
128
+ post[:on_behalf_of] = options[:on_behalf_of] if options[:on_behalf_of]
129
+ post[:usage] = options[:usage] if %w(on_session off_session).include?(options[:usage])
130
+ post[:description] = options[:description] if options[:description]
131
+
132
+ commit(:post, 'setup_intents', post, options)
133
+ end
134
+
135
+ def retrieve_setup_intent(setup_intent_id)
136
+ # Retrieving a setup_intent passing 'expand[]=latest_attempt' allows the caller to
137
+ # check for a network_transaction_id and ds_transaction_id
138
+ # eg (latest_attempt -> payment_method_details -> card -> network_transaction_id)
139
+ #
140
+ # Being able to retrieve these fields enables payment flows that rely on MIT exemptions, e.g: off_session
141
+ commit(:post, "setup_intents/#{setup_intent_id}", {
142
+ 'expand[]': 'latest_attempt'
143
+ }, {})
144
+ end
145
+
146
+ def authorize(money, payment_method, options = {})
147
+ create_intent(money, payment_method, options.merge!(confirm: true, capture_method: 'manual'))
148
+ end
149
+
150
+ def purchase(money, payment_method, options = {})
151
+ create_intent(money, payment_method, options.merge!(confirm: true, capture_method: 'automatic'))
152
+ end
153
+
154
+ def capture(money, intent_id, options = {})
155
+ post = {}
156
+ currency = options[:currency] || currency(money)
157
+ post[:amount_to_capture] = localized_amount(money, currency)
158
+ if options[:transfer_amount]
159
+ post[:transfer_data] = {}
160
+ post[:transfer_data][:amount] = options[:transfer_amount]
161
+ end
162
+ post[:application_fee_amount] = options[:application_fee] if options[:application_fee]
163
+ options = format_idempotency_key(options, 'capture')
164
+ commit(:post, "payment_intents/#{intent_id}/capture", post, options)
165
+ end
166
+
167
+ def void(intent_id, options = {})
168
+ post = {}
169
+ post[:cancellation_reason] = options[:cancellation_reason] if ALLOWED_CANCELLATION_REASONS.include?(options[:cancellation_reason])
170
+ commit(:post, "payment_intents/#{intent_id}/cancel", post, options)
171
+ end
172
+
173
+ def refund(money, intent_id, options = {})
174
+ if intent_id.include?('pi_')
175
+ intent = api_request(:get, "payment_intents/#{intent_id}", nil, options)
176
+
177
+ return Response.new(false, intent['error']['message'], intent) if intent['error']
178
+
179
+ charge_id = intent.try(:[], 'charges').try(:[], 'data').try(:[], 0).try(:[], 'id')
180
+
181
+ if charge_id.nil?
182
+ error_message = "No associated charge for #{intent['id']}"
183
+ error_message << "; payment_intent has a status of #{intent['status']}" if intent.try(:[], 'status') && intent.try(:[], 'status') != 'succeeded'
184
+ return Response.new(false, error_message, intent)
185
+ end
186
+ else
187
+ charge_id = intent_id
188
+ end
189
+
190
+ super(money, charge_id, options)
191
+ end
192
+
193
+ # Note: Not all payment methods are currently supported by the {Payment Methods API}[https://stripe.com/docs/payments/payment-methods]
194
+ # Current implementation will create a PaymentMethod object if the method is a token or credit card
195
+ # All other types will default to legacy Stripe store
196
+ def store(payment_method, options = {})
197
+ params = {}
198
+ post = {}
199
+ # If customer option is provided, create a payment method and attach to customer id
200
+ # Otherwise, create a customer, then attach
201
+ if payment_method.is_a?(StripePaymentToken) || payment_method.is_a?(ActiveMerchant::Billing::CreditCard)
202
+ result = add_payment_method_token(params, payment_method, options)
203
+ return result if result.is_a?(ActiveMerchant::Billing::Response)
204
+
205
+ if options[:customer]
206
+ customer_id = options[:customer]
207
+ else
208
+ post[:description] = options[:description] if options[:description]
209
+ post[:email] = options[:email] if options[:email]
210
+ options = format_idempotency_key(options, 'customer')
211
+ post[:expand] = [:sources]
212
+ customer = commit(:post, 'customers', post, options)
213
+ customer_id = customer.params['id']
214
+ end
215
+ options = format_idempotency_key(options, 'attach')
216
+ attach_parameters = { customer: customer_id }
217
+ attach_parameters[:validate] = options[:validate] unless options[:validate].nil?
218
+ commit(:post, "payment_methods/#{params[:payment_method]}/attach", attach_parameters, options)
219
+ else
220
+ super(payment_method, options)
221
+ end
222
+ end
223
+
224
+ def unstore(identification, options = {}, deprecated_options = {})
225
+ if identification.include?('pm_')
226
+ _, payment_method = identification.split('|')
227
+ commit(:post, "payment_methods/#{payment_method}/detach", nil, options)
228
+ else
229
+ super(identification, options, deprecated_options)
230
+ end
231
+ end
232
+
233
+ def verify(payment_method, options = {})
234
+ create_setup_intent(payment_method, options.merge!(confirm: true))
235
+ end
236
+
237
+ def setup_purchase(money, options = {})
238
+ requires!(options, :payment_method_types)
239
+ post = {}
240
+ add_currency(post, options, money)
241
+ add_amount(post, money, options)
242
+ add_payment_method_types(post, options)
243
+ add_metadata(post, options)
244
+ commit(:post, 'payment_intents', post, options)
245
+ end
246
+
247
+ private
248
+
249
+ def off_session_request?(options = {})
250
+ (options[:off_session] || options[:setup_future_usage]) && options[:confirm] == true
251
+ end
252
+
253
+ def add_connected_account(post, options = {})
254
+ super(post, options)
255
+ post[:application_fee_amount] = options[:application_fee] if options[:application_fee]
256
+ end
257
+
258
+ def add_whitelisted_attribute(post, options, attribute)
259
+ post[attribute] = options[attribute] if options[attribute]
260
+ end
261
+
262
+ def add_capture_method(post, options)
263
+ capture_method = options[:capture_method].to_s
264
+ post[:capture_method] = capture_method if ALLOWED_METHOD_STATES.include?(capture_method)
265
+ end
266
+
267
+ def add_confirmation_method(post, options)
268
+ confirmation_method = options[:confirmation_method].to_s
269
+ post[:confirmation_method] = confirmation_method if ALLOWED_METHOD_STATES.include?(confirmation_method)
270
+ end
271
+
272
+ def add_customer(post, options)
273
+ customer = options[:customer].to_s
274
+ post[:customer] = customer if customer.start_with?('cus_')
275
+ end
276
+
277
+ def add_fulfillment_date(post, options)
278
+ post[:fulfillment_date] = options[:fulfillment_date].to_i if options[:fulfillment_date]
279
+ end
280
+
281
+ def add_metadata(post, options = {})
282
+ super
283
+
284
+ post[:metadata][:event_type] = options[:event_type] if options[:event_type]
285
+ end
286
+
287
+ def add_return_url(post, options)
288
+ return unless options[:confirm]
289
+
290
+ post[:confirm] = options[:confirm]
291
+ post[:return_url] = options[:return_url] if options[:return_url]
292
+ end
293
+
294
+ def add_payment_method_token(post, payment_method, options)
295
+ case payment_method
296
+ when StripePaymentToken
297
+ post[:payment_method_data] = {
298
+ type: 'card',
299
+ card: {
300
+ token: payment_method.payment_data['id'] || payment_method.payment_data
301
+ }
302
+ }
303
+ post[:payment_method] = payment_method.payment_data['id'] || payment_method.payment_data
304
+ when String
305
+ extract_token_from_string_and_maybe_add_customer_id(post, payment_method)
306
+ when ActiveMerchant::Billing::CreditCard
307
+ get_payment_method_data_from_card(post, payment_method, options)
308
+ end
309
+ end
310
+
311
+ def extract_token_from_string_and_maybe_add_customer_id(post, payment_method)
312
+ if payment_method.include?('|')
313
+ customer_id, payment_method = payment_method.split('|')
314
+ post[:customer] = customer_id
315
+ end
316
+
317
+ if payment_method.include?('tok_')
318
+ add_payment_method_card_data_token(post, payment_method)
319
+ else
320
+ post[:payment_method] = payment_method
321
+ end
322
+ end
323
+
324
+ def tokenize_apple_google(payment, options = {})
325
+ tokenization_method = payment.source == :google_pay ? :android_pay : payment.source
326
+ post = {
327
+ card: {
328
+ number: payment.number,
329
+ exp_month: payment.month,
330
+ exp_year: payment.year,
331
+ tokenization_method: tokenization_method,
332
+ eci: payment.eci,
333
+ cryptogram: payment.payment_cryptogram
334
+ }
335
+ }
336
+ token_response = api_request(:post, 'tokens', post, options)
337
+ success = token_response['error'].nil?
338
+ if success && token_response['id']
339
+ Response.new(success, nil, token: token_response)
340
+ elsif token_response['error']['message']
341
+ Response.new(false, "The tokenization process fails. #{token_response['error']['message']}")
342
+ else
343
+ Response.new(false, "The tokenization process fails. #{token_response}")
344
+ end
345
+ end
346
+
347
+ def get_payment_method_data_from_card(post, payment_method, options)
348
+ return create_payment_method_and_extract_token(post, payment_method, options) unless off_session_request?(options)
349
+
350
+ post[:payment_method_data] = add_payment_method_data(payment_method, options)
351
+ end
352
+
353
+ def create_payment_method_and_extract_token(post, payment_method, options)
354
+ payment_method_response = create_payment_method(payment_method, options)
355
+ return payment_method_response if payment_method_response.failure?
356
+
357
+ add_payment_method_token(post, payment_method_response.params['id'], options)
358
+ end
359
+
360
+ def add_payment_method_types(post, options)
361
+ payment_method_types = options[:payment_method_types] if options[:payment_method_types]
362
+ return if payment_method_types.nil?
363
+
364
+ post[:payment_method_types] = Array(payment_method_types)
365
+ end
366
+
367
+ def add_exemption(post, options = {})
368
+ return unless options[:confirm]
369
+
370
+ post[:payment_method_options] ||= {}
371
+ post[:payment_method_options][:card] ||= {}
372
+ post[:payment_method_options][:card][:moto] = true if options[:moto]
373
+ end
374
+
375
+ # Stripe Payment Intents does not pass any parameters for cardholder/merchant initiated
376
+ # it also does not support installments for any country other than Mexico (reason for this is unknown)
377
+ # The only thing that Stripe PI requires for stored credentials to work currently is the network_transaction_id
378
+ # network_transaction_id is created when the card is authenticated using the field `setup_for_future_usage` with the value `off_session` see def setup_future_usage below
379
+
380
+ def add_stored_credentials(post, options = {})
381
+ return unless options[:stored_credential] && !options[:stored_credential].values.all?(&:nil?)
382
+
383
+ stored_credential = options[:stored_credential]
384
+ post[:payment_method_options] ||= {}
385
+ post[:payment_method_options][:card] ||= {}
386
+ post[:payment_method_options][:card][:mit_exemption] = {}
387
+
388
+ # Stripe PI accepts network_transaction_id and ds_transaction_id via mit field under card.
389
+ # The network_transaction_id can be sent in nested under stored credentials OR as its own field (add_ntid handles when it is sent in on its own)
390
+ # If it is sent is as its own field AND under stored credentials, the value sent under its own field is what will send.
391
+ post[:payment_method_options][:card][:mit_exemption][:ds_transaction_id] = stored_credential[:ds_transaction_id] if stored_credential[:ds_transaction_id]
392
+ post[:payment_method_options][:card][:mit_exemption][:network_transaction_id] = stored_credential[:network_transaction_id] if stored_credential[:network_transaction_id]
393
+ end
394
+
395
+ def add_ntid(post, options = {})
396
+ return unless options[:network_transaction_id]
397
+
398
+ post[:payment_method_options] ||= {}
399
+ post[:payment_method_options][:card] ||= {}
400
+ post[:payment_method_options][:card][:mit_exemption] = {}
401
+
402
+ post[:payment_method_options][:card][:mit_exemption][:network_transaction_id] = options[:network_transaction_id] if options[:network_transaction_id]
403
+ end
404
+
405
+ def add_claim_without_transaction_id(post, options = {})
406
+ return if options[:stored_credential] || options[:network_transaction_id] || options[:ds_transaction_id]
407
+ return unless options[:claim_without_transaction_id]
408
+
409
+ post[:payment_method_options] ||= {}
410
+ post[:payment_method_options][:card] ||= {}
411
+ post[:payment_method_options][:card][:mit_exemption] = {}
412
+
413
+ # Stripe PI accepts claim_without_transaction_id for transactions without transaction ids.
414
+ # Gateway validation for this field occurs through a different service, before the transaction request is sent to the gateway.
415
+ post[:payment_method_options][:card][:mit_exemption][:claim_without_transaction_id] = options[:claim_without_transaction_id]
416
+ end
417
+
418
+ def add_error_on_requires_action(post, options = {})
419
+ return unless options[:confirm]
420
+
421
+ post[:error_on_requires_action] = true if options[:error_on_requires_action]
422
+ end
423
+
424
+ def request_three_d_secure(post, options = {})
425
+ return unless options[:request_three_d_secure] && %w(any automatic).include?(options[:request_three_d_secure])
426
+
427
+ post[:payment_method_options] ||= {}
428
+ post[:payment_method_options][:card] ||= {}
429
+ post[:payment_method_options][:card][:request_three_d_secure] = options[:request_three_d_secure]
430
+ end
431
+
432
+ def add_external_three_d_secure_auth_data(post, options = {})
433
+ return unless options[:three_d_secure]&.is_a?(Hash)
434
+
435
+ three_d_secure = options[:three_d_secure]
436
+ post[:payment_method_options] ||= {}
437
+ post[:payment_method_options][:card] ||= {}
438
+ post[:payment_method_options][:card][:three_d_secure] ||= {}
439
+ post[:payment_method_options][:card][:three_d_secure][:version] = three_d_secure[:version] || (three_d_secure[:ds_transaction_id] ? '2.2.0' : '1.0.2')
440
+ post[:payment_method_options][:card][:three_d_secure][:electronic_commerce_indicator] = three_d_secure[:eci] if three_d_secure[:eci]
441
+ post[:payment_method_options][:card][:three_d_secure][:cryptogram] = three_d_secure[:cavv] if three_d_secure[:cavv]
442
+ post[:payment_method_options][:card][:three_d_secure][:transaction_id] = three_d_secure[:ds_transaction_id] || three_d_secure[:xid]
443
+ end
444
+
445
+ def setup_future_usage(post, options = {})
446
+ post[:setup_future_usage] = options[:setup_future_usage] if %w(on_session off_session).include?(options[:setup_future_usage])
447
+ post[:off_session] = options[:off_session] if off_session_request?(options)
448
+ post
449
+ end
450
+
451
+ def add_billing_address(post, options = {})
452
+ return unless billing = options[:billing_address] || options[:address]
453
+
454
+ post[:billing_details] = {}
455
+ post[:billing_details][:address] = {}
456
+ post[:billing_details][:address][:city] = billing[:city] if billing[:city]
457
+ post[:billing_details][:address][:country] = billing[:country] if billing[:country]
458
+ post[:billing_details][:address][:line1] = billing[:address1] if billing[:address1]
459
+ post[:billing_details][:address][:line2] = billing[:address2] if billing[:address2]
460
+ post[:billing_details][:address][:postal_code] = billing[:zip] if billing[:zip]
461
+ post[:billing_details][:address][:state] = billing[:state] if billing[:state]
462
+ post[:billing_details][:email] = billing[:email] if billing[:email]
463
+ post[:billing_details][:name] = billing[:name] if billing[:name]
464
+ post[:billing_details][:phone] = billing[:phone] if billing[:phone]
465
+ end
466
+
467
+ def add_name_only(post, payment_method)
468
+ post[:billing_details] = {} unless post[:billing_details]
469
+
470
+ name = [payment_method.first_name, payment_method.last_name].compact.join(' ')
471
+ post[:billing_details][:name] = name
472
+ end
473
+
474
+ def add_shipping_address(post, options = {})
475
+ return unless shipping = options[:shipping_address]
476
+
477
+ post[:shipping] = {}
478
+
479
+ # fields required by Stripe PI
480
+ post[:shipping][:address] = {}
481
+ post[:shipping][:address][:line1] = shipping[:address1]
482
+ post[:shipping][:name] = shipping[:name]
483
+
484
+ # fields considered optional by Stripe PI
485
+ post[:shipping][:address][:city] = shipping[:city] if shipping[:city]
486
+ post[:shipping][:address][:country] = shipping[:country] if shipping[:country]
487
+ post[:shipping][:address][:line2] = shipping[:address2] if shipping[:address2]
488
+ post[:shipping][:address][:postal_code] = shipping[:zip] if shipping[:zip]
489
+ post[:shipping][:address][:state] = shipping[:state] if shipping[:state]
490
+ post[:shipping][:phone] = shipping[:phone_number] if shipping[:phone_number]
491
+ post[:shipping][:carrier] = (shipping[:carrier] || options[:shipping_carrier]) if shipping[:carrier] || options[:shipping_carrier]
492
+ post[:shipping][:tracking_number] = (shipping[:tracking_number] || options[:shipping_tracking_number]) if shipping[:tracking_number] || options[:shipping_tracking_number]
493
+ end
494
+
495
+ def format_idempotency_key(options, suffix)
496
+ return options unless options[:idempotency_key]
497
+
498
+ options.merge(idempotency_key: "#{options[:idempotency_key]}-#{suffix}")
499
+ end
500
+
501
+ def success_from(response, options)
502
+ if response['status'] == 'requires_action' && !options[:execute_threed]
503
+ response['error'] = {}
504
+ response['error']['message'] = 'Received unexpected 3DS authentication response. Use the execute_threed option to initiate a proper 3DS flow.'
505
+ return false
506
+ end
507
+
508
+ super(response, options)
509
+ end
510
+
511
+ def add_currency(post, options, money)
512
+ post[:currency] = options[:currency] || currency(money)
513
+ end
514
+ end
515
+ end
516
+ end
@@ -6,17 +6,14 @@ module ActiveMerchant #:nodoc:
6
6
  TRANSACTION_APPROVED_MSG = 'Transaction approved'
7
7
  TRANSACTION_DECLINED_MSG = 'Transaction declined'
8
8
 
9
- LIVE_URLS = {
10
- 'NZ' => 'https://api.swipehq.com',
11
- 'CA' => 'https://api.swipehq.ca'
12
- }
9
+ self.live_url = 'https://api.swipehq.com'
13
10
  self.test_url = 'https://api.swipehq.com'
14
11
 
15
12
  TRANSACTION_API = '/createShopifyTransaction.php'
16
13
 
17
- self.supported_countries = %w[ NZ CA ]
14
+ self.supported_countries = %w[NZ CA]
18
15
  self.default_currency = 'NZD'
19
- self.supported_cardtypes = [:visa, :master]
16
+ self.supported_cardtypes = %i[visa master]
20
17
  self.homepage_url = 'https://www.swipehq.com/checkout'
21
18
  self.display_name = 'Swipe Checkout'
22
19
  self.money_format = :dollars
@@ -57,12 +54,11 @@ module ActiveMerchant #:nodoc:
57
54
 
58
55
  post[:company] = address[:company]
59
56
 
60
- # groups all names after the first into the last name param
61
- post[:first_name], post[:last_name] = address[:name].split(' ', 2)
57
+ post[:first_name], post[:last_name] = split_names(address[:name])
62
58
  post[:address] = "#{address[:address1]}, #{address[:address2]}"
63
59
  post[:city] = address[:city]
64
60
  post[:country] = address[:country]
65
- post[:mobile] = address[:phone] # API only has a "mobile" field, no "phone"
61
+ post[:mobile] = address[:phone] # API only has a "mobile" field, no "phone"
66
62
  end
67
63
 
68
64
  def add_invoice(post, options)
@@ -70,7 +66,7 @@ module ActiveMerchant #:nodoc:
70
66
  post[:td_user_data] = options[:order_id] if options[:order_id]
71
67
  post[:td_item] = options[:description] if options[:description]
72
68
  post[:td_description] = options[:description] if options[:description]
73
- post[:item_quantity] = "1"
69
+ post[:item_quantity] = '1'
74
70
  end
75
71
 
76
72
  def add_creditcard(post, creditcard)
@@ -96,16 +92,16 @@ module ActiveMerchant #:nodoc:
96
92
 
97
93
  def commit(action, money, parameters)
98
94
  case action
99
- when "sale"
95
+ when 'sale'
100
96
  begin
101
97
  response = call_api(TRANSACTION_API, parameters)
102
98
 
103
99
  # response code and message params should always be present
104
- code = response["response_code"]
105
- message = response["message"]
100
+ code = response['response_code']
101
+ message = response['message']
106
102
 
107
103
  if code == 200
108
- result = response["data"]["result"]
104
+ result = response['data']['result']
109
105
  success = (result == 'accepted' || (test? && result == 'test-accepted'))
110
106
 
111
107
  Response.new(success,
@@ -113,45 +109,43 @@ module ActiveMerchant #:nodoc:
113
109
  TRANSACTION_APPROVED_MSG :
114
110
  TRANSACTION_DECLINED_MSG,
115
111
  response,
116
- :test => test?
117
- )
112
+ test: test?)
118
113
  else
119
114
  build_error_response(message, response)
120
115
  end
121
116
  rescue ResponseError => e
122
117
  build_error_response("ssl_post() with url #{url} raised ResponseError: #{e}")
123
118
  rescue JSON::ParserError => e
124
- msg = 'Invalid response received from the Swipe Checkout API. ' +
125
- 'Please contact support@optimizerhq.com if you continue to receive this message.' +
119
+ msg = 'Invalid response received from the Swipe Checkout API. ' \
120
+ 'Please contact support@optimizerhq.com if you continue to receive this message.' \
126
121
  " (Full error message: #{e})"
127
122
  build_error_response(msg)
128
123
  end
129
124
  end
130
125
  end
131
126
 
132
- def call_api(api, params=nil)
127
+ def call_api(api, params = nil)
133
128
  params ||= {}
134
129
  params[:merchant_id] = @options[:login]
135
130
  params[:api_key] = @options[:api_key]
136
131
 
137
132
  # ssl_post() returns the response body as a string on success,
138
133
  # or raises a ResponseError exception on failure
139
- JSON.parse(ssl_post(url(@options[:region], api), params.to_query))
134
+ JSON.parse(ssl_post(url(api), params.to_query))
140
135
  end
141
136
 
142
- def url(region, api)
143
- ((test? ? self.test_url : LIVE_URLS[region]) + api)
137
+ def url(api)
138
+ (test? ? self.test_url : self.live_url) + api
144
139
  end
145
140
 
146
- def build_error_response(message, params={})
141
+ def build_error_response(message, params = {})
147
142
  Response.new(
148
143
  false,
149
144
  message,
150
145
  params,
151
- :test => test?
146
+ test: test?
152
147
  )
153
148
  end
154
149
  end
155
150
  end
156
151
  end
157
-