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
@@ -2,6 +2,8 @@ require 'active_support/core_ext/hash/slice'
2
2
 
3
3
  module ActiveMerchant #:nodoc:
4
4
  module Billing #:nodoc:
5
+ # This gateway uses an older version of the Stripe API.
6
+ # To utilize the updated {Payment Intents API}[https://stripe.com/docs/api/payment_intents], integrate with the StripePaymentIntents gateway
5
7
  class StripeGateway < Gateway
6
8
  self.live_url = 'https://api.stripe.com/v1/'
7
9
 
@@ -21,13 +23,13 @@ module ActiveMerchant #:nodoc:
21
23
  'unchecked' => 'P'
22
24
  }
23
25
 
24
- # Source: https://support.stripe.com/questions/which-zero-decimal-currencies-does-stripe-support
25
- CURRENCIES_WITHOUT_FRACTIONS = ['BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VUV', 'XAF', 'XOF', 'XPF']
26
+ DEFAULT_API_VERSION = '2020-08-27'
26
27
 
27
- self.supported_countries = %w(AU BE CA CH DE ES FI FR GB IE IT LU NL US)
28
+ self.supported_countries = %w(AE AT AU BE BG BR CA CH CY CZ DE DK EE ES FI FR GB GR HK HU IE IN IT JP LT LU LV MT MX MY NL NO NZ PL PT RO SE SG SI SK US)
28
29
  self.default_currency = 'USD'
29
30
  self.money_format = :cents
30
- self.supported_cardtypes = [:visa, :master, :american_express, :discover, :jcb, :diners_club]
31
+ self.supported_cardtypes = %i[visa master american_express discover jcb diners_club maestro unionpay]
32
+ self.currencies_without_fractions = %w(BIF CLP DJF GNF JPY KMF KRW MGA PYG RWF VND VUV XAF XOF XPF UGX)
31
33
 
32
34
  self.homepage_url = 'https://stripe.com/'
33
35
  self.display_name = 'Stripe'
@@ -42,27 +44,57 @@ module ActiveMerchant #:nodoc:
42
44
  'incorrect_cvc' => STANDARD_ERROR_CODE[:incorrect_cvc],
43
45
  'incorrect_zip' => STANDARD_ERROR_CODE[:incorrect_zip],
44
46
  'card_declined' => STANDARD_ERROR_CODE[:card_declined],
45
- 'processing_error' => STANDARD_ERROR_CODE[:processing_error]
47
+ 'call_issuer' => STANDARD_ERROR_CODE[:call_issuer],
48
+ 'processing_error' => STANDARD_ERROR_CODE[:processing_error],
49
+ 'incorrect_pin' => STANDARD_ERROR_CODE[:incorrect_pin],
50
+ 'test_mode_live_card' => STANDARD_ERROR_CODE[:test_mode_live_card],
51
+ 'pickup_card' => STANDARD_ERROR_CODE[:pickup_card],
52
+ 'amount_too_small' => STANDARD_ERROR_CODE[:invalid_amount]
53
+ }
54
+
55
+ BANK_ACCOUNT_HOLDER_TYPE_MAPPING = {
56
+ 'personal' => 'individual',
57
+ 'business' => 'company'
58
+ }
59
+
60
+ MINIMUM_AUTHORIZE_AMOUNTS = {
61
+ 'USD' => 100,
62
+ 'CAD' => 100,
63
+ 'GBP' => 60,
64
+ 'EUR' => 100,
65
+ 'DKK' => 500,
66
+ 'NOK' => 600,
67
+ 'SEK' => 600,
68
+ 'CHF' => 100,
69
+ 'AUD' => 100,
70
+ 'JPY' => 100,
71
+ 'MXN' => 2000,
72
+ 'SGD' => 100,
73
+ 'HKD' => 800
46
74
  }
47
75
 
48
76
  def initialize(options = {})
49
77
  requires!(options, :login)
50
78
  @api_key = options[:login]
51
79
  @fee_refund_api_key = options[:fee_refund_login]
52
- @version = options[:version]
53
-
54
80
  super
55
81
  end
56
82
 
57
83
  def authorize(money, payment, options = {})
84
+ if ach?(payment)
85
+ direct_bank_error = 'Direct bank account transactions are not supported for authorize.'
86
+ return Response.new(false, direct_bank_error)
87
+ end
88
+
58
89
  MultiResponse.run do |r|
59
90
  if payment.is_a?(ApplePayPaymentToken)
60
91
  r.process { tokenize_apple_pay_token(payment) }
61
- payment = StripePaymentToken.new(r.params["token"]) if r.success?
92
+ payment = StripePaymentToken.new(r.params['token']) if r.success?
62
93
  end
63
- r.process do |r|
94
+ r.process do
64
95
  post = create_post_for_auth_or_purchase(money, payment, options)
65
- post[:capture] = "false"
96
+ add_application_fee(post, options) if emv_payment?(payment)
97
+ post[:capture] = 'false'
66
98
  commit(:post, 'charges', post, options)
67
99
  end
68
100
  end.responses.last
@@ -76,13 +108,19 @@ module ActiveMerchant #:nodoc:
76
108
  #
77
109
  # purchase(money, nil, { :customer => id, ... })
