activemerchant 1.38.0 → 1.78.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (397) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +1344 -3
  3. data/CONTRIBUTORS +154 -0
  4. data/README.md +157 -144
  5. data/lib/active_merchant/billing/apple_pay_payment_token.rb +22 -0
  6. data/lib/active_merchant/billing/base.rb +21 -17
  7. data/lib/active_merchant/billing/check.rb +32 -22
  8. data/lib/active_merchant/billing/compatibility.rb +120 -0
  9. data/lib/active_merchant/billing/credit_card.rb +215 -67
  10. data/lib/active_merchant/billing/credit_card_formatting.rb +4 -1
  11. data/lib/active_merchant/billing/credit_card_methods.rb +149 -52
  12. data/lib/active_merchant/billing/cvv_result.rb +15 -15
  13. data/lib/active_merchant/billing/gateway.rb +170 -24
  14. data/lib/active_merchant/billing/gateways/adyen.rb +284 -0
  15. data/lib/active_merchant/billing/gateways/allied_wallet.rb +206 -0
  16. data/lib/active_merchant/billing/gateways/authorize_net.rb +899 -606
  17. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +417 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +43 -18
  19. data/lib/active_merchant/billing/gateways/axcessms.rb +181 -0
  20. data/lib/active_merchant/billing/gateways/balanced.rb +134 -346
  21. data/lib/active_merchant/billing/gateways/bank_frick.rb +225 -0
  22. data/lib/active_merchant/billing/gateways/banwire.rb +13 -2
  23. data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +325 -0
  24. data/lib/active_merchant/billing/gateways/be2bill.rb +131 -0
  25. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +96 -15
  26. data/lib/active_merchant/billing/gateways/beanstream.rb +52 -9
  27. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +12 -8
  28. data/lib/active_merchant/billing/gateways/blue_pay.rb +520 -501
  29. data/lib/active_merchant/billing/gateways/blue_snap.rb +343 -0
  30. data/lib/active_merchant/billing/gateways/bogus.rb +94 -50
  31. data/lib/active_merchant/billing/gateways/borgun.rb +222 -0
  32. data/lib/active_merchant/billing/gateways/bpoint.rb +277 -0
  33. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +14 -2
  34. data/lib/active_merchant/billing/gateways/braintree.rb +2 -2
  35. data/lib/active_merchant/billing/gateways/braintree_blue.rb +372 -137
  36. data/lib/active_merchant/billing/gateways/braintree_orange.rb +4 -4
  37. data/lib/active_merchant/billing/gateways/bridge_pay.rb +245 -0
  38. data/lib/active_merchant/billing/gateways/cams.rb +230 -0
  39. data/lib/active_merchant/billing/gateways/card_connect.rb +286 -0
  40. data/lib/active_merchant/billing/gateways/card_stream.rb +269 -118
  41. data/lib/active_merchant/billing/gateways/cardknox.rb +328 -0
  42. data/lib/active_merchant/billing/gateways/cardprocess.rb +254 -0
  43. data/lib/active_merchant/billing/gateways/cashnet.rb +219 -0
  44. data/lib/active_merchant/billing/gateways/cc5.rb +45 -0
  45. data/lib/active_merchant/billing/gateways/cecabank.rb +239 -0
  46. data/lib/active_merchant/billing/gateways/cenpos.rb +327 -0
  47. data/lib/active_merchant/billing/gateways/checkout.rb +214 -0
  48. data/lib/active_merchant/billing/gateways/checkout_v2.rb +226 -0
  49. data/lib/active_merchant/billing/gateways/citrus_pay.rb +23 -0
  50. data/lib/active_merchant/billing/gateways/clearhaus.rb +222 -0
  51. data/lib/active_merchant/billing/gateways/commercegate.rb +143 -0
  52. data/lib/active_merchant/billing/gateways/conekta.rb +224 -0
  53. data/lib/active_merchant/billing/gateways/creditcall.rb +272 -0
  54. data/lib/active_merchant/billing/gateways/credorax.rb +345 -0
  55. data/lib/active_merchant/billing/gateways/culqi.rb +279 -0
  56. data/lib/active_merchant/billing/gateways/cyber_source.rb +228 -98
  57. data/lib/active_merchant/billing/gateways/data_cash.rb +41 -314
  58. data/lib/active_merchant/billing/gateways/dibs.rb +205 -0
  59. data/lib/active_merchant/billing/gateways/digitzs.rb +292 -0
  60. data/lib/active_merchant/billing/gateways/ebanx.rb +296 -0
  61. data/lib/active_merchant/billing/gateways/efsnet.rb +3 -14
  62. data/lib/active_merchant/billing/gateways/elavon.rb +143 -142
  63. data/lib/active_merchant/billing/gateways/element.rb +356 -0
  64. data/lib/active_merchant/billing/gateways/epay.rb +23 -12
  65. data/lib/active_merchant/billing/gateways/eway.rb +12 -12
  66. data/lib/active_merchant/billing/gateways/eway_managed.rb +1 -1
  67. data/lib/active_merchant/billing/gateways/eway_rapid.rb +417 -204
  68. data/lib/active_merchant/billing/gateways/exact.rb +10 -1
  69. data/lib/active_merchant/billing/gateways/ezic.rb +196 -0
  70. data/lib/active_merchant/billing/gateways/fat_zebra.rb +65 -37
  71. data/lib/active_merchant/billing/gateways/federated_canada.rb +1 -8
  72. data/lib/active_merchant/billing/gateways/finansbank.rb +3 -2
  73. data/lib/active_merchant/billing/gateways/first_giving.rb +143 -0
  74. data/lib/active_merchant/billing/gateways/first_pay.rb +109 -124
  75. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +155 -29
  76. data/lib/active_merchant/billing/gateways/flo2cash.rb +215 -0
  77. data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +20 -0
  78. data/lib/active_merchant/billing/gateways/forte.rb +256 -0
  79. data/lib/active_merchant/billing/gateways/garanti.rb +11 -5
  80. data/lib/active_merchant/billing/gateways/global_collect.rb +334 -0
  81. data/lib/active_merchant/billing/gateways/global_transport.rb +194 -0
  82. data/lib/active_merchant/billing/gateways/hps.rb +305 -0
  83. data/lib/active_merchant/billing/gateways/iats_payments.rb +271 -16
  84. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +2 -5
  85. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +0 -0
  86. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +1 -1
  87. data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +15 -0
  88. data/lib/active_merchant/billing/gateways/inspire.rb +8 -10
  89. data/lib/active_merchant/billing/gateways/instapay.rb +0 -0
  90. data/lib/active_merchant/billing/gateways/ipp.rb +175 -0
  91. data/lib/active_merchant/billing/gateways/iridium.rb +210 -4
  92. data/lib/active_merchant/billing/gateways/iveri.rb +251 -0
  93. data/lib/active_merchant/billing/gateways/jetpay.rb +176 -49
  94. data/lib/active_merchant/billing/gateways/jetpay_v2.rb +437 -0
  95. data/lib/active_merchant/billing/gateways/komoju.rb +115 -0
  96. data/lib/active_merchant/billing/gateways/kushki.rb +227 -0
  97. data/lib/active_merchant/billing/gateways/latitude19.rb +416 -0
  98. data/lib/active_merchant/billing/gateways/linkpoint.rb +17 -13
  99. data/lib/active_merchant/billing/gateways/litle.rb +329 -439
  100. data/lib/active_merchant/billing/gateways/mastercard.rb +268 -0
  101. data/lib/active_merchant/billing/gateways/maxipago.rb +220 -0
  102. data/lib/active_merchant/billing/gateways/mercado_pago.rb +262 -0
  103. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +15 -7
  104. data/lib/active_merchant/billing/gateways/merchant_one.rb +0 -1
  105. data/lib/active_merchant/billing/gateways/merchant_partners.rb +245 -0
  106. data/lib/active_merchant/billing/gateways/merchant_ware.rb +12 -15
  107. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +24 -13
  108. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +21 -14
  109. data/lib/active_merchant/billing/gateways/mercury.rb +74 -29
  110. data/lib/active_merchant/billing/gateways/metrics_global.rb +2 -21
  111. data/lib/active_merchant/billing/gateways/micropayment.rb +185 -0
  112. data/lib/active_merchant/billing/gateways/migs.rb +74 -13
  113. data/lib/active_merchant/billing/gateways/modern_payments.rb +1 -1
  114. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +1 -3
  115. data/lib/active_merchant/billing/gateways/monei.rb +307 -0
  116. data/lib/active_merchant/billing/gateways/moneris.rb +119 -36
  117. data/lib/active_merchant/billing/gateways/moneris_us.rb +146 -45
  118. data/lib/active_merchant/billing/gateways/money_movers.rb +152 -0
  119. data/lib/active_merchant/billing/gateways/nab_transact.rb +78 -53
  120. data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +165 -0
  121. data/lib/active_merchant/billing/gateways/net_registry.rb +8 -3
  122. data/lib/active_merchant/billing/gateways/netbanx.rb +289 -0
  123. data/lib/active_merchant/billing/gateways/netbilling.rb +61 -26
  124. data/lib/active_merchant/billing/gateways/netpay.rb +1 -1
  125. data/lib/active_merchant/billing/gateways/network_merchants.rb +242 -0
  126. data/lib/active_merchant/billing/gateways/nmi.rb +265 -10
  127. data/lib/active_merchant/billing/gateways/ogone.rb +85 -27
  128. data/lib/active_merchant/billing/gateways/omise.rb +324 -0
  129. data/lib/active_merchant/billing/gateways/openpay.rb +227 -0
  130. data/lib/active_merchant/billing/gateways/opp.rb +372 -0
  131. data/lib/active_merchant/billing/gateways/optimal_payment.rb +59 -28
  132. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +22 -21
  133. data/lib/active_merchant/billing/gateways/orbital.rb +346 -56
  134. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +207 -0
  135. data/lib/active_merchant/billing/gateways/pagarme.rb +248 -0
  136. data/lib/active_merchant/billing/gateways/pago_facil.rb +122 -0
  137. data/lib/active_merchant/billing/gateways/pay_conex.rb +246 -0
  138. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +30 -14
  139. data/lib/active_merchant/billing/gateways/pay_hub.rb +213 -0
  140. data/lib/active_merchant/billing/gateways/pay_junction.rb +19 -25
  141. data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +190 -0
  142. data/lib/active_merchant/billing/gateways/pay_secure.rb +0 -7
  143. data/lib/active_merchant/billing/gateways/paybox_direct.rb +16 -12
  144. data/lib/active_merchant/billing/gateways/payeezy.rb +386 -0
  145. data/lib/active_merchant/billing/gateways/payex.rb +412 -0
  146. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +38 -17
  147. data/lib/active_merchant/billing/gateways/payflow.rb +100 -19
  148. data/lib/active_merchant/billing/gateways/payflow_express.rb +22 -22
  149. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +2 -2
  150. data/lib/active_merchant/billing/gateways/payflow_uk.rb +6 -6
  151. data/lib/active_merchant/billing/gateways/payment_express.rb +15 -3
  152. data/lib/active_merchant/billing/gateways/paymentez.rb +283 -0
  153. data/lib/active_merchant/billing/gateways/paymill.rb +237 -48
  154. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +41 -8
  155. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +4 -0
  156. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +18 -4
  157. data/lib/active_merchant/billing/gateways/paypal.rb +49 -20
  158. data/lib/active_merchant/billing/gateways/paypal_ca.rb +1 -1
  159. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +6 -5
  160. data/lib/active_merchant/billing/gateways/paypal_express.rb +32 -4
  161. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +3 -3
  162. data/lib/active_merchant/billing/gateways/payscout.rb +162 -0
  163. data/lib/active_merchant/billing/gateways/paystation.rb +22 -24
  164. data/lib/active_merchant/billing/gateways/payu_in.rb +248 -0
  165. data/lib/active_merchant/billing/gateways/payu_latam.rb +440 -0
  166. data/lib/active_merchant/billing/gateways/pin.rb +68 -13
  167. data/lib/active_merchant/billing/gateways/plugnpay.rb +1 -12
  168. data/lib/active_merchant/billing/gateways/pro_pay.rb +326 -0
  169. data/lib/active_merchant/billing/gateways/psigate.rb +3 -14
  170. data/lib/active_merchant/billing/gateways/psl_card.rb +3 -3
  171. data/lib/active_merchant/billing/gateways/qbms.rb +1 -1
  172. data/lib/active_merchant/billing/gateways/quantum.rb +2 -2
  173. data/lib/active_merchant/billing/gateways/quickbooks.rb +290 -0
  174. data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +188 -0
  175. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +299 -0
  176. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +227 -0
  177. data/lib/active_merchant/billing/gateways/quickpay.rb +10 -319
  178. data/lib/active_merchant/billing/gateways/qvalent.rb +236 -0
  179. data/lib/active_merchant/billing/gateways/realex.rb +27 -25
  180. data/lib/active_merchant/billing/gateways/redsys.rb +212 -80
  181. data/lib/active_merchant/billing/gateways/s5.rb +247 -0
  182. data/lib/active_merchant/billing/gateways/safe_charge.rb +258 -0
  183. data/lib/active_merchant/billing/gateways/sage.rb +412 -119
  184. data/lib/active_merchant/billing/gateways/sage_pay.rb +176 -59
  185. data/lib/active_merchant/billing/gateways/secure_net.rb +35 -29
  186. data/lib/active_merchant/billing/gateways/secure_pay.rb +182 -9
  187. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +21 -7
  188. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +0 -7
  189. data/lib/active_merchant/billing/gateways/securion_pay.rb +267 -0
  190. data/lib/active_merchant/billing/gateways/skip_jack.rb +1 -3
  191. data/lib/active_merchant/billing/gateways/smart_ps.rb +13 -2
  192. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
  193. data/lib/active_merchant/billing/gateways/spreedly_core.rb +36 -11
  194. data/lib/active_merchant/billing/gateways/stripe.rb +461 -82
  195. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +156 -0
  196. data/lib/active_merchant/billing/gateways/telr.rb +275 -0
  197. data/lib/active_merchant/billing/gateways/tns.rb +22 -0
  198. data/lib/active_merchant/billing/gateways/trans_first.rb +142 -28
  199. data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +608 -0
  200. data/lib/active_merchant/billing/gateways/transact_pro.rb +224 -0
  201. data/lib/active_merchant/billing/gateways/transnational.rb +2 -231
  202. data/lib/active_merchant/billing/gateways/trexle.rb +217 -0
  203. data/lib/active_merchant/billing/gateways/trust_commerce.rb +17 -11
  204. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +193 -75
  205. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +150 -63
  206. data/lib/active_merchant/billing/gateways/vanco.rb +294 -0
  207. data/lib/active_merchant/billing/gateways/verifi.rb +1 -8
  208. data/lib/active_merchant/billing/gateways/viaklix.rb +1 -15
  209. data/lib/active_merchant/billing/gateways/visanet_peru.rb +209 -0
  210. data/lib/active_merchant/billing/gateways/webpay.rb +45 -28
  211. data/lib/active_merchant/billing/gateways/wepay.rb +238 -0
  212. data/lib/active_merchant/billing/gateways/wirecard.rb +167 -49
  213. data/lib/active_merchant/billing/gateways/world_net.rb +344 -0
  214. data/lib/active_merchant/billing/gateways/worldpay.rb +131 -36
  215. data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +218 -0
  216. data/lib/active_merchant/billing/gateways/worldpay_us.rb +221 -0
  217. data/lib/active_merchant/billing/gateways.rb +8 -11
  218. data/lib/active_merchant/billing/model.rb +30 -0
  219. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +39 -0
  220. data/lib/active_merchant/billing/payment_token.rb +21 -0
  221. data/lib/active_merchant/billing/rails.rb +3 -0
  222. data/lib/active_merchant/billing/response.rb +24 -17
  223. data/lib/active_merchant/billing.rb +7 -1
  224. data/lib/active_merchant/connection.rb +177 -0
  225. data/lib/active_merchant/country.rb +334 -0
  226. data/lib/active_merchant/empty.rb +20 -0
  227. data/lib/active_merchant/errors.rb +35 -0
  228. data/lib/active_merchant/network_connection_retries.rb +79 -0
  229. data/lib/active_merchant/post_data.rb +24 -0
  230. data/lib/active_merchant/posts_data.rb +84 -0
  231. data/lib/active_merchant/version.rb +1 -1
  232. data/lib/active_merchant.rb +24 -21
  233. data/lib/certs/cacert.pem +3951 -0
  234. data/lib/support/gateway_support.rb +16 -10
  235. data/lib/support/outbound_hosts.rb +13 -10
  236. metadata +161 -306
  237. data/gem-public_cert.pem +0 -20
  238. data/lib/active_merchant/billing/expiry_date.rb +0 -34
  239. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +0 -314
  240. data/lib/active_merchant/billing/gateways/card_stream_modern.rb +0 -155
  241. data/lib/active_merchant/billing/gateways/certo_direct.rb +0 -277
  242. data/lib/active_merchant/billing/gateways/orbital/avs_result.rb +0 -93
  243. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +0 -93
  244. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +0 -114
  245. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +0 -102
  246. data/lib/active_merchant/billing/gateways/samurai.rb +0 -118
  247. data/lib/active_merchant/billing/gateways/vindicia.rb +0 -361
  248. data/lib/active_merchant/billing/integrations/a1agregator/helper.rb +0 -31
  249. data/lib/active_merchant/billing/integrations/a1agregator/notification.rb +0 -186
  250. data/lib/active_merchant/billing/integrations/a1agregator/status.rb +0 -38
  251. data/lib/active_merchant/billing/integrations/a1agregator.rb +0 -26
  252. data/lib/active_merchant/billing/integrations/action_view_helper.rb +0 -73
  253. data/lib/active_merchant/billing/integrations/authorize_net_sim/helper.rb +0 -229
  254. data/lib/active_merchant/billing/integrations/authorize_net_sim/notification.rb +0 -340
  255. data/lib/active_merchant/billing/integrations/authorize_net_sim.rb +0 -38
  256. data/lib/active_merchant/billing/integrations/bogus/helper.rb +0 -17
  257. data/lib/active_merchant/billing/integrations/bogus/notification.rb +0 -11
  258. data/lib/active_merchant/billing/integrations/bogus/return.rb +0 -10
  259. data/lib/active_merchant/billing/integrations/bogus.rb +0 -23
  260. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +0 -120
  261. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +0 -158
  262. data/lib/active_merchant/billing/integrations/chronopay/return.rb +0 -10
  263. data/lib/active_merchant/billing/integrations/chronopay.rb +0 -23
  264. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +0 -200
  265. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +0 -76
  266. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +0 -32
  267. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +0 -37
  268. data/lib/active_merchant/billing/integrations/direc_pay.rb +0 -41
  269. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +0 -90
  270. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +0 -120
  271. data/lib/active_merchant/billing/integrations/directebanking/return.rb +0 -11
  272. data/lib/active_merchant/billing/integrations/directebanking.rb +0 -47
  273. data/lib/active_merchant/billing/integrations/dotpay/helper.rb +0 -77
  274. data/lib/active_merchant/billing/integrations/dotpay/notification.rb +0 -86
  275. data/lib/active_merchant/billing/integrations/dotpay/return.rb +0 -11
  276. data/lib/active_merchant/billing/integrations/dotpay.rb +0 -22
  277. data/lib/active_merchant/billing/integrations/dwolla/common.rb +0 -23
  278. data/lib/active_merchant/billing/integrations/dwolla/helper.rb +0 -43
  279. data/lib/active_merchant/billing/integrations/dwolla/notification.rb +0 -64
  280. data/lib/active_merchant/billing/integrations/dwolla/return.rb +0 -49
  281. data/lib/active_merchant/billing/integrations/dwolla.rb +0 -23
  282. data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +0 -34
  283. data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +0 -84
  284. data/lib/active_merchant/billing/integrations/e_payment_plans.rb +0 -48
  285. data/lib/active_merchant/billing/integrations/easy_pay/common.rb +0 -40
  286. data/lib/active_merchant/billing/integrations/easy_pay/helper.rb +0 -36
  287. data/lib/active_merchant/billing/integrations/easy_pay/notification.rb +0 -59
  288. data/lib/active_merchant/billing/integrations/easy_pay.rb +0 -30
  289. data/lib/active_merchant/billing/integrations/epay/helper.rb +0 -55
  290. data/lib/active_merchant/billing/integrations/epay/notification.rb +0 -110
  291. data/lib/active_merchant/billing/integrations/epay.rb +0 -21
  292. data/lib/active_merchant/billing/integrations/first_data/helper.rb +0 -61
  293. data/lib/active_merchant/billing/integrations/first_data/notification.rb +0 -56
  294. data/lib/active_merchant/billing/integrations/first_data.rb +0 -38
  295. data/lib/active_merchant/billing/integrations/gestpay/common.rb +0 -42
  296. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +0 -70
  297. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +0 -85
  298. data/lib/active_merchant/billing/integrations/gestpay/return.rb +0 -10
  299. data/lib/active_merchant/billing/integrations/gestpay.rb +0 -25
  300. data/lib/active_merchant/billing/integrations/helper.rb +0 -117
  301. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +0 -58
  302. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +0 -59
  303. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +0 -68
  304. data/lib/active_merchant/billing/integrations/hi_trust.rb +0 -27
  305. data/lib/active_merchant/billing/integrations/ipay88/helper.rb +0 -114
  306. data/lib/active_merchant/billing/integrations/ipay88/return.rb +0 -95
  307. data/lib/active_merchant/billing/integrations/ipay88.rb +0 -19
  308. data/lib/active_merchant/billing/integrations/liqpay/helper.rb +0 -43
  309. data/lib/active_merchant/billing/integrations/liqpay/notification.rb +0 -89
  310. data/lib/active_merchant/billing/integrations/liqpay/return.rb +0 -83
  311. data/lib/active_merchant/billing/integrations/liqpay.rb +0 -30
  312. data/lib/active_merchant/billing/integrations/maksuturva/helper.rb +0 -119
  313. data/lib/active_merchant/billing/integrations/maksuturva/notification.rb +0 -48
  314. data/lib/active_merchant/billing/integrations/maksuturva.rb +0 -86
  315. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +0 -75
  316. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +0 -129
  317. data/lib/active_merchant/billing/integrations/moneybookers.rb +0 -26
  318. data/lib/active_merchant/billing/integrations/nochex/helper.rb +0 -68
  319. data/lib/active_merchant/billing/integrations/nochex/notification.rb +0 -94
  320. data/lib/active_merchant/billing/integrations/nochex/return.rb +0 -10
  321. data/lib/active_merchant/billing/integrations/nochex.rb +0 -88
  322. data/lib/active_merchant/billing/integrations/notification.rb +0 -71
  323. data/lib/active_merchant/billing/integrations/paxum/common.rb +0 -24
  324. data/lib/active_merchant/billing/integrations/paxum/helper.rb +0 -42
  325. data/lib/active_merchant/billing/integrations/paxum/notification.rb +0 -33
  326. data/lib/active_merchant/billing/integrations/paxum.rb +0 -44
  327. data/lib/active_merchant/billing/integrations/pay_fast/common.rb +0 -42
  328. data/lib/active_merchant/billing/integrations/pay_fast/helper.rb +0 -50
  329. data/lib/active_merchant/billing/integrations/pay_fast/notification.rb +0 -134
  330. data/lib/active_merchant/billing/integrations/pay_fast/return.rb +0 -10
  331. data/lib/active_merchant/billing/integrations/pay_fast.rb +0 -70
  332. data/lib/active_merchant/billing/integrations/payflow_link/helper.rb +0 -116
  333. data/lib/active_merchant/billing/integrations/payflow_link/notification.rb +0 -78
  334. data/lib/active_merchant/billing/integrations/payflow_link.rb +0 -21
  335. data/lib/active_merchant/billing/integrations/paypal/helper.rb +0 -119
  336. data/lib/active_merchant/billing/integrations/paypal/notification.rb +0 -227
  337. data/lib/active_merchant/billing/integrations/paypal/return.rb +0 -10
  338. data/lib/active_merchant/billing/integrations/paypal.rb +0 -39
  339. data/lib/active_merchant/billing/integrations/paypal_payments_advanced/helper.rb +0 -15
  340. data/lib/active_merchant/billing/integrations/paypal_payments_advanced.rb +0 -20
  341. data/lib/active_merchant/billing/integrations/paysbuy/helper.rb +0 -15
  342. data/lib/active_merchant/billing/integrations/paysbuy/notification.rb +0 -28
  343. data/lib/active_merchant/billing/integrations/paysbuy.rb +0 -36
  344. data/lib/active_merchant/billing/integrations/payu_in/helper.rb +0 -74
  345. data/lib/active_merchant/billing/integrations/payu_in/notification.rb +0 -165
  346. data/lib/active_merchant/billing/integrations/payu_in/return.rb +0 -36
  347. data/lib/active_merchant/billing/integrations/payu_in.rb +0 -43
  348. data/lib/active_merchant/billing/integrations/platron/helper.rb +0 -32
  349. data/lib/active_merchant/billing/integrations/platron/notification.rb +0 -113
  350. data/lib/active_merchant/billing/integrations/platron.rb +0 -28
  351. data/lib/active_merchant/billing/integrations/pxpay/helper.rb +0 -112
  352. data/lib/active_merchant/billing/integrations/pxpay/notification.rb +0 -157
  353. data/lib/active_merchant/billing/integrations/pxpay/return.rb +0 -25
  354. data/lib/active_merchant/billing/integrations/pxpay.rb +0 -31
  355. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +0 -74
  356. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +0 -137
  357. data/lib/active_merchant/billing/integrations/quickpay.rb +0 -21
  358. data/lib/active_merchant/billing/integrations/rbkmoney/helper.rb +0 -23
  359. data/lib/active_merchant/billing/integrations/rbkmoney/notification.rb +0 -91
  360. data/lib/active_merchant/billing/integrations/rbkmoney.rb +0 -17
  361. data/lib/active_merchant/billing/integrations/return.rb +0 -42
  362. data/lib/active_merchant/billing/integrations/robokassa/common.rb +0 -19
  363. data/lib/active_merchant/billing/integrations/robokassa/helper.rb +0 -50
  364. data/lib/active_merchant/billing/integrations/robokassa/notification.rb +0 -55
  365. data/lib/active_merchant/billing/integrations/robokassa/return.rb +0 -17
  366. data/lib/active_merchant/billing/integrations/robokassa.rb +0 -49
  367. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +0 -33
  368. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +0 -136
  369. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +0 -210
  370. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +0 -31
  371. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +0 -37
  372. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +0 -91
  373. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +0 -139
  374. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +0 -17
  375. data/lib/active_merchant/billing/integrations/two_checkout.rb +0 -44
  376. data/lib/active_merchant/billing/integrations/valitor/helper.rb +0 -86
  377. data/lib/active_merchant/billing/integrations/valitor/notification.rb +0 -13
  378. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +0 -97
  379. data/lib/active_merchant/billing/integrations/valitor/return.rb +0 -13
  380. data/lib/active_merchant/billing/integrations/valitor.rb +0 -33
  381. data/lib/active_merchant/billing/integrations/verkkomaksut/helper.rb +0 -88
  382. data/lib/active_merchant/billing/integrations/verkkomaksut/notification.rb +0 -59
  383. data/lib/active_merchant/billing/integrations/verkkomaksut.rb +0 -20
  384. data/lib/active_merchant/billing/integrations/web_pay/common.rb +0 -50
  385. data/lib/active_merchant/billing/integrations/web_pay/helper.rb +0 -68
  386. data/lib/active_merchant/billing/integrations/web_pay/notification.rb +0 -51
  387. data/lib/active_merchant/billing/integrations/web_pay.rb +0 -45
  388. data/lib/active_merchant/billing/integrations/webmoney/common.rb +0 -17
  389. data/lib/active_merchant/billing/integrations/webmoney/helper.rb +0 -40
  390. data/lib/active_merchant/billing/integrations/webmoney/notification.rb +0 -47
  391. data/lib/active_merchant/billing/integrations/webmoney.rb +0 -43
  392. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +0 -101
  393. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +0 -160
  394. data/lib/active_merchant/billing/integrations/world_pay.rb +0 -34
  395. data/lib/active_merchant/billing/integrations.rb +0 -17
  396. data.tar.gz.sig +0 -0
  397. metadata.gz.sig +0 -0
