archetype2142_activemerchant 1.124.0

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