78
110
  def purchase(money, payment, options = {})
111
+ if ach?(payment)
112
+ direct_bank_error = 'Direct bank account transactions are not supported. Bank accounts must be stored and verified before use.'
113
+ return Response.new(false, direct_bank_error)
114
+ end
115
+
79
116
  MultiResponse.run do |r|
80
117
  if payment.is_a?(ApplePayPaymentToken)
81
118
  r.process { tokenize_apple_pay_token(payment) }
82
- payment = StripePaymentToken.new(r.params["token"]) if r.success?
119
+ payment = StripePaymentToken.new(r.params['token']) if r.success?
83
120
  end
84
- r.process do |r|
121
+ r.process do
85
122
  post = create_post_for_auth_or_purchase(money, payment, options)
123
+ post[:card][:processing_method] = 'quick_chip' if quickchip_payment?(payment)
86
124
  commit(:post, 'charges', post, options)
87
125
  end
88
126
  end.responses.last
@@ -90,85 +128,107 @@ module ActiveMerchant #:nodoc:
90
128
 
91
129
  def capture(money, authorization, options = {})
92
130
  post = {}
93
- add_amount(post, money, options)
94
- add_application_fee(post, options)
131
+
132
+ if emv_tc_response = options.delete(:icc_data)
133
+ # update the charge with emv data if card present
134
+ update = {}
135
+ update[:card] = { emv_approval_data: emv_tc_response }
136
+ commit(:post, "charges/#{CGI.escape(authorization)}", update, options)
137
+ else
138
+ add_application_fee(post, options)
139
+ add_amount(post, money, options)
140
+ add_exchange_rate(post, options)
141
+ end
95
142
 
96
143
  commit(:post, "charges/#{CGI.escape(authorization)}/capture", post, options)
97
144
  end
98
145
 
99
146
  def void(identification, options = {})
100
- commit(:post, "charges/#{CGI.escape(identification)}/refund", {}, options)
147
+ post = {}
148
+ post[:metadata] = options[:metadata] if options[:metadata]
149
+ post[:reason] = options[:reason] if options[:reason]
150
+ post[:expand] = [:charge]
151
+ commit(:post, "charges/#{CGI.escape(identification)}/refunds", post, options)
101
152
  end
102
153
 
103
154
  def refund(money, identification, options = {})
104
155
  post = {}
105
156
  add_amount(post, money, options)
106
157
  post[:refund_application_fee] = true if options[:refund_application_fee]
107
-
108
- MultiResponse.run(:first) do |r|
109
- r.process { commit(:post, "charges/#{CGI.escape(identification)}/refund", post, options) }
110
-
111
- return r unless options[:refund_fee_amount]
112
-
113
- r.process { fetch_application_fees(identification, options) }
114
- r.process { refund_application_fee(options[:refund_fee_amount], application_fee_from_response(r.responses.last), options) }
158
+ post[:reverse_transfer] = options[:reverse_transfer] if options[:reverse_transfer]
159
+ post[:metadata] = options[:metadata] if options[:metadata]
160
+ post[:reason] = options[:reason] if options[:reason]
161
+ post[:expand] = [:charge]
162
+
163
+ response = commit(:post, "charges/#{CGI.escape(identification)}/refunds", post, options)
164
+
165
+ if response.success? && options[:refund_fee_amount] && options[:refund_fee_amount].to_s != '0'
166
+ charge = api_request(:get, "charges/#{CGI.escape(identification)}", nil, options)
167
+
168
+ if application_fee = charge['application_fee']
169
+ fee_refund_options = {
170
+ currency: options[:currency], # currency isn't used by Stripe here, but we need it for #add_amount
171
+ key: @fee_refund_api_key
172
+ }
173
+ refund_application_fee(options[:refund_fee_amount].to_i, application_fee, fee_refund_options)
174
+ end
115
175
  end
176
+
177
+ response
116
178
  end
117
179
 
118
180
  def verify(payment, options = {})
119
181
  MultiResponse.run(:use_first_response) do |r|
120
- r.process { authorize(50, payment, options) }
182
+ r.process { authorize(auth_minimum_amount(options), payment, options) }
183
+ options[:idempotency_key] = nil
121
184
  r.process(:ignore_result) { void(r.authorization, options) }
122
185
  end
123
186
  end
124
187
 
125
- def application_fee_from_response(response)
126
- return unless response.success?
127
-
128
- application_fees = response.params["data"].select { |fee| fee["object"] == "application_fee" }
129
- application_fees.first["id"] unless application_fees.empty?
130
- end
131
-
132
188
  def refund_application_fee(money, identification, options = {})
133
- return Response.new(false, "Application fee id could not be found") unless identification
134
-
135
189
  post = {}
136
190
  add_amount(post, money, options)
137
- options.merge!(:key => @fee_refund_api_key)
138
-
139
- commit(:post, "application_fees/#{CGI.escape(identification)}/refund", post, options)
191
+ commit(:post, "application_fees/#{CGI.escape(identification)}/refunds", post, options)
140
192
  end
141
193
 
142
194
  # Note: creating a new credit card will not change the customer's existing default credit card (use :set_default => true)
143
195
  def store(payment, options = {})
144
- card_params = {}
196
+ params = {}
145
197
  post = {}