@@ -21,14 +21,53 @@ module ActiveMerchant #:nodoc:
21
21
  'unchecked' => 'P'
22
22
  }
23
23
 
24
- self.supported_countries = ['US', 'CA', 'GB']
24
+ self.supported_countries = %w(AT AU BE BR CA CH DE DK ES FI FR GB HK IE IT JP LU MX NL NO NZ PT SE SG US)
25
25
  self.default_currency = 'USD'
26
26
  self.money_format = :cents
27
- self.supported_cardtypes = [:visa, :master, :american_express, :discover, :jcb, :diners_club]
27
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover, :jcb, :diners_club, :maestro]
28
+ self.currencies_without_fractions = %w(BIF CLP DJF GNF JPY KMF KRW MGA PYG RWF VND VUV XAF XOF XPF)
28
29
 
29
30
  self.homepage_url = 'https://stripe.com/'
30
31
  self.display_name = 'Stripe'
31
32
 
33
+ STANDARD_ERROR_CODE_MAPPING = {
34
+ 'incorrect_number' => STANDARD_ERROR_CODE[:incorrect_number],
35
+ 'invalid_number' => STANDARD_ERROR_CODE[:invalid_number],
36
+ 'invalid_expiry_month' => STANDARD_ERROR_CODE[:invalid_expiry_date],
37
+ 'invalid_expiry_year' => STANDARD_ERROR_CODE[:invalid_expiry_date],
38
+ 'invalid_cvc' => STANDARD_ERROR_CODE[:invalid_cvc],
39
+ 'expired_card' => STANDARD_ERROR_CODE[:expired_card],
40
+ 'incorrect_cvc' => STANDARD_ERROR_CODE[:incorrect_cvc],
41
+ 'incorrect_zip' => STANDARD_ERROR_CODE[:incorrect_zip],
42
+ 'card_declined' => STANDARD_ERROR_CODE[:card_declined],
43
+ 'call_issuer' => STANDARD_ERROR_CODE[:call_issuer],
44
+ 'processing_error' => STANDARD_ERROR_CODE[:processing_error],
45
+ 'incorrect_pin' => STANDARD_ERROR_CODE[:incorrect_pin],
46
+ 'test_mode_live_card' => STANDARD_ERROR_CODE[:test_mode_live_card],
47
+ 'pickup_card' => STANDARD_ERROR_CODE[:pickup_card]
48
+ }
49
+
50
+ BANK_ACCOUNT_HOLDER_TYPE_MAPPING = {
51
+ "personal" => "individual",
52
+ "business" => "company",
53
+ }
54
+
55
+ MINIMUM_AUTHORIZE_AMOUNTS = {
56
+ "USD" => 100,
57
+ "CAD" => 100,
58
+ "GBP" => 60,
59
+ "EUR" => 100,
60
+ "DKK" => 500,
61
+ "NOK" => 600,
62
+ "SEK" => 600,
63
+ "CHF" => 100,
64
+ "AUD" => 100,
65
+ "JPY" => 100,
66
+ "MXN" => 2000,
67
+ "SGD" => 100,
68
+ "HKD" => 800
69
+ }
70
+
32
71
  def initialize(options = {})