146
198
 
147
199
  if payment.is_a?(ApplePayPaymentToken)
148
200
  token_exchange_response = tokenize_apple_pay_token(payment)
149
- card_params = { card: token_exchange_response.params["token"]["id"] } if token_exchange_response.success?
201
+ params = { card: token_exchange_response.params['token']['id'] } if token_exchange_response.success?
202
+ elsif payment.is_a?(StripePaymentToken)
203
+ add_payment_token(params, payment, options)
204
+ elsif payment.is_a?(Check)
205
+ bank_token_response = tokenize_bank_account(payment)
206
+ return bank_token_response unless bank_token_response.success?
207
+
208
+ params = { source: bank_token_response.params['token']['id'] }
150
209
  else
151
- add_creditcard(card_params, payment, options)
210
+ add_creditcard(params, payment, options)
152
211
  end
153
212
 
213
+ post[:validate] = options[:validate] unless options[:validate].nil?
154
214
  post[:description] = options[:description] if options[:description]
155
215
  post[:email] = options[:email] if options[:email]
156
216
 
157
- if options[:customer]
217
+ if options[:account]
218
+ add_external_account(post, params, payment)
219
+ commit(:post, "accounts/#{CGI.escape(options[:account])}/external_accounts", post, options)
220
+ elsif options[:customer]
158
221
  MultiResponse.run(:first) do |r|
159
222
  # The /cards endpoint does not update other customer parameters.
160
- r.process { commit(:post, "customers/#{CGI.escape(options[:customer])}/cards", card_params, options) }
223
+ r.process { commit(:post, "customers/#{CGI.escape(options[:customer])}/cards", params, options) }
161
224
 
162
- if options[:set_default] and r.success? and !r.params['id'].blank?
163
- post[:default_card] = r.params['id']
164
- end
225
+ post[:default_card] = r.params['id'] if options[:set_default] && r.success? && !r.params['id'].blank?
165
226
 
166
- if post.count > 0
167
- r.process { update_customer(options[:customer], post) }
168
- end
227
+ r.process { update_customer(options[:customer], post.merge(expand: [:sources])) } if post.count > 0
169
228
  end
170
229
  else
171
- commit(:post, 'customers', post.merge(card_params), options)
230
+ post[:expand] = [:sources]
231
+ commit(:post, 'customers', post.merge(params), options)
172
232
  end
173
233
  end
174
234
 
@@ -180,28 +240,72 @@ module ActiveMerchant #:nodoc:
180
240
  commit(:post, "customers/#{CGI.escape(customer_id)}", options, options)
181
241
  end
182
242
 
183
- def unstore(customer_id, options = {}, deprecated_options = {})
243
+ def unstore(identification, options = {}, deprecated_options = {})
244
+ customer_id, card_id = identification.split('|')
245
+
184
246
  if options.kind_of?(String)
185
- ActiveMerchant.deprecated "Passing the card_id as the 2nd parameter is deprecated. Put it in the options hash instead."
186
- options = deprecated_options.merge(card_id: options)
247
+ ActiveMerchant.deprecated 'Passing the card_id as the 2nd parameter is deprecated. The response authorization includes both the customer_id and the card_id.'
248
+ card_id ||= options
249
+ options = deprecated_options
187
250
  end
188
251
 
189
- if options[:card_id]
190
- commit(:delete, "customers/#{CGI.escape(customer_id)}/cards/#{CGI.escape(options[:card_id])}", nil, options)
191
- else
192
- commit(:delete, "customers/#{CGI.escape(customer_id)}", nil, options)
193
- end
252
+ commit(:delete, "customers/#{CGI.escape(customer_id)}/cards/#{CGI.escape(card_id)}", nil, options)
194
253
  end
195
254
 
196
255
  def tokenize_apple_pay_token(apple_pay_payment_token, options = {})
197
256
  token_response = api_request(:post, "tokens?pk_token=#{CGI.escape(apple_pay_payment_token.payment_data.to_json)}")
198
- success = !token_response.key?("error")
257
+ success = !token_response.key?('error')
199
258
 
200
- if success && token_response.key?("id")
259
+ if success && token_response.key?('id')
201
260
  Response.new(success, nil, token: token_response)
202
261
  else
203
- Response.new(success, token_response["error"]["message"])
262
+ Response.new(success, token_response['error']['message'])
263
+ end
264
+ end
265
+
266
+ def verify_credentials
267
+ begin
268
+ ssl_get(live_url + 'charges/nonexistent', headers)
269
+ rescue ResponseError => e
270
+ return false if e.response.code.to_i == 401
204
271
  end
272
+
273
+ true
274
+ end
275
+
276
+ def supports_scrubbing?
277
+ true
278
+ end
279
+
280
+ def scrub(transcript)
281
+ transcript.
282
+ gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
283
+ gsub(%r((&?three_d_secure\[cryptogram\]=)[\w=]*(&?)), '\1[FILTERED]\2').
284
+ gsub(%r(((\[card\]|card)\[cryptogram\]=)[^&]+(&?)), '\1[FILTERED]\3').
285
+ gsub(%r(((\[card\]|card)\[cvc\]=)\d+), '\1[FILTERED]').
286
+ gsub(%r(((\[card\]|card)\[emv_approval_data\]=)[^&]+(&?)), '\1[FILTERED]\3').
287
+ gsub(%r(((\[card\]|card)\[emv_auth_data\]=)[^&]+(&?)), '\1[FILTERED]\3').
288
+ gsub(%r(((\[card\]|card)\[encrypted_pin\]=)[^&]+(&?)), '\1[FILTERED]\3').
289
+ gsub(%r(((\[card\]|card)\[encrypted_pin_key_id\]=)[\w=]+(&?)), '\1[FILTERED]\3').
290
+ gsub(%r(((\[card\]|card)\[number\]=)\d+), '\1[FILTERED]').
291
+ gsub(%r(((\[card\]|card)\[swipe_data\]=)[^&]+(&?)), '\1[FILTERED]\3').
292
+ gsub(%r(((\[bank_account\]|bank_account)\[account_number\]=)\d+), '\1[FILTERED]').
293
+ gsub(%r(((\[payment_method_data\]|payment_method_data)\[card\]\[token\]=)[^&]+(&?)), '\1[FILTERED]\3')
294
+ end
295
+
296
+ def supports_network_tokenization?
297
+ true
298
+ end
299
+
300
+ # Helper method to prevent hitting the external_account limit from remote test runs
301
+ def delete_latest_test_external_account(account)
302
+ return unless test?
303
+
304
+ auth_header = { 'Authorization': "Bearer #{options[:login]}" }
305
+ url = "#{live_url}accounts/#{CGI.escape(account)}/external_accounts"
306
+ accounts_response = JSON.parse(ssl_get("#{url}?limit=100", auth_header))
307
+ to_delete = accounts_response['data'].reject { |ac| ac['default_for_currency'] }
308
+ ssl_request(:delete, "#{url}/#{to_delete.first['id']}", nil, auth_header)
205
309
  end
206
310
 
207
311
  private
@@ -212,26 +316,85 @@ module ActiveMerchant #:nodoc:
212
316
  end
213
317
  end
214
318
 
215
- def create_post_for_auth_or_purchase(money, payment, options)
319
+ def create_source(money, payment, type, options = {})
216
320
  post = {}
217
321
  add_amount(post, money, options, true)
322
+ post[:type] = type
323
+ if type == 'card'
324
+ add_creditcard(post, payment, options, true)
325
+ add_source_owner(post, payment, options)
326
+ elsif type == 'three_d_secure'
327
+ post[:three_d_secure] = { card: payment }
328
+ post[:redirect] = { return_url: options[:redirect_url] }
329
+ end
330
+ commit(:post, 'sources', post, options)
331
+ end
332
+
333
+ def show_source(source_id, options)
334
+ commit(:get, "sources/#{source_id}", nil, options)
335
+ end
336
+
337
+ def create_webhook_endpoint(options, events)
338
+ post = {}
339
+ post[:url] = options[:callback_url]
340
+ post[:enabled_events] = events
341
+ post[:connect] = true if options[:stripe_account]
342
+ options.delete(:stripe_account)
343
+ commit(:post, 'webhook_endpoints', post, options)
344
+ end
345
+
346
+ def delete_webhook_endpoint(options)
347
+ commit(:delete, "webhook_endpoints/#{options[:webhook_id]}", {}, options)
348
+ end
349
+
350
+ def show_webhook_endpoint(options)
351
+ options.delete(:stripe_account)
352
+ commit(:get, "webhook_endpoints/#{options[:webhook_id]}", nil, options)
353
+ end
354
+
355
+ def list_webhook_endpoints(options)
356
+ params = {}
357
+ params[:limit] = options[:limit] if options[:limit]
358
+ options.delete(:stripe_account)
359
+ commit(:get, "webhook_endpoints?#{post_data(params)}", nil, options)
360
+ end
361
+
362
+ def create_post_for_auth_or_purchase(money, payment, options)
363
+ post = {}
364
+
218
365
  if payment.is_a?(StripePaymentToken)
219
366
  add_payment_token(post, payment, options)
220
367
  else
221
368
  add_creditcard(post, payment, options)
222
369
  end
223
- add_customer(post, payment, options)
224
- add_customer_data(post, options)
225
- post[:description] = options[:description]
226
- post[:statement_description] = options[:statement_description]
227
370
 
228
- post[:metadata] = {}
229
- post[:metadata][:email] = options[:email] if options[:email]
230
- post[:metadata][:order_id] = options[:order_id] if options[:order_id]
231
- post.delete(:metadata) if post[:metadata].empty?
371
+ add_charge_details(post, money, payment, options)
372
+ post
373
+ end
374
+
375
+ # Used internally by Spreedly to populate the charge object for 3DS 1.0 transactions
376
+ def add_charge_details(post, money, payment, options)
377
+ if emv_payment?(payment)
378
+ add_statement_address(post, options)
379
+ add_emv_metadata(post, payment)
380
+ else
381
+ add_amount(post, money, options, true)
382
+ add_customer_data(post, options)
383
+ post[:description] = options[:description]
384
+ post[:statement_descriptor] = options[:statement_description]
385
+ post[:statement_descriptor_suffix] = options[:statement_descriptor_suffix] if options[:statement_descriptor_suffix]
386
+ post[:receipt_email] = options[:receipt_email] if options[:receipt_email]
387
+ add_customer(post, payment, options)
388
+ add_flags(post, options)
389
+ end
232
390
 