33
72
  requires!(options, :login)
34
73
  @api_key = options[:login]
@@ -36,11 +75,22 @@ module ActiveMerchant #:nodoc:
36
75
  super
37
76
  end
38
77
 
39
- def authorize(money, creditcard, options = {})
40
- post = create_post_for_auth_or_purchase(money, creditcard, options)
41
- post[:capture] = "false"
42
-
43
- commit(:post, 'charges', post, generate_meta(options))
78
+ def authorize(money, payment, options = {})
79
+ MultiResponse.run do |r|
80
+ if payment.is_a?(ApplePayPaymentToken)
81
+ r.process { tokenize_apple_pay_token(payment) }
82
+ payment = StripePaymentToken.new(r.params["token"]) if r.success?
83
+ end
84
+ r.process do
85
+ post = create_post_for_auth_or_purchase(money, payment, options)
86
+ if emv_payment?(payment)
87
+ add_application_fee(post, options)
88
+ else
89
+ post[:capture] = "false"
90
+ end
91
+ commit(:post, 'charges', post, options)
92
+ end
93
+ end.responses.last
44
94
  end
45
95
 
46
96
  # To create a charge on a card or a token, call
@@ -50,102 +100,268 @@ module ActiveMerchant #:nodoc:
50
100
  # To create a charge on a customer, call