233
- add_flags(post, options)
391
+ add_metadata(post, options)
234
392
  add_application_fee(post, options)
393
+ add_exchange_rate(post, options)
394
+ add_destination(post, options)
395
+ add_level_three(post, options)
396
+ add_connected_account(post, options)
397
+ add_radar_data(post, options)
235
398
  post
236
399
  end
237
400
 
@@ -245,12 +408,45 @@ module ActiveMerchant #:nodoc:
245
408
  post[:application_fee] = options[:application_fee] if options[:application_fee]
246
409
  end
247
410
 
411
+ def add_exchange_rate(post, options)
412
+ post[:exchange_rate] = options[:exchange_rate] if options[:exchange_rate]
413
+ end
414
+
415
+ def add_destination(post, options)
416
+ if options[:destination]
417
+ post[:destination] = {}
418
+ post[:destination][:account] = options[:destination]
419
+ post[:destination][:amount] = options[:destination_amount] if options[:destination_amount]
420
+ end
421
+ end
422
+
423
+ def add_level_three(post, options)
424
+ level_three = {}
425
+
426
+ copy_when_present(level_three, [:merchant_reference], options)
427
+ copy_when_present(level_three, [:customer_reference], options)
428
+ copy_when_present(level_three, [:shipping_address_zip], options)
429
+ copy_when_present(level_three, [:shipping_from_zip], options)
430
+ copy_when_present(level_three, [:shipping_amount], options)
431
+ copy_when_present(level_three, [:line_items], options)
432
+
433
+ post[:level3] = level_three unless level_three.empty?
434
+ end
435
+
248
436
  def add_expand_parameters(post, options)
249
- post[:expand] = Array.wrap(options[:expand])
437
+ post[:expand] ||= []
438
+ post[:expand].concat(Array.wrap(options[:expand]).map(&:to_sym)).uniq!
439
+ end
440
+
441
+ def add_external_account(post, card_params, payment)
442
+ external_account = {}
443
+ external_account[:object] = 'card'
444
+ external_account[:currency] = (options[:currency] || currency(payment)).downcase
445
+ post[:external_account] = external_account.merge(card_params[:card])
250
446
  end
251
447
 
252
448
  def add_customer_data(post, options)
253
- metadata_options = [:description, :ip, :user_agent, :referrer]
449
+ metadata_options = %i[description ip user_agent referrer]
254
450
  post.update(options.slice(*metadata_options))
255
451
 
256
452
  post[:external_id] = options[:order_id]
@@ -258,7 +454,8 @@ module ActiveMerchant #:nodoc:
258
454
  end
259
455
 
260
456
  def add_address(post, options)
261
- return unless post[:card] && post[:card].kind_of?(Hash)
457
+ return unless post[:card]&.kind_of?(Hash)
458
+
262
459
  if address = options[:billing_address] || options[:address]
263
460
  post[:card][:address_line1] = address[:address1] if address[:address1]
264
461
  post[:card][:address_line2] = address[:address2] if address[:address2]
@@ -269,24 +466,59 @@ module ActiveMerchant #:nodoc:
269
466
  end
270
467
  end
271
468
 
272
- def add_creditcard(post, creditcard, options)
469
+ def add_statement_address(post, options)
470
+ return unless statement_address = options[:statement_address]
471
+ return unless %i[address1 city zip state].all? { |key| statement_address[key].present? }
472
+
473
+ post[:statement_address] = {}
474
+ post[:statement_address][:line1] = statement_address[:address1]
475
+ post[:statement_address][:line2] = statement_address[:address2] if statement_address[:address2].present?
476
+ post[:statement_address][:city] = statement_address[:city]
477
+ post[:statement_address][:postal_code] = statement_address[:zip]
478
+ post[:statement_address][:state] = statement_address[:state]
479
+ end
480
+
481
+ def add_creditcard(post, creditcard, options, use_sources = false)
273
482
  card = {}
274
- if creditcard.respond_to?(:number)
483
+ if emv_payment?(creditcard)
484
+ add_emv_creditcard(post, creditcard.icc_data)
485
+ post[:card][:read_method] = 'contactless' if creditcard.read_method == 'contactless'
486
+ post[:card][:read_method] = 'contactless_magstripe_mode' if creditcard.read_method == 'contactless_magstripe'
487
+ if creditcard.encrypted_pin_cryptogram.present? && creditcard.encrypted_pin_ksn.present?
488
+ post[:card][:encrypted_pin] = creditcard.encrypted_pin_cryptogram
489
+ post[:card][:encrypted_pin_key_id] = creditcard.encrypted_pin_ksn
490
+ end
491
+ elsif creditcard.respond_to?(:number)
275
492
  if creditcard.respond_to?(:track_data) && creditcard.track_data.present?
276
493
  card[:swipe_data] = creditcard.track_data