51
101
  #
52
102
  # purchase(money, nil, { :customer => id, ... })
53
- def purchase(money, creditcard, options = {})
54
- post = create_post_for_auth_or_purchase(money, creditcard, options)
103
+ def purchase(money, payment, options = {})
104
+ if ach?(payment)
105
+ direct_bank_error = "Direct bank account transactions are not supported. Bank accounts must be stored and verified before use."
106
+ return Response.new(false, direct_bank_error)
107
+ end
55
108
 
56
- commit(:post, 'charges', post, generate_meta(options))
109
+ MultiResponse.run do |r|
110
+ if payment.is_a?(ApplePayPaymentToken)
111
+ r.process { tokenize_apple_pay_token(payment) }
112
+ payment = StripePaymentToken.new(r.params["token"]) if r.success?
113
+ end
114
+ r.process do
115
+ post = create_post_for_auth_or_purchase(money, payment, options)
116
+ post[:card][:processing_method] = 'quick_chip' if quickchip_payment?(payment)
117
+ commit(:post, 'charges', post, options)
118
+ end
119
+ end.responses.last
57
120
  end
58
121
 
59
122
  def capture(money, authorization, options = {})
60
- post = {:amount => amount(money)}
61
- add_application_fee(post, options)
123
+ post = {}
62
124
 
63
- commit(:post, "charges/#{CGI.escape(authorization)}/capture", post)
125
+ if emv_tc_response = options.delete(:icc_data)
126
+ post[:card] = { emv_approval_data: emv_tc_response }
127
+ commit(:post, "charges/#{CGI.escape(authorization)}", post, options)
128
+ else
129
+ add_application_fee(post, options)
130
+ add_amount(post, money, options)
131
+ add_exchange_rate(post, options)
132
+ commit(:post, "charges/#{CGI.escape(authorization)}/capture", post, options)
133
+ end
64
134
  end
65
135
 
66
136
  def void(identification, options = {})
67
- commit(:post, "charges/#{CGI.escape(identification)}/refund", {})
137
+ post = {}
138
+ post[:metadata] = options[:metadata] if options[:metadata]
139
+ post[:expand] = [:charge]
140
+ commit(:post, "charges/#{CGI.escape(identification)}/refunds", post, options)
68
141
  end
69
142
 
70
143
  def refund(money, identification, options = {})
71
- post = {:amount => amount(money)}
72
- commit_options = generate_meta(options)
144
+ post = {}
145
+ add_amount(post, money, options)
146
+ post[:refund_application_fee] = true if options[:refund_application_fee]
147
+ post[:reverse_transfer] = options[:reverse_transfer] if options[:reverse_transfer]
148
+ post[:metadata] = options[:metadata] if options[:metadata]
149
+ post[:expand] = [:charge]
73
150
 
74
151
  MultiResponse.run(:first) do |r|
75
- r.process { commit(:post, "charges/#{CGI.escape(identification)}/refund", post, commit_options) }
152
+ r.process { commit(:post, "charges/#{CGI.escape(identification)}/refunds", post, options) }
76
153
 
77
- return r unless options[:refund_fee_amount]
154
+ if options[:refund_fee_amount] && options[:refund_fee_amount].to_s != '0'
155
+ r.process { fetch_application_fee(identification, options) }
156
+ r.process { refund_application_fee(options[:refund_fee_amount].to_i, application_fee_from_response(r.responses.last), options) }
157
+ end
158
+ end
159
+ end
78
160
 
79
- r.process { fetch_application_fees(identification, commit_options) }
80
- r.process { refund_application_fee(options[:refund_fee_amount], application_fee_from_response(r), commit_options) }
161
+ def verify(payment, options = {})
162
+ MultiResponse.run(:use_first_response) do |r|
163
+ r.process { authorize(auth_minimum_amount(options), payment, options) }
164
+ options[:idempotency_key] = nil
165
+ r.process(:ignore_result) { void(r.authorization, options) }
81
166
  end
82
167
  end
83
168
 
84
169
  def application_fee_from_response(response)
85
170
  return unless response.success?
86
-
87
- application_fees = response.params["data"].select { |fee| fee["object"] == "application_fee" }
88
- application_fees.first["id"] unless application_fees.empty?
171
+ response.params["application_fee"] unless response.params["application_fee"].empty?
89
172
  end
90
173
 
91
174
  def refund_application_fee(money, identification, options = {})
92
175
  return Response.new(false, "Application fee id could not be found") unless identification
93
176
 
94
- post = {:amount => amount(money)}
95
- options.merge!(:key => @fee_refund_api_key)
177
+ post = {}
178
+ add_amount(post, money, options)
179
+ options.merge!(:key => @fee_refund_api_key) if @fee_refund_api_key
180
+ options.delete(:stripe_account)
96
181
 