494
+ if creditcard.respond_to?(:read_method)
495
+ card[:fallback_reason] = 'no_chip' if creditcard.read_method == 'fallback_no_chip'
496
+ card[:fallback_reason] = 'chip_error' if creditcard.read_method == 'fallback_chip_error'
497
+ card[:read_method] = 'contactless_magstripe_mode' if creditcard.read_method == 'contactless_magstripe'
498
+ end
277
499
  else
278
500
  card[:number] = creditcard.number
279
501
  card[:exp_month] = creditcard.month
280
502
  card[:exp_year] = creditcard.year
281
503
  card[:cvc] = creditcard.verification_value if creditcard.verification_value?
282
- card[:name] = creditcard.name if creditcard.name
504
+ card[:name] = creditcard.name if creditcard.name && !use_sources
283
505
  end
284
506
 
507
+ if creditcard.is_a?(NetworkTokenizationCreditCard)
508
+ card[:cryptogram] = creditcard.payment_cryptogram
509
+ card[:eci] = creditcard.eci.rjust(2, '0') if creditcard.eci =~ /^[0-9]+$/
510
+ card[:tokenization_method] = creditcard.source.to_s
511
+ end
285
512
  post[:card] = card
286
- add_address(post, options)
513
+
514
+ add_address(post, options) unless use_sources
287
515
  elsif creditcard.kind_of?(String)
288
516
  if options[:track_data]
289
517
  card[:swipe_data] = options[:track_data]
518
+ elsif creditcard.include?('|')
519
+ customer_id, card_id = creditcard.split('|')
520
+ card = card_id
521
+ post[:customer] = customer_id
290
522
  else
291
523
  card = creditcard
292
524
  end
@@ -294,8 +526,12 @@ module ActiveMerchant #:nodoc:
294
526
  end
295
527
  end
296
528
 
529
+ def add_emv_creditcard(post, icc_data, options = {})
530
+ post[:card] = { emv_auth_data: icc_data }
531
+ end
532
+
297
533
  def add_payment_token(post, token, options = {})
298
- post[:card] = token.payment_data["id"]
534
+ post[:card] = token.payment_data['id']
299
535
  end
300
536
 
301
537
  def add_customer(post, payment, options)
@@ -304,13 +540,57 @@ module ActiveMerchant #:nodoc:
304
540
 
305
541
  def add_flags(post, options)
306
542
  post[:uncaptured] = true if options[:uncaptured]
307
- post[:recurring] = true if (options[:eci] == 'recurring' || options[:recurring])
543
+ post[:recurring] = true if options[:eci] == 'recurring' || options[:recurring]
544
+ end
545
+
546
+ def add_metadata(post, options = {})
547
+ post[:metadata] ||= {}
548
+ post[:metadata].merge!(options[:metadata]) if options[:metadata]
549
+ post[:metadata][:email] = options[:email] if options[:email]
550
+ post[:metadata][:order_id] = options[:order_id] if options[:order_id]
551
+ end
552
+
553
+ def add_emv_metadata(post, creditcard)
554
+ post[:metadata] ||= {}
555
+ post[:metadata][:card_read_method] = creditcard.read_method if creditcard.respond_to?(:read_method)
556
+ end
557
+
558
+ def add_source_owner(post, creditcard, options)
559
+ post[:owner] = {}
560
+ post[:owner][:name] = creditcard.name if creditcard.name
561
+ post[:owner][:email] = options[:email] if options[:email]
562
+
563
+ if address = options[:billing_address] || options[:address]
564
+ owner_address = {}
565
+ owner_address[:line1] = address[:address1] if address[:address1]
566
+ owner_address[:line2] = address[:address2] if address[:address2]
567
+ owner_address[:country] = address[:country] if address[:country]
568
+ owner_address[:postal_code] = address[:zip] if address[:zip]
569
+ owner_address[:state] = address[:state] if address[:state]
570
+ owner_address[:city] = address[:city] if address[:city]
571
+
572
+ post[:owner][:phone] = address[:phone] if address[:phone]
573
+ post[:owner][:address] = owner_address
574
+ end
308
575
  end
309
576
 
310
- def fetch_application_fees(identification, options = {})
311
- options.merge!(:key => @fee_refund_api_key)
577
+ def add_connected_account(post, options = {})
578
+ post[:on_behalf_of] = options[:on_behalf_of] if options[:on_behalf_of]
579
+
580
+ return unless options[:transfer_destination]
312
581
 
313
- commit(:get, "application_fees?charge=#{identification}", nil, options)
582
+ post[:transfer_data] = { destination: options[:transfer_destination] }
583
+ post[:transfer_data][:amount] = options[:transfer_amount] if options[:transfer_amount]
584
+ post[:transfer_group] = options[:transfer_group] if options[:transfer_group]
585
+ post[:application_fee_amount] = options[:application_fee_amount] if options[:application_fee_amount]
586
+ end
587
+
588
+ def add_radar_data(post, options = {})
589
+ radar_options = {}
590
+ radar_options[:session] = options[:radar_session_id] if options[:radar_session_id]
591
+ radar_options[:skip_rules] = ['all'] if options[:skip_radar_rules]
592
+
593
+ post[:radar_options] = radar_options unless radar_options.empty?
314
594
  end
315
595
 
316
596
  def parse(body)
@@ -320,36 +600,64 @@ module ActiveMerchant #:nodoc:
320
600
  def post_data(params)
321
601
  return nil unless params
322
602
 
323
- params.map do |key, value|
324
- next if value.blank?
603
+ flatten_params([], params).join('&')
604
+ end
605
+
606
+ def flatten_params(flattened, params, prefix = nil)
607
+ params.each do |key, value|
608
+ next if value != false && value.blank?
609
+
610
+ flattened_key = prefix.nil? ? key : "#{prefix}[#{key}]"
325
611
  if value.is_a?(Hash)
326
- h = {}
327
- value.each do |k, v|
328
- h["#{key}[#{k}]"] = v unless v.blank?
329
- end
330
- post_data(h)
612
+ flatten_params(flattened, value, flattened_key)
331
613
  elsif value.is_a?(Array)
332
- value.map { |v| "#{key}[]=#{CGI.escape(v.to_s)}" }.join("&")
614
+ flatten_array(flattened, value, flattened_key)
333
615
  else
334
- "#{key}=#{CGI.escape(value.to_s)}"
616
+ flattened << "#{flattened_key}=#{CGI.escape(value.to_s)}"
335
617
  end
336
- end.compact.join("&")
618
+ end
619
+ flattened
620
+ end
621
+
622
+ def flatten_array(flattened, array, prefix)
623
+ array.each_with_index do |item, idx|
624
+ key = "#{prefix}[#{idx}]"
625
+ if item.is_a?(Hash)
626
+ flatten_params(flattened, item, key)
627
+ elsif item.is_a?(Array)
628
+ flatten_array(flattened, item, key)
629
+ else
630
+ flattened << "#{key}=#{CGI.escape(item.to_s)}"
631
+ end
632
+ end
337
633
  end
338
634
 
339
635
  def headers(options = {})
340
- key = options[:key] || @api_key
341
- version = options[:version] || @version
636
+ key = options[:key] || @api_key
637
+ idempotency_key = options[:idempotency_key]
342
638
 
343
639
  headers = {
344
- "Authorization" => "Basic " + Base64.encode64(key.to_s + ":").strip,
345
- "User-Agent" => "Stripe/v1 ActiveMerchantBindings/#{ActiveMerchant::VERSION}",
346
- "X-Stripe-Client-User-Agent" => user_agent,
347
- "X-Stripe-Client-User-Metadata" => {:ip => options[:ip]}.to_json
640
+ 'Authorization' => 'Basic ' + Base64.strict_encode64(key.to_s + ':').strip,
641
+ 'User-Agent' => "Stripe/v1 ActiveMerchantBindings/#{ActiveMerchant::VERSION}",
642
+ 'Stripe-Version' => api_version(options),
643
+ 'X-Stripe-Client-User-Agent' => stripe_client_user_agent(options),
644
+ 'X-Stripe-Client-User-Metadata' => { ip: options[:ip] }.to_json
348
645
  }
349
- headers.merge!("Stripe-Version" => version) if version
646
+ headers['Idempotency-Key'] = idempotency_key if idempotency_key
647
+ headers['Stripe-Account'] = options[:stripe_account] if options[:stripe_account]
350
648
  headers
351
649
  end
352
650
 
651
+ def stripe_client_user_agent(options)
652
+ return user_agent unless options[:application]
653
+
654
+ JSON.dump(JSON.parse(user_agent).merge!({ application: options[:application] }))
655
+ end
656
+
657
+ def api_version(options)
658
+ options[:version] || @options[:version] || self.class::DEFAULT_API_VERSION
659
+ end
660
+
353
661
  def api_request(method, endpoint, parameters = nil, options = {})
354
662
  raw_response = response = nil
355
663
  begin
@@ -366,45 +674,153 @@ module ActiveMerchant #:nodoc:
366
674
 
367
675
  def commit(method, url, parameters = nil, options = {})
368
676
  add_expand_parameters(parameters, options) if parameters
369
-
370
677
  response = api_request(method, url, parameters, options)
371
- success = !response.key?("error")
372
-
373
- card = response["card"] || response["active_card"] || {}
374
- avs_code = AVS_CODE_TRANSLATOR["line1: #{card["address_line1_check"]}, zip: #{card["address_zip_check"]}"]
375
- cvc_code = CVC_CODE_TRANSLATOR[card["cvc_check"]]
678
+ response['webhook_id'] = options[:webhook_id] if options[:webhook_id]
679
+ success = success_from(response, options)
376
680
 
681
+ card = card_from_response(response)
682
+ avs_code = AVS_CODE_TRANSLATOR["line1: #{card['address_line1_check']}, zip: #{card['address_zip_check']}"]
683
+ cvc_code = CVC_CODE_TRANSLATOR[card['cvc_check']]
377
684
  Response.new(success,
378
- success ? "Transaction approved" : response["error"]["message"],
685
+ message_from(success, response),
379
686
  response,
380
- :test => response.has_key?("livemode") ? !response["livemode"] : false,
381
- :authorization => success ? response["id"] : response["error"]["charge"],
382
- :avs_result => { :code => avs_code },
383
- :cvv_result => cvc_code,
384
- :error_code => success ? nil : STANDARD_ERROR_CODE_MAPPING[response["error"]["code"]]
385
- )
687
+ test: response_is_test?(response),
688
+ authorization: authorization_from(success, url, method, response),
689
+ avs_result: { code: avs_code },
690
+ cvv_result: cvc_code,
691
+ emv_authorization: emv_authorization_from_response(response),
692
+ error_code: success ? nil : error_code_from(response))
386
693
  end