97
- commit(:post, "application_fees/#{CGI.escape(identification)}/refund", post, options)
182
+ refund_fee = commit(:post, "application_fees/#{CGI.escape(identification)}/refunds", post, options)
183
+ application_fee_response!(refund_fee, "Application fee could not be refunded: #{refund_fee.message}")
98
184
  end
99
185
 
100
- def store(creditcard, options = {})
186
+ # Note: creating a new credit card will not change the customer's existing default credit card (use :set_default => true)
187
+ def store(payment, options = {})
188
+ params = {}
101
189
  post = {}
102
- add_creditcard(post, creditcard, options)
103
- post[:description] = options[:description]
104
- post[:email] = options[:email]
105
190
 
106
- path = if options[:customer]
107
- "customers/#{CGI.escape(options[:customer])}"
191
+ if payment.is_a?(ApplePayPaymentToken)
192
+ token_exchange_response = tokenize_apple_pay_token(payment)
193
+ params = { card: token_exchange_response.params["token"]["id"] } if token_exchange_response.success?
194
+ elsif payment.is_a?(StripePaymentToken)
195
+ add_payment_token(params, payment, options)
196
+ elsif payment.is_a?(Check)
197
+ bank_token_response = tokenize_bank_account(payment)
198
+ return bank_token_response unless bank_token_response.success?
199
+ params = { source: bank_token_response.params["token"]["id"] }
108
200
  else
109
- 'customers'
201
+ add_creditcard(params, payment, options)
110
202
  end
111
203
 
112
- commit(:post, path, post, generate_meta(options))
204
+ post[:validate] = options[:validate] unless options[:validate].nil?
205
+ post[:description] = options[:description] if options[:description]
206
+ post[:email] = options[:email] if options[:email]
207
+
208
+ if options[:account]
209
+ add_external_account(post, params, payment)
210
+ commit(:post, "accounts/#{CGI.escape(options[:account])}/external_accounts", post, options)
211
+ elsif options[:customer]
212
+ MultiResponse.run(:first) do |r|
213
+ # The /cards endpoint does not update other customer parameters.
214
+ r.process { commit(:post, "customers/#{CGI.escape(options[:customer])}/cards", params, options) }
215
+
216
+ if options[:set_default] and r.success? and !r.params['id'].blank?
217
+ post[:default_card] = r.params['id']
218
+ end
219
+
220
+ if post.count > 0
221
+ r.process { update_customer(options[:customer], post) }
222
+ end
223
+ end
224
+ else
225
+ commit(:post, 'customers', post.merge(params), options)
226
+ end
113
227
  end
114
228
 
115
- def update(customer_id, creditcard, options = {})
116
- options = options.merge(:customer => customer_id)
117
- store(creditcard, options)
229
+ def update(customer_id, card_id, options = {})
230
+ commit(:post, "customers/#{CGI.escape(customer_id)}/cards/#{CGI.escape(card_id)}", options, options)
118
231
  end
119
232
 
120
- def unstore(customer_id, options = {})
121
- commit(:delete, "customers/#{CGI.escape(customer_id)}", nil, generate_meta(options))
233
+ def update_customer(customer_id, options = {})
234
+ commit(:post, "customers/#{CGI.escape(customer_id)}", options, options)
235
+ end
236
+
237
+ def unstore(identification, options = {}, deprecated_options = {})
238
+ customer_id, card_id = identification.split("|")
239
+
240
+ if options.kind_of?(String)
241
+ ActiveMerchant.deprecated "Passing the card_id as the 2nd parameter is deprecated. The response authorization includes both the customer_id and the card_id."
242
+ card_id ||= options
243
+ options = deprecated_options
244
+ end
245
+
246
+ commit(:delete, "customers/#{CGI.escape(customer_id)}/cards/#{CGI.escape(card_id)}", nil, options)
247
+ end
248
+
249
+ def tokenize_apple_pay_token(apple_pay_payment_token, options = {})
250
+ token_response = api_request(:post, "tokens?pk_token=#{CGI.escape(apple_pay_payment_token.payment_data.to_json)}")
251
+ success = !token_response.key?("error")
252
+
253
+ if success && token_response.key?("id")
254
+ Response.new(success, nil, token: token_response)
255
+ else
256
+ Response.new(success, token_response["error"]["message"])
257
+ end
258
+ end
259
+
260
+ def verify_credentials
261
+ begin
262
+ ssl_get(live_url + "charges/nonexistent", headers)
263
+ rescue ResponseError => e
264
+ return false if e.response.code.to_i == 401
265
+ end
266
+
267
+ true
268
+ end
269
+
270
+ def supports_scrubbing?
271
+ true
272
+ end
273
+
274
+ def scrub(transcript)
275
+ transcript.
276
+ gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
277
+ gsub(%r((&?three_d_secure\[cryptogram\]=)[\w=]*(&?)), '\1[FILTERED]\2').
278
+ gsub(%r((card\[cryptogram\]=)[^&]+(&?)), '\1[FILTERED]\2').
279
+ gsub(%r((card\[cvc\]=)\d+), '\1[FILTERED]').
280
+ gsub(%r((card\[emv_approval_data\]=)[^&]+(&?)), '\1[FILTERED]\2').
281
+ gsub(%r((card\[emv_auth_data\]=)[^&]+(&?)), '\1[FILTERED]\2').
282
+ gsub(%r((card\[encrypted_pin\]=)[^&]+(&?)), '\1[FILTERED]\2').
283
+ gsub(%r((card\[encrypted_pin_key_id\]=)[\w=]+(&?)), '\1[FILTERED]\2').
284
+ gsub(%r((card\[number\]=)\d+), '\1[FILTERED]').
285
+ gsub(%r((card\[swipe_data\]=)[^&]+(&?)), '\1[FILTERED]\2')
286
+ end
287
+
288
+ def supports_network_tokenization?
289
+ true
122
290
  end
123
291
 
124
292
  private
125
293
 
126
- def create_post_for_auth_or_purchase(money, creditcard, options)
294
+ class StripePaymentToken < PaymentToken
295
+ def type
296
+ 'stripe'
297
+ end
298
+ end
299
+
300
+ def create_post_for_auth_or_purchase(money, payment, options)
127
301
  post = {}
128
- add_amount(post, money, options)
129
- add_creditcard(post, creditcard, options)
130
- add_customer(post, options)
131
- add_customer_data(post,options)
132
- post[:description] = options[:description] || options[:email]
133
- add_flags(post, options)
302
+
303
+ if payment.is_a?(StripePaymentToken)
304
+ add_payment_token(post, payment, options)
305
+ else
306
+ add_creditcard(post, payment, options)
307
+ end
308
+
309
+ if emv_payment?(payment)
310
+ add_statement_address(post, options)
311
+ add_emv_metadata(post, payment)
312
+ else
313
+ add_amount(post, money, options, true)
314
+ add_customer_data(post, options)
315
+ post[:description] = options[:description]
316
+ post[:statement_descriptor] = options[:statement_description]
317
+ post[:receipt_email] = options[:receipt_email] if options[:receipt_email]
318
+ add_customer(post, payment, options)
319
+ add_flags(post, options)
320
+ end
321
+
322
+ add_metadata(post, options)
134
323
  add_application_fee(post, options)
324
+ add_exchange_rate(post, options)
325
+ add_destination(post, options)
135
326
  post
136
327
  end
137
328
 
138
- def add_amount(post, money, options)
139
- post[:amount] = amount(money)
140
- post[:currency] = (options[:currency] || currency(money)).downcase
329
+ def add_amount(post, money, options, include_currency = false)
330
+ currency = options[:currency] || currency(money)
331
+ post[:amount] = localized_amount(money, currency)
332
+ post[:currency] = currency.downcase if include_currency
141
333
  end
142
334
 
143
335
  def add_application_fee(post, options)
144
336
  post[:application_fee] = options[:application_fee] if options[:application_fee]
145
337
  end
146
338
 
339
+ def add_exchange_rate(post, options)
340
+ post[:exchange_rate] = options[:exchange_rate] if options[:exchange_rate]
341
+ end
342
+
343
+ def add_destination(post, options)
344
+ if options[:destination]
345
+ post[:destination] = {}
346
+ post[:destination][:account] = options[:destination]
347
+ post[:destination][:amount] = options[:destination_amount] if options[:destination_amount]
348
+ end
349
+ end
350
+
351
+ def add_expand_parameters(post, options)
352
+ post[:expand] ||= []
353
+ post[:expand].concat(Array.wrap(options[:expand]).map(&:to_sym)).uniq!
354
+ end
355
+
356
+ def add_external_account(post, card_params, payment)
357
+ external_account = {}
358
+ external_account[:object] ="card"
359
+ external_account[:currency] = (options[:currency] || currency(payment)).downcase
360
+ post[:external_account] = external_account.merge(card_params[:card])
361
+ end
362
+
147
363
  def add_customer_data(post, options)
148
- metadata_options = [:description,:browser_ip,:user_agent,:referrer]
364
+ metadata_options = [:description, :ip, :user_agent, :referrer]
149
365
  post.update(options.slice(*metadata_options))
150
366
 
151
367
  post[:external_id] = options[:order_id]
@@ -164,11 +380,35 @@ module ActiveMerchant #:nodoc:
164
380
  end
165
381
  end
166
382
 
383
+ def add_statement_address(post, options)
384
+ return unless statement_address = options[:statement_address]
385
+ return unless [:address1, :city, :zip, :state].all? { |key| statement_address[key].present? }
386
+
387
+ post[:statement_address] = {}
388
+ post[:statement_address][:line1] = statement_address[:address1]
389
+ post[:statement_address][:line2] = statement_address[:address2] if statement_address[:address2].present?
390
+ post[:statement_address][:city] = statement_address[:city]
391
+ post[:statement_address][:postal_code] = statement_address[:zip]
392
+ post[:statement_address][:state] = statement_address[:state]
393
+ end
394
+
167
395
  def add_creditcard(post, creditcard, options)
168
396
  card = {}
169
- if creditcard.respond_to?(:number)
397
+ if emv_payment?(creditcard)
398
+ add_emv_creditcard(post, creditcard.icc_data)
399
+ post[:card][:read_method] = "contactless" if creditcard.read_method == 'contactless'
400
+ if creditcard.encrypted_pin_cryptogram.present? && creditcard.encrypted_pin_ksn.present?
401
+ post[:card][:encrypted_pin] = creditcard.encrypted_pin_cryptogram
402
+ post[:card][:encrypted_pin_key_id] = creditcard.encrypted_pin_ksn
403
+ end
404
+ elsif creditcard.respond_to?(:number)
170
405
  if creditcard.respond_to?(:track_data) && creditcard.track_data.present?
171
406
  card[:swipe_data] = creditcard.track_data
407
+ if creditcard.respond_to?(:read_method)
408
+ card[:fallback_reason] = 'no_chip' if creditcard.read_method == 'fallback_no_chip'
409
+ card[:fallback_reason] = 'chip_error' if creditcard.read_method == 'fallback_chip_error'
410
+ card[:read_method] = "contactless_magstripe_mode" if creditcard.read_method == 'contactless_magstripe'
411
+ end
172
412
  else
173
413
  card[:number] = creditcard.number
174
414
  card[:exp_month] = creditcard.month
@@ -177,30 +417,70 @@ module ActiveMerchant #:nodoc:
177
417
  card[:name] = creditcard.name if creditcard.name
178
418
  end
179
419
 
420
+ if creditcard.is_a?(NetworkTokenizationCreditCard)
421
+ card[:cryptogram] = creditcard.payment_cryptogram
422
+ card[:eci] = creditcard.eci.rjust(2, '0') if creditcard.eci =~ /^[0-9]+$/
423
+ card[:tokenization_method] = creditcard.source.to_s
424
+ end
180
425
  post[:card] = card
426
+
181
427
  add_address(post, options)
182
428
  elsif creditcard.kind_of?(String)
183
429
  if options[:track_data]
184
430
  card[:swipe_data] = options[:track_data]
431
+ elsif creditcard.include?("|")
432
+ customer_id, card_id = creditcard.split("|")
433
+ card = card_id
434
+ post[:customer] = customer_id
185
435
  else
186
- card[:number] = creditcard
436
+ card = creditcard
187
437
  end
188
438
  post[:card] = card
189
439
  end
190
440
  end
191
441
 
192
- def add_customer(post, options)
193
- post[:customer] = options[:customer] if options[:customer] && post[:card].blank?
442
+ def add_emv_creditcard(post, icc_data, options = {})
443
+ post[:card] = { emv_auth_data: icc_data }
444
+ end
445
+
446
+ def add_payment_token(post, token, options = {})
447
+ post[:card] = token.payment_data["id"]
448
+ end
449
+
450
+ def add_customer(post, payment, options)
451
+ if options[:customer] && !payment.respond_to?(:number)
452
+ ActiveMerchant.deprecated "Passing the customer in the options is deprecated. Just use the response.authorization instead."
453
+ post[:customer] = options[:customer]
454
+ end
194
455
  end
195
456
 
196
457
  def add_flags(post, options)
197
458
  post[:uncaptured] = true if options[:uncaptured]
459
+ post[:recurring] = true if (options[:eci] == 'recurring' || options[:recurring])
198
460
  end
199
461
 
200
- def fetch_application_fees(identification, options = {})
462
+ def add_metadata(post, options = {})
463
+ post[:metadata] ||= {}
464
+ post[:metadata].merge!(options[:metadata]) if options[:metadata]
465
+ post[:metadata][:email] = options[:email] if options[:email]
466
+ post[:metadata][:order_id] = options[:order_id] if options[:order_id]
467
+ post.delete(:metadata) if post[:metadata].empty?
468
+ end
469
+
470
+ def add_emv_metadata(post, creditcard)
471
+ post[:metadata] ||= {}
472
+ post[:metadata][:card_read_method] = creditcard.read_method if creditcard.respond_to?(:read_method)
473
+ end
474
+
475
+ def fetch_application_fee(identification, options = {})
201
476
  options.merge!(:key => @fee_refund_api_key)
202
477
 
203
- commit(:get, "application_fees?charge=#{identification}", nil, options)
478
+ fetch_charge = commit(:get, "charges/#{CGI.escape(identification)}", nil, options)
479
+ application_fee_response!(fetch_charge, "Application fee id could not be retrieved: #{fetch_charge.message}")
480
+ end
481
+
482
+ def application_fee_response!(response, message)
483
+ response.success? ? response : Response.new(false, message)
204
484
  end
205
485
 
206
486
  def parse(body)
@@ -211,70 +491,94 @@ module ActiveMerchant #:nodoc:
211
491
  return nil unless params
212
492
 
213
493
  params.map do |key, value|
214
- next if value.blank?
494
+ next if value != false && value.blank?
215
495
  if value.is_a?(Hash)
216
496
  h = {}
217
497
  value.each do |k, v|
218
498
  h["#{key}[#{k}]"] = v unless v.blank?