387
694
 
388
- def response_error(raw_response)
389
- begin
390
- parse(raw_response)
391
- rescue JSON::ParserError
392
- json_error(raw_response)
695
+ def authorization_from(success, url, method, response)
696
+ return response.fetch('error', {})['charge'] unless success
697
+
698
+ if url == 'customers'
699
+ [response['id'], response.dig('sources', 'data').first&.dig('id')].join('|')
700
+ elsif method == :post && (url.match(/customers\/.*\/cards/) || url.match(/payment_methods\/.*\/attach/))
701
+ [response['customer'], response['id']].join('|')
702
+ else
703
+ response['id']
393
704
  end
394
705
  end
395
706
 
707
+ def message_from(success, response)
708
+ success ? 'Transaction approved' : response.fetch('error', { 'message' => 'No error details' })['message']
709
+ end
710
+
711
+ def success_from(response, options)
712
+ !response.key?('error') && response['status'] != 'failed'
713
+ end
714
+
715
+ def response_error(raw_response)
716
+ parse(raw_response)
717
+ rescue JSON::ParserError
718
+ json_error(raw_response)
719
+ end
720
+
396
721
  def json_error(raw_response)
397
722
  msg = 'Invalid response received from the Stripe API. Please contact support@stripe.com if you continue to receive this message.'
398
723
  msg += " (The raw response returned by the API was #{raw_response.inspect})"
399
724
  {
400
- "error" => {
401
- "message" => msg
725
+ 'error' => {
726
+ 'message' => msg
402
727
  }
403
728
  }
404
729
  end
405
730
 
406
- def non_fractional_currency?(currency)
407
- CURRENCIES_WITHOUT_FRACTIONS.include?(currency.to_s)
731
+ def response_is_test?(response)
732
+ if response.has_key?('livemode')
733
+ !response['livemode']
734
+ elsif response['charge'].is_a?(Hash) && response['charge'].has_key?('livemode')
735
+ !response['charge']['livemode']
736
+ else
737
+ false
738
+ end
739
+ end
740
+
741
+ def emv_payment?(payment)
742
+ payment.respond_to?(:emv?) && payment.emv?
743
+ end
744
+
745
+ def quickchip_payment?(payment)
746
+ payment.respond_to?(:read_method) && payment.read_method == 'contact_quickchip'
747
+ end
748
+
749
+ def card_from_response(response)
750
+ response['card'] || response['active_card'] || response['source'] || {}
751
+ end
752
+
753
+ def emv_authorization_from_response(response)
754
+ return response['error']['emv_auth_data'] if response['error']
755
+
756
+ card_from_response(response)['emv_auth_data']
757
+ end
758
+
759
+ def error_code_from(response)
760
+ return STANDARD_ERROR_CODE_MAPPING['processing_error'] unless response['error']
761
+
762
+ code = response['error']['code']
763
+ decline_code = response['error']['decline_code'] if code == 'card_declined'
764
+
765
+ error_code = STANDARD_ERROR_CODE_MAPPING[decline_code]
766
+ error_code ||= STANDARD_ERROR_CODE_MAPPING[code]
767
+ error_code
768
+ end
769
+
770
+ def tokenize_bank_account(bank_account, options = {})
771
+ account_holder_type = BANK_ACCOUNT_HOLDER_TYPE_MAPPING[bank_account.account_holder_type]
772
+
773
+ post = {
774
+ bank_account: {
775
+ account_number: bank_account.account_number,
776
+ country: 'US',
777
+ currency: 'usd',
778
+ routing_number: bank_account.routing_number,
779
+ account_holder_name: bank_account.name,
780
+ account_holder_type: account_holder_type
781
+ }
782
+ }
783
+
784
+ token_response = api_request(:post, "tokens?#{post_data(post)}")
785
+ success = token_response['error'].nil?
786
+
787
+ if success && token_response['id']
788
+ Response.new(success, nil, token: token_response)
789
+ else
790
+ Response.new(success, token_response['error']['message'])
791
+ end
792
+ end
793
+
794
+ def ach?(payment_method)
795
+ case payment_method
796
+ when String, nil
797
+ false
798
+ else
799
+ card_brand(payment_method) == 'check'
800
+ end
801
+ end
802
+
803
+ def auth_minimum_amount(options)
804
+ return 100 unless options[:currency]
805
+
806
+ return MINIMUM_AUTHORIZE_AMOUNTS[options[:currency].upcase] || 100
807
+ end
808
+
809
+ def copy_when_present(dest, dest_path, source, source_path = nil)
810
+ source_path ||= dest_path
811
+ source_path.each do |key|
812
+ return nil unless source[key]
813
+
814
+ source = source[key]
815
+ end
816
+
817
+ if source
818
+ dest_path.first(dest_path.size - 1).each do |key|
819
+ dest[key] ||= {}
820
+ dest = dest[key]
821
+ end
822
+ dest[dest_path.last] = source
823
+ end
408
824
  end
409
825
  end
410
826
  end