219
499
  end
220
500
  post_data(h)
501
+ elsif value.is_a?(Array)
502
+ value.map { |v| "#{key}[]=#{CGI.escape(v.to_s)}" }.join("&")
221
503
  else
222
504
  "#{key}=#{CGI.escape(value.to_s)}"
223
505
  end
224
506
  end.compact.join("&")
225
507
  end
226
508
 
227
- def generate_meta(options)
228
- {:meta => {:ip => options[:ip]}}
229
- end
230
-
231
509
  def headers(options = {})
232
- @@ua ||= JSON.dump({
233
- :bindings_version => ActiveMerchant::VERSION,
234
- :lang => 'ruby',
235
- :lang_version => "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})",
236
- :platform => RUBY_PLATFORM,
237
- :publisher => 'active_merchant',
238
- :uname => (RUBY_PLATFORM =~ /linux|darwin/i ? `uname -a 2>/dev/null`.strip : nil)
239
- })
240
-
241
- key = options[:key] || @api_key
510
+ key = options[:key] || @api_key
511
+ idempotency_key = options[:idempotency_key]
242
512
 
243
- {
513
+ headers = {
244
514
  "Authorization" => "Basic " + Base64.encode64(key.to_s + ":").strip,
245
515
  "User-Agent" => "Stripe/v1 ActiveMerchantBindings/#{ActiveMerchant::VERSION}",
246
- "X-Stripe-Client-User-Agent" => @@ua,
247
- "X-Stripe-Client-User-Metadata" => options[:meta].to_json
516
+ "Stripe-Version" => api_version(options),
517
+ "X-Stripe-Client-User-Agent" => stripe_client_user_agent(options),
518
+ "X-Stripe-Client-User-Metadata" => {:ip => options[:ip]}.to_json
248
519
  }
520
+ headers.merge!("Idempotency-Key" => idempotency_key) if idempotency_key
521
+ headers.merge!("Stripe-Account" => options[:stripe_account]) if options[:stripe_account]
522
+ headers
523
+ end
524
+
525
+ def stripe_client_user_agent(options)
526
+ return user_agent unless options[:application]
527
+ JSON.dump(JSON.parse(user_agent).merge!({application: options[:application]}))
528
+ end
529
+
530
+ def api_version(options)
531
+ options[:version] || @options[:version] || "2015-04-07"
249
532
  end
250
533
 
251
- def commit(method, url, parameters=nil, options = {})
534
+ def api_request(method, endpoint, parameters = nil, options = {})
252
535
  raw_response = response = nil
253
- success = false
254
536
  begin
255
- raw_response = ssl_request(method, self.live_url + url, post_data(parameters), headers(options))
537
+ raw_response = ssl_request(method, self.live_url + endpoint, post_data(parameters), headers(options))
256
538
  response = parse(raw_response)
257
- success = !response.key?("error")
258
539
  rescue ResponseError => e
259
540
  raw_response = e.response.body
260
541
  response = response_error(raw_response)
261
542
  rescue JSON::ParserError
262
543
  response = json_error(raw_response)
263
544
  end
545
+ response
546
+ end
547
+
548
+ def commit(method, url, parameters = nil, options = {})
549
+ add_expand_parameters(parameters, options) if parameters
550
+ response = api_request(method, url, parameters, options)
264
551
 
265
- card = response["card"] || response["active_card"] || {}
552
+ success = !response.key?("error")
553
+
554
+ card = card_from_response(response)
266
555
  avs_code = AVS_CODE_TRANSLATOR["line1: #{card["address_line1_check"]}, zip: #{card["address_zip_check"]}"]
267
556
  cvc_code = CVC_CODE_TRANSLATOR[card["cvc_check"]]
557
+
268
558
  Response.new(success,
269
559
  success ? "Transaction approved" : response["error"]["message"],
270
560
  response,
271
- :test => response.has_key?("livemode") ? !response["livemode"] : false,
272
- :authorization => response["id"],
561
+ :test => response_is_test?(response),
562
+ :authorization => authorization_from(success, url, method, response),
273
563
  :avs_result => { :code => avs_code },
274
- :cvv_result => cvc_code
564
+ :cvv_result => cvc_code,
565
+ :emv_authorization => emv_authorization_from_response(response),
566
+ :error_code => success ? nil : error_code_from(response)
275
567
  )
276
568
  end
277
569
 
570
+ def authorization_from(success, url, method, response)
571
+ return response["error"]["charge"] unless success
572
+
573
+ if url == "customers"
574
+ [response["id"], response["sources"]["data"].first["id"]].join("|")
575
+ elsif method == :post && url.match(/customers\/.*\/cards/)
576
+ [response["customer"], response["id"]].join("|")
577
+ else
578
+ response["id"]
579
+ end
580
+ end
581
+
278
582
  def response_error(raw_response)
279
583
  begin
280
584
  parse(raw_response)
@@ -292,6 +596,81 @@ module ActiveMerchant #:nodoc:
292
596
  }
293
597
  }
294
598
  end
599
+
600
+ def response_is_test?(response)
601
+ if response.has_key?('livemode')
602
+ !response['livemode']
603
+ elsif response['charge'].is_a?(Hash) && response['charge'].has_key?('livemode')
604
+ !response['charge']['livemode']
605
+ else
606
+ false
607
+ end
608
+ end
609
+
610
+ def emv_payment?(payment)
611
+ payment.respond_to?(:emv?) && payment.emv?
612
+ end
613
+
614
+ def quickchip_payment?(payment)
615
+ payment.respond_to?(:read_method) && payment.read_method == 'contact_quickchip'
616
+ end
617
+
618
+ def card_from_response(response)
619
+ response["card"] || response["active_card"] || response["source"] || {}
620
+ end
621
+
622
+ def emv_authorization_from_response(response)
623
+ return response["error"]["emv_auth_data"] if response["error"]
624
+
625
+ card_from_response(response)["emv_auth_data"]
626
+ end
627
+
628
+ def error_code_from(response)
629
+ code = response['error']['code']
630
+ decline_code = response['error']['decline_code'] if code == 'card_declined'
631
+
632
+ error_code = STANDARD_ERROR_CODE_MAPPING[decline_code]
633
+ error_code ||= STANDARD_ERROR_CODE_MAPPING[code]
634
+ error_code
635
+ end
636
+
637
+ def tokenize_bank_account(bank_account, options = {})
638
+ account_holder_type = BANK_ACCOUNT_HOLDER_TYPE_MAPPING[bank_account.account_holder_type]
639
+
640
+ post = {
641
+ bank_account: {
642
+ account_number: bank_account.account_number,
643
+ country: 'US',
644
+ currency: 'usd',
645
+ routing_number: bank_account.routing_number,
646
+ name: bank_account.name,
647
+ account_holder_type: account_holder_type,
648
+ }
649
+ }
650
+
651
+ token_response = api_request(:post, "tokens?#{post_data(post)}")
652
+ success = token_response["error"].nil?
653
+
654
+ if success && token_response["id"]
655
+ Response.new(success, nil, token: token_response)
656
+ else
657
+ Response.new(success, token_response["error"]["message"])
658
+ end
659
+ end
660
+
661
+ def ach?(payment_method)
662
+ case payment_method
663
+ when String, nil
664
+ false
665
+ else
666
+ card_brand(payment_method) == "check"
667
+ end
668
+ end
669
+
670
+ def auth_minimum_amount(options)
671
+ return 100 unless options[:currency]
672
+ return MINIMUM_AUTHORIZE_AMOUNTS[options[:currency].upcase] || 100
673
+ end
295
674
  end
296
675
  end
297
676
  end