swiss-activemerchant 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (287) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +4033 -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 +112 -0
  10. data/lib/active_merchant/billing/compatibility.rb +118 -0
  11. data/lib/active_merchant/billing/credit_card.rb +451 -0
  12. data/lib/active_merchant/billing/credit_card_formatting.rb +24 -0
  13. data/lib/active_merchant/billing/credit_card_methods.rb +512 -0
  14. data/lib/active_merchant/billing/cvv_result.rb +37 -0
  15. data/lib/active_merchant/billing/gateway.rb +332 -0
  16. data/lib/active_merchant/billing/gateways/adyen.rb +774 -0
  17. data/lib/active_merchant/billing/gateways/airwallex.rb +370 -0
  18. data/lib/active_merchant/billing/gateways/alelo.rb +256 -0
  19. data/lib/active_merchant/billing/gateways/allied_wallet.rb +205 -0
  20. data/lib/active_merchant/billing/gateways/authorize_net.rb +1125 -0
  21. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +424 -0
  22. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +977 -0
  23. data/lib/active_merchant/billing/gateways/axcessms.rb +243 -0
  24. data/lib/active_merchant/billing/gateways/balanced.rb +263 -0
  25. data/lib/active_merchant/billing/gateways/bambora_apac.rb +222 -0
  26. data/lib/active_merchant/billing/gateways/bank_frick.rb +225 -0
  27. data/lib/active_merchant/billing/gateways/banwire.rb +116 -0
  28. data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +397 -0
  29. data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +15 -0
  30. data/lib/active_merchant/billing/gateways/be2bill.rb +131 -0
  31. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +474 -0
  32. data/lib/active_merchant/billing/gateways/beanstream.rb +238 -0
  33. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +57 -0
  34. data/lib/active_merchant/billing/gateways/blue_pay.rb +549 -0
  35. data/lib/active_merchant/billing/gateways/blue_snap.rb +644 -0
  36. data/lib/active_merchant/billing/gateways/bogus.rb +190 -0
  37. data/lib/active_merchant/billing/gateways/borgun.rb +272 -0
  38. data/lib/active_merchant/billing/gateways/bpoint.rb +277 -0
  39. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +28 -0
  40. data/lib/active_merchant/billing/gateways/braintree/token_nonce.rb +113 -0
  41. data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
  42. data/lib/active_merchant/billing/gateways/braintree_blue.rb +952 -0
  43. data/lib/active_merchant/billing/gateways/braintree_orange.rb +19 -0
  44. data/lib/active_merchant/billing/gateways/bridge_pay.rb +244 -0
  45. data/lib/active_merchant/billing/gateways/cams.rb +230 -0
  46. data/lib/active_merchant/billing/gateways/card_connect.rb +338 -0
  47. data/lib/active_merchant/billing/gateways/card_save.rb +21 -0
  48. data/lib/active_merchant/billing/gateways/card_stream.rb +394 -0
  49. data/lib/active_merchant/billing/gateways/cardknox.rb +327 -0
  50. data/lib/active_merchant/billing/gateways/cardprocess.rb +256 -0
  51. data/lib/active_merchant/billing/gateways/cashnet.rb +235 -0
  52. data/lib/active_merchant/billing/gateways/cc5.rb +198 -0
  53. data/lib/active_merchant/billing/gateways/cecabank.rb +249 -0
  54. data/lib/active_merchant/billing/gateways/cenpos.rb +328 -0
  55. data/lib/active_merchant/billing/gateways/checkout.rb +212 -0
  56. data/lib/active_merchant/billing/gateways/checkout_v2.rb +587 -0
  57. data/lib/active_merchant/billing/gateways/citrus_pay.rb +21 -0
  58. data/lib/active_merchant/billing/gateways/clearhaus.rb +219 -0
  59. data/lib/active_merchant/billing/gateways/commerce_hub.rb +366 -0
  60. data/lib/active_merchant/billing/gateways/commercegate.rb +142 -0
  61. data/lib/active_merchant/billing/gateways/conekta.rb +230 -0
  62. data/lib/active_merchant/billing/gateways/creditcall.rb +272 -0
  63. data/lib/active_merchant/billing/gateways/credorax.rb +526 -0
  64. data/lib/active_merchant/billing/gateways/ct_payment.rb +269 -0
  65. data/lib/active_merchant/billing/gateways/culqi.rb +279 -0
  66. data/lib/active_merchant/billing/gateways/cyber_source/cyber_source_common.rb +36 -0
  67. data/lib/active_merchant/billing/gateways/cyber_source.rb +1148 -0
  68. data/lib/active_merchant/billing/gateways/cyber_source_rest.rb +454 -0
  69. data/lib/active_merchant/billing/gateways/d_local.rb +343 -0
  70. data/lib/active_merchant/billing/gateways/data_cash.rb +302 -0
  71. data/lib/active_merchant/billing/gateways/decidir.rb +358 -0
  72. data/lib/active_merchant/billing/gateways/decidir_plus.rb +344 -0
  73. data/lib/active_merchant/billing/gateways/dibs.rb +199 -0
  74. data/lib/active_merchant/billing/gateways/digitzs.rb +295 -0
  75. data/lib/active_merchant/billing/gateways/ebanx.rb +346 -0
  76. data/lib/active_merchant/billing/gateways/efsnet.rb +215 -0
  77. data/lib/active_merchant/billing/gateways/elavon.rb +475 -0
  78. data/lib/active_merchant/billing/gateways/element.rb +406 -0
  79. data/lib/active_merchant/billing/gateways/epay.rb +296 -0
  80. data/lib/active_merchant/billing/gateways/evo_ca.rb +307 -0
  81. data/lib/active_merchant/billing/gateways/eway.rb +226 -0
  82. data/lib/active_merchant/billing/gateways/eway_managed.rb +289 -0
  83. data/lib/active_merchant/billing/gateways/eway_rapid.rb +578 -0
  84. data/lib/active_merchant/billing/gateways/exact.rb +219 -0
  85. data/lib/active_merchant/billing/gateways/ezic.rb +195 -0
  86. data/lib/active_merchant/billing/gateways/fat_zebra.rb +223 -0
  87. data/lib/active_merchant/billing/gateways/federated_canada.rb +158 -0
  88. data/lib/active_merchant/billing/gateways/finansbank.rb +22 -0
  89. data/lib/active_merchant/billing/gateways/first_giving.rb +143 -0
  90. data/lib/active_merchant/billing/gateways/first_pay.rb +182 -0
  91. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +452 -0
  92. data/lib/active_merchant/billing/gateways/firstdata_e4_v27.rb +505 -0
  93. data/lib/active_merchant/billing/gateways/flo2cash.rb +215 -0
  94. data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +20 -0
  95. data/lib/active_merchant/billing/gateways/fluidpay.rb +275 -0
  96. data/lib/active_merchant/billing/gateways/forte.rb +286 -0
  97. data/lib/active_merchant/billing/gateways/garanti.rb +256 -0
  98. data/lib/active_merchant/billing/gateways/global_collect.rb +580 -0
  99. data/lib/active_merchant/billing/gateways/global_transport.rb +193 -0
  100. data/lib/active_merchant/billing/gateways/hdfc.rb +205 -0
  101. data/lib/active_merchant/billing/gateways/hps.rb +472 -0
  102. data/lib/active_merchant/billing/gateways/iats_payments.rb +312 -0
  103. data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +15 -0
  104. data/lib/active_merchant/billing/gateways/inspire.rb +213 -0
  105. data/lib/active_merchant/billing/gateways/instapay.rb +159 -0
  106. data/lib/active_merchant/billing/gateways/ipg.rb +420 -0
  107. data/lib/active_merchant/billing/gateways/ipp.rb +176 -0
  108. data/lib/active_merchant/billing/gateways/iridium.rb +467 -0
  109. data/lib/active_merchant/billing/gateways/itransact.rb +448 -0
  110. data/lib/active_merchant/billing/gateways/iveri.rb +290 -0
  111. data/lib/active_merchant/billing/gateways/ixopay.rb +320 -0
  112. data/lib/active_merchant/billing/gateways/jetpay.rb +395 -0
  113. data/lib/active_merchant/billing/gateways/jetpay_v2.rb +432 -0
  114. data/lib/active_merchant/billing/gateways/klarna.rb +317 -0
  115. data/lib/active_merchant/billing/gateways/komoju.rb +115 -0
  116. data/lib/active_merchant/billing/gateways/kushki.rb +297 -0
  117. data/lib/active_merchant/billing/gateways/latitude19.rb +412 -0
  118. data/lib/active_merchant/billing/gateways/linkpoint.rb +448 -0
  119. data/lib/active_merchant/billing/gateways/litle.rb +643 -0
  120. data/lib/active_merchant/billing/gateways/mastercard.rb +286 -0
  121. data/lib/active_merchant/billing/gateways/maxipago.rb +220 -0
  122. data/lib/active_merchant/billing/gateways/mercado_pago.rb +348 -0
  123. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +228 -0
  124. data/lib/active_merchant/billing/gateways/merchant_one.rb +110 -0
  125. data/lib/active_merchant/billing/gateways/merchant_partners.rb +245 -0
  126. data/lib/active_merchant/billing/gateways/merchant_ware.rb +313 -0
  127. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +284 -0
  128. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +248 -0
  129. data/lib/active_merchant/billing/gateways/mercury.rb +352 -0
  130. data/lib/active_merchant/billing/gateways/metrics_global.rb +293 -0
  131. data/lib/active_merchant/billing/gateways/micropayment.rb +182 -0
  132. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  133. data/lib/active_merchant/billing/gateways/migs.rb +329 -0
  134. data/lib/active_merchant/billing/gateways/mit.rb +260 -0
  135. data/lib/active_merchant/billing/gateways/modern_payments.rb +37 -0
  136. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +215 -0
  137. data/lib/active_merchant/billing/gateways/moka.rb +290 -0
  138. data/lib/active_merchant/billing/gateways/monei.rb +424 -0
  139. data/lib/active_merchant/billing/gateways/moneris.rb +488 -0
  140. data/lib/active_merchant/billing/gateways/money_movers.rb +150 -0
  141. data/lib/active_merchant/billing/gateways/mundipagg.rb +366 -0
  142. data/lib/active_merchant/billing/gateways/nab_transact.rb +299 -0
  143. data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +163 -0
  144. data/lib/active_merchant/billing/gateways/net_registry.rb +198 -0
  145. data/lib/active_merchant/billing/gateways/netaxept.rb +180 -0
  146. data/lib/active_merchant/billing/gateways/netbanx.rb +376 -0
  147. data/lib/active_merchant/billing/gateways/netbilling.rb +229 -0
  148. data/lib/active_merchant/billing/gateways/netpay.rb +223 -0
  149. data/lib/active_merchant/billing/gateways/network_merchants.rb +238 -0
  150. data/lib/active_merchant/billing/gateways/nmi.rb +396 -0
  151. data/lib/active_merchant/billing/gateways/ogone.rb +509 -0
  152. data/lib/active_merchant/billing/gateways/omise.rb +323 -0
  153. data/lib/active_merchant/billing/gateways/openpay.rb +246 -0
  154. data/lib/active_merchant/billing/gateways/opp.rb +394 -0
  155. data/lib/active_merchant/billing/gateways/optimal_payment.rb +331 -0
  156. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +45 -0
  157. data/lib/active_merchant/billing/gateways/orbital.rb +1267 -0
  158. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +206 -0
  159. data/lib/active_merchant/billing/gateways/pagarme.rb +239 -0
  160. data/lib/active_merchant/billing/gateways/pago_facil.rb +120 -0
  161. data/lib/active_merchant/billing/gateways/pay_arc.rb +392 -0
  162. data/lib/active_merchant/billing/gateways/pay_conex.rb +245 -0
  163. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +277 -0
  164. data/lib/active_merchant/billing/gateways/pay_hub.rb +213 -0
  165. data/lib/active_merchant/billing/gateways/pay_junction.rb +390 -0
  166. data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +206 -0
  167. data/lib/active_merchant/billing/gateways/pay_secure.rb +110 -0
  168. data/lib/active_merchant/billing/gateways/pay_trace.rb +450 -0
  169. data/lib/active_merchant/billing/gateways/paybox_direct.rb +224 -0
  170. data/lib/active_merchant/billing/gateways/payeezy.rb +513 -0
  171. data/lib/active_merchant/billing/gateways/payex.rb +409 -0
  172. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +235 -0
  173. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +42 -0
  174. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  175. data/lib/active_merchant/billing/gateways/payflow.rb +473 -0
  176. data/lib/active_merchant/billing/gateways/payflow_express.rb +220 -0
  177. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +14 -0
  178. data/lib/active_merchant/billing/gateways/payflow_uk.rb +20 -0
  179. data/lib/active_merchant/billing/gateways/payment_express.rb +373 -0
  180. data/lib/active_merchant/billing/gateways/paymentez.rb +365 -0
  181. data/lib/active_merchant/billing/gateways/paymill.rb +369 -0
  182. data/lib/active_merchant/billing/gateways/paynetworx.rb +227 -0
  183. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +718 -0
  184. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +69 -0
  185. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +262 -0
  186. data/lib/active_merchant/billing/gateways/paypal.rb +136 -0
  187. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  188. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +44 -0
  189. data/lib/active_merchant/billing/gateways/paypal_express.rb +272 -0
  190. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  191. data/lib/active_merchant/billing/gateways/paypal_standard.rb +281 -0
  192. data/lib/active_merchant/billing/gateways/paysafe.rb +420 -0
  193. data/lib/active_merchant/billing/gateways/payscout.rb +159 -0
  194. data/lib/active_merchant/billing/gateways/paystation.rb +204 -0
  195. data/lib/active_merchant/billing/gateways/payu_in.rb +249 -0
  196. data/lib/active_merchant/billing/gateways/payu_latam.rb +482 -0
  197. data/lib/active_merchant/billing/gateways/payway.rb +207 -0
  198. data/lib/active_merchant/billing/gateways/payway_dot_com.rb +253 -0
  199. data/lib/active_merchant/billing/gateways/pin.rb +273 -0
  200. data/lib/active_merchant/billing/gateways/pixxels.rb +263 -0
  201. data/lib/active_merchant/billing/gateways/plexo.rb +308 -0
  202. data/lib/active_merchant/billing/gateways/plugnpay.rb +283 -0
  203. data/lib/active_merchant/billing/gateways/priority.rb +392 -0
  204. data/lib/active_merchant/billing/gateways/pro_pay.rb +325 -0
  205. data/lib/active_merchant/billing/gateways/psigate.rb +227 -0
  206. data/lib/active_merchant/billing/gateways/psl_card.rb +295 -0
  207. data/lib/active_merchant/billing/gateways/qbms.rb +302 -0
  208. data/lib/active_merchant/billing/gateways/quantum.rb +274 -0
  209. data/lib/active_merchant/billing/gateways/quickbooks.rb +377 -0
  210. data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +184 -0
  211. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +297 -0
  212. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +226 -0
  213. data/lib/active_merchant/billing/gateways/quickpay.rb +24 -0
  214. data/lib/active_merchant/billing/gateways/qvalent.rb +305 -0
  215. data/lib/active_merchant/billing/gateways/rapyd.rb +319 -0
  216. data/lib/active_merchant/billing/gateways/reach.rb +277 -0
  217. data/lib/active_merchant/billing/gateways/realex.rb +400 -0
  218. data/lib/active_merchant/billing/gateways/redsys.rb +723 -0
  219. data/lib/active_merchant/billing/gateways/s5.rb +247 -0
  220. data/lib/active_merchant/billing/gateways/safe_charge.rb +298 -0
  221. data/lib/active_merchant/billing/gateways/sage.rb +446 -0
  222. data/lib/active_merchant/billing/gateways/sage_pay.rb +434 -0
  223. data/lib/active_merchant/billing/gateways/sallie_mae.rb +141 -0
  224. data/lib/active_merchant/billing/gateways/secure_net.rb +260 -0
  225. data/lib/active_merchant/billing/gateways/secure_pay.rb +191 -0
  226. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +290 -0
  227. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +103 -0
  228. data/lib/active_merchant/billing/gateways/securion_pay.rb +305 -0
  229. data/lib/active_merchant/billing/gateways/shift4.rb +345 -0
  230. data/lib/active_merchant/billing/gateways/simetrik.rb +368 -0
  231. data/lib/active_merchant/billing/gateways/skip_jack.rb +450 -0
  232. data/lib/active_merchant/billing/gateways/smart_ps.rb +274 -0
  233. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
  234. data/lib/active_merchant/billing/gateways/spreedly_core.rb +312 -0
  235. data/lib/active_merchant/billing/gateways/stripe.rb +866 -0
  236. data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +602 -0
  237. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +151 -0
  238. data/lib/active_merchant/billing/gateways/telr.rb +273 -0
  239. data/lib/active_merchant/billing/gateways/tns.rb +23 -0
  240. data/lib/active_merchant/billing/gateways/trans_first.rb +240 -0
  241. data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +612 -0
  242. data/lib/active_merchant/billing/gateways/transact_pro.rb +222 -0
  243. data/lib/active_merchant/billing/gateways/transax.rb +21 -0
  244. data/lib/active_merchant/billing/gateways/transnational.rb +9 -0
  245. data/lib/active_merchant/billing/gateways/trexle.rb +221 -0
  246. data/lib/active_merchant/billing/gateways/trust_commerce.rb +500 -0
  247. data/lib/active_merchant/billing/gateways/usa_epay.rb +24 -0
  248. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1612 -0
  249. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +367 -0
  250. data/lib/active_merchant/billing/gateways/vanco.rb +303 -0
  251. data/lib/active_merchant/billing/gateways/verifi.rb +224 -0
  252. data/lib/active_merchant/billing/gateways/viaklix.rb +171 -0
  253. data/lib/active_merchant/billing/gateways/visanet_peru.rb +250 -0
  254. data/lib/active_merchant/billing/gateways/vpos.rb +223 -0
  255. data/lib/active_merchant/billing/gateways/webpay.rb +97 -0
  256. data/lib/active_merchant/billing/gateways/wepay.rb +235 -0
  257. data/lib/active_merchant/billing/gateways/wirecard.rb +430 -0
  258. data/lib/active_merchant/billing/gateways/wompi.rb +197 -0
  259. data/lib/active_merchant/billing/gateways/world_net.rb +345 -0
  260. data/lib/active_merchant/billing/gateways/worldpay.rb +1050 -0
  261. data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +208 -0
  262. data/lib/active_merchant/billing/gateways/worldpay_us.rb +221 -0
  263. data/lib/active_merchant/billing/gateways.rb +14 -0
  264. data/lib/active_merchant/billing/model.rb +30 -0
  265. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +39 -0
  266. data/lib/active_merchant/billing/payment_token.rb +21 -0
  267. data/lib/active_merchant/billing/rails.rb +3 -0
  268. data/lib/active_merchant/billing/response.rb +120 -0
  269. data/lib/active_merchant/billing/three_d_secure_eci_mapper.rb +27 -0
  270. data/lib/active_merchant/billing.rb +16 -0
  271. data/lib/active_merchant/connection.rb +194 -0
  272. data/lib/active_merchant/country.rb +338 -0
  273. data/lib/active_merchant/empty.rb +20 -0
  274. data/lib/active_merchant/errors.rb +38 -0
  275. data/lib/active_merchant/net_http_ssl_connection.rb +11 -0
  276. data/lib/active_merchant/network_connection_retries.rb +78 -0
  277. data/lib/active_merchant/post_data.rb +26 -0
  278. data/lib/active_merchant/posts_data.rb +92 -0
  279. data/lib/active_merchant/version.rb +3 -0
  280. data/lib/active_merchant.rb +63 -0
  281. data/lib/activemerchant.rb +1 -0
  282. data/lib/certs/cacert.pem +3214 -0
  283. data/lib/support/gateway_support.rb +69 -0
  284. data/lib/support/outbound_hosts.rb +28 -0
  285. data/lib/support/ssl_verify.rb +88 -0
  286. data/lib/support/ssl_version.rb +86 -0
  287. metadata +506 -0
@@ -0,0 +1,774 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class AdyenGateway < Gateway
4
+ # we recommend setting up merchant-specific endpoints.
5
+ # https://docs.adyen.com/developers/api-manual#apiendpoints
6
+ self.test_url = 'https://pal-test.adyen.com/pal/servlet/'
7
+ self.live_url = 'https://pal-live.adyen.com/pal/servlet/'
8
+
9
+ self.supported_countries = %w(AT AU BE BG BR CH CY CZ DE DK EE ES FI FR GB GI GR HK HU IE IS IT LI LT LU LV MC MT MX NL NO PL PT RO SE SG SK SI US)
10
+ self.default_currency = 'USD'
11
+ self.currencies_without_fractions = %w(CVE DJF GNF IDR JPY KMF KRW PYG RWF UGX VND VUV XAF XOF XPF)
12
+ self.currencies_with_three_decimal_places = %w(BHD IQD JOD KWD LYD OMR TND)
13
+ self.supported_cardtypes = %i[visa master american_express diners_club jcb dankort maestro discover elo naranja cabal unionpay]
14
+
15
+ self.money_format = :cents
16
+
17
+ self.homepage_url = 'https://www.adyen.com/'
18
+ self.display_name = 'Adyen'
19
+
20
+ PAYMENT_API_VERSION = 'v68'
21
+ RECURRING_API_VERSION = 'v68'
22
+
23
+ STANDARD_ERROR_CODE_MAPPING = {
24
+ '0' => STANDARD_ERROR_CODE[:processing_error],
25
+ '10' => STANDARD_ERROR_CODE[:config_error],
26
+ '100' => STANDARD_ERROR_CODE[:invalid_amount],
27
+ '101' => STANDARD_ERROR_CODE[:incorrect_number],
28
+ '103' => STANDARD_ERROR_CODE[:invalid_cvc],
29
+ '104' => STANDARD_ERROR_CODE[:incorrect_address],
30
+ '131' => STANDARD_ERROR_CODE[:incorrect_address],
31
+ '132' => STANDARD_ERROR_CODE[:incorrect_address],
32
+ '133' => STANDARD_ERROR_CODE[:incorrect_address],
33
+ '134' => STANDARD_ERROR_CODE[:incorrect_address],
34
+ '135' => STANDARD_ERROR_CODE[:incorrect_address]
35
+ }
36
+
37
+ def initialize(options = {})
38
+ requires!(options, :username, :password, :merchant_account)
39
+ @username, @password, @merchant_account = options.values_at(:username, :password, :merchant_account)
40
+ super
41
+ end
42
+
43
+ def purchase(money, payment, options = {})
44
+ if options[:execute_threed] || options[:threed_dynamic]
45
+ authorize(money, payment, options)
46
+ else
47
+ MultiResponse.run do |r|
48
+ r.process { authorize(money, payment, options) }
49
+ r.process { capture(money, r.authorization, capture_options(options)) }
50
+ end
51
+ end
52
+ end
53
+
54
+ def authorize(money, payment, options = {})
55
+ requires!(options, :order_id)
56
+ post = init_post(options)
57
+ add_invoice(post, money, options)
58
+ add_payment(post, payment, options)
59
+ add_extra_data(post, payment, options)
60
+ add_stored_credentials(post, payment, options)
61
+ add_address(post, options)
62
+ add_installments(post, options) if options[:installments]
63
+ add_3ds(post, options)
64
+ add_3ds_authenticated_data(post, options)
65
+ add_splits(post, options)
66
+ add_recurring_contract(post, options)
67
+ add_network_transaction_reference(post, options)
68
+ add_application_info(post, options)
69
+ add_level_2_data(post, options)
70
+ add_level_3_data(post, options)
71
+ commit('authorise', post, options)
72
+ end
73
+
74
+ def capture(money, authorization, options = {})
75
+ post = init_post(options)
76
+ add_invoice_for_modification(post, money, options)
77
+ add_reference(post, authorization, options)
78
+ add_splits(post, options)
79
+ add_network_transaction_reference(post, options)
80
+ add_shopper_statement(post, options)
81
+ commit('capture', post, options)
82
+ end
83
+
84
+ def refund(money, authorization, options = {})
85
+ post = init_post(options)
86
+ add_invoice_for_modification(post, money, options)
87
+ add_reference(post, authorization, options)
88
+ add_splits(post, options)
89
+ add_network_transaction_reference(post, options)
90
+ commit('refund', post, options)
91
+ end
92
+
93
+ def credit(money, payment, options = {})
94
+ action = 'refundWithData'
95
+ post = init_post(options)
96
+ add_invoice(post, money, options)
97
+ add_payment(post, payment, options, action)
98
+ add_shopper_reference(post, options)
99
+ add_network_transaction_reference(post, options)
100
+ commit(action, post, options)
101
+ end
102
+
103
+ def void(authorization, options = {})
104
+ post = init_post(options)
105
+ endpoint = options[:cancel_or_refund] ? 'cancelOrRefund' : 'cancel'
106
+ add_reference(post, authorization, options)
107
+ add_network_transaction_reference(post, options)
108
+ commit(endpoint, post, options)
109
+ end
110
+
111
+ def adjust(money, authorization, options = {})
112
+ post = init_post(options)
113
+ add_invoice_for_modification(post, money, options)
114
+ add_reference(post, authorization, options)
115
+ add_extra_data(post, nil, options)
116
+ commit('adjustAuthorisation', post, options)
117
+ end
118
+
119
+ def store(credit_card, options = {})
120
+ requires!(options, :order_id)
121
+ post = init_post(options)
122
+ add_invoice(post, 0, options)
123
+ add_payment(post, credit_card, options)
124
+ add_extra_data(post, credit_card, options)
125
+ add_stored_credentials(post, credit_card, options)
126
+ add_address(post, options)
127
+ add_network_transaction_reference(post, options)
128
+ options[:recurring_contract_type] ||= 'RECURRING'
129
+ add_recurring_contract(post, options)
130
+
131
+ action = options[:tokenize_only] ? 'storeToken' : 'authorise'
132
+
133
+ initial_response = commit(action, post, options)
134
+
135
+ if initial_response.success? && card_not_stored?(initial_response)
136
+ unsupported_failure_response(initial_response)
137
+ else
138
+ initial_response
139
+ end
140
+ end
141
+
142
+ def unstore(options = {})
143
+ requires!(options, :shopper_reference, :recurring_detail_reference)
144
+ post = {}
145
+
146
+ add_shopper_reference(post, options)
147
+ add_merchant_account(post, options)
148
+ post[:recurringDetailReference] = options[:recurring_detail_reference]
149
+
150
+ commit('disable', post, options)
151
+ end
152
+
153
+ def verify(credit_card, options = {})
154
+ amount = options[:verify_amount]&.to_i || 0
155
+ MultiResponse.run(:use_first_response) do |r|
156
+ r.process { authorize(amount, credit_card, options) }
157
+ options[:idempotency_key] = nil
158
+ r.process(:ignore_result) { void(r.authorization, options) }
159
+ end
160
+ end
161
+
162
+ def supports_scrubbing?
163
+ true
164
+ end
165
+
166
+ def supports_network_tokenization?
167
+ true
168
+ end
169
+
170
+ def scrub(transcript)
171
+ transcript.
172
+ gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
173
+ gsub(%r(("number\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
174
+ gsub(%r(("cvc\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
175
+ gsub(%r(("cavv\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
176
+ gsub(%r(("bankLocationId\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
177
+ gsub(%r(("iban\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
178
+ gsub(%r(("bankAccountNumber\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]')
179
+ end
180
+
181
+ private
182
+
183
+ AVS_MAPPING = {
184
+ '0' => 'R', # Unknown
185
+ '1' => 'A', # Address matches, postal code doesn't
186
+ '2' => 'N', # Neither postal code nor address match
187
+ '3' => 'R', # AVS unavailable
188
+ '4' => 'E', # AVS not supported for this card type
189
+ '5' => 'U', # No AVS data provided
190
+ '6' => 'Z', # Postal code matches, address doesn't match
191
+ '7' => 'D', # Both postal code and address match
192
+ '8' => 'U', # Address not checked, postal code unknown
193
+ '9' => 'B', # Address matches, postal code unknown
194
+ '10' => 'N', # Address doesn't match, postal code unknown
195
+ '11' => 'U', # Postal code not checked, address unknown
196
+ '12' => 'B', # Address matches, postal code not checked
197
+ '13' => 'U', # Address doesn't match, postal code not checked
198
+ '14' => 'P', # Postal code matches, address unknown
199
+ '15' => 'P', # Postal code matches, address not checked
200
+ '16' => 'N', # Postal code doesn't match, address unknown
201
+ '17' => 'U', # Postal code doesn't match, address not checked
202
+ '18' => 'I', # Neither postal code nor address were checked
203
+ '19' => 'L', # Name and postal code matches.
204
+ '20' => 'V', # Name, address and postal code matches.
205
+ '21' => 'O', # Name and address matches.
206
+ '22' => 'K', # Name matches.
207
+ '23' => 'F', # Postal code matches, name doesn't match.
208
+ '24' => 'H', # Both postal code and address matches, name doesn't match.
209
+ '25' => 'T', # Address matches, name doesn't match.
210
+ '26' => 'N' # Neither postal code, address nor name matches.
211
+ }
212
+
213
+ CVC_MAPPING = {
214
+ '0' => 'P', # Unknown
215
+ '1' => 'M', # Matches
216
+ '2' => 'N', # Does not match
217
+ '3' => 'P', # Not checked
218
+ '4' => 'S', # No CVC/CVV provided, but was required
219
+ '5' => 'U', # Issuer not certifed by CVC/CVV
220
+ '6' => 'P' # No CVC/CVV provided
221
+ }
222
+
223
+ NETWORK_TOKENIZATION_CARD_SOURCE = {
224
+ 'apple_pay' => 'applepay',
225
+ 'android_pay' => 'androidpay',
226
+ 'google_pay' => 'googlepay'
227
+ }
228
+
229
+ def add_extra_data(post, payment, options)
230
+ post[:telephoneNumber] = (options[:billing_address][:phone_number] if options.dig(:billing_address, :phone_number)) || (options[:billing_address][:phone] if options.dig(:billing_address, :phone)) || ''
231
+ post[:fraudOffset] = options[:fraud_offset] if options[:fraud_offset]
232
+ post[:selectedBrand] = options[:selected_brand] if options[:selected_brand]
233
+ post[:selectedBrand] ||= NETWORK_TOKENIZATION_CARD_SOURCE[payment.source.to_s] if payment.is_a?(NetworkTokenizationCreditCard)
234
+ post[:deliveryDate] = options[:delivery_date] if options[:delivery_date]
235
+ post[:merchantOrderReference] = options[:merchant_order_reference] if options[:merchant_order_reference]
236
+ post[:captureDelayHours] = options[:capture_delay_hours] if options[:capture_delay_hours]
237
+ post[:additionalData] ||= {}
238
+ post[:additionalData][:overwriteBrand] = normalize(options[:overwrite_brand]) if options[:overwrite_brand]
239
+ post[:additionalData][:customRoutingFlag] = options[:custom_routing_flag] if options[:custom_routing_flag]
240
+ post[:additionalData]['paymentdatasource.type'] = NETWORK_TOKENIZATION_CARD_SOURCE[payment.source.to_s] if payment.is_a?(NetworkTokenizationCreditCard)
241
+ post[:additionalData][:authorisationType] = options[:authorisation_type] if options[:authorisation_type]
242
+ post[:additionalData][:adjustAuthorisationData] = options[:adjust_authorisation_data] if options[:adjust_authorisation_data]
243
+ post[:additionalData][:industryUsage] = options[:industry_usage] if options[:industry_usage]
244
+ post[:additionalData][:RequestedTestAcquirerResponseCode] = options[:requested_test_acquirer_response_code] if options[:requested_test_acquirer_response_code] && test?
245
+ post[:deviceFingerprint] = options[:device_fingerprint] if options[:device_fingerprint]
246
+ add_shopper_data(post, options)
247
+ add_risk_data(post, options)
248
+ add_shopper_reference(post, options)
249
+ add_merchant_data(post, options)
250
+ end
251
+
252
+ def extract_and_transform(mapper, from)
253
+ mapper.each_with_object({}) do |key_map, hsh|
254
+ key, item_key = key_map[0], key_map[1]
255
+ hsh[key] = from[item_key.to_sym]
256
+ end
257
+ end
258
+
259
+ def add_level_2_data(post, options)
260
+ return unless options[:level_2_data].present?
261
+
262
+ mapper = {
263
+ "enhancedSchemeData.totalTaxAmount": 'total_tax_amount',
264
+ "enhancedSchemeData.customerReference": 'customer_reference'
265
+ }
266
+ post[:additionalData].merge!(extract_and_transform(mapper, options[:level_2_data]))
267
+ end
268
+
269
+ def add_level_3_data(post, options)
270
+ return unless options[:level_3_data].present?
271
+
272
+ mapper = { "enhancedSchemeData.freightAmount": 'freight_amount',
273
+ "enhancedSchemeData.destinationStateProvinceCode": 'destination_state_province_code',
274
+ "enhancedSchemeData.shipFromPostalCode": 'ship_from_postal_code',
275
+ "enhancedSchemeData.orderDate": 'order_date',
276
+ "enhancedSchemeData.destinationPostalCode": 'destination_postal_code',
277
+ "enhancedSchemeData.destinationCountryCode": 'destination_country_code',
278
+ "enhancedSchemeData.dutyAmount": 'duty_amount' }
279
+
280
+ post[:additionalData].merge!(extract_and_transform(mapper, options[:level_3_data]))
281
+
282
+ item_detail_keys = %w[description product_code quantity unit_of_measure unit_price discount_amount total_amount commodity_code]
283
+ if options[:level_3_data][:items].present?
284
+ options[:level_3_data][:items].last(9).each.with_index(1) do |item, index|
285
+ mapper = item_detail_keys.each_with_object({}) do |key, hsh|
286
+ hsh["enhancedSchemeData.itemDetailLine#{index}.#{key.camelize(:lower)}"] = key
287
+ end
288
+ post[:additionalData].merge!(extract_and_transform(mapper, item))
289
+ end
290
+ end
291
+ post[:additionalData].compact!
292
+ end
293
+
294
+ def add_shopper_data(post, options)
295
+ post[:shopperEmail] = options[:email] if options[:email]
296
+ post[:shopperEmail] = options[:shopper_email] if options[:shopper_email]
297
+ post[:shopperIP] = options[:ip] if options[:ip]
298
+ post[:shopperIP] = options[:shopper_ip] if options[:shopper_ip]
299
+ post[:shopperStatement] = options[:shopper_statement] if options[:shopper_statement]
300
+ post[:additionalData][:updateShopperStatement] = options[:update_shopper_statement] if options[:update_shopper_statement]
301
+ end
302
+
303
+ def add_shopper_statement(post, options)
304
+ return unless options[:shopper_statement]
305
+
306
+ post[:additionalData] = {
307
+ shopperStatement: options[:shopper_statement]
308
+ }
309
+ end
310
+
311
+ def add_merchant_data(post, options)
312
+ post[:additionalData][:subMerchantID] = options[:sub_merchant_id] if options[:sub_merchant_id]
313
+ post[:additionalData][:subMerchantName] = options[:sub_merchant_name] if options[:sub_merchant_name]
314
+ post[:additionalData][:subMerchantStreet] = options[:sub_merchant_street] if options[:sub_merchant_street]
315
+ post[:additionalData][:subMerchantCity] = options[:sub_merchant_city] if options[:sub_merchant_city]
316
+ post[:additionalData][:subMerchantState] = options[:sub_merchant_state] if options[:sub_merchant_state]
317
+ post[:additionalData][:subMerchantPostalCode] = options[:sub_merchant_postal_code] if options[:sub_merchant_postal_code]
318
+ post[:additionalData][:subMerchantCountry] = options[:sub_merchant_country] if options[:sub_merchant_country]
319
+ post[:additionalData][:subMerchantTaxId] = options[:sub_merchant_tax_id] if options[:sub_merchant_tax_id]
320
+ post[:additionalData][:subMerchantMCC] = options[:sub_merchant_mcc] if options[:sub_merchant_mcc]
321
+ post[:additionalData] = post[:additionalData].merge(options[:sub_merchant_data]) if options[:sub_merchant_data]
322
+ end
323
+
324
+ def add_risk_data(post, options)
325
+ if (risk_data = options[:risk_data])
326
+ risk_data = Hash[risk_data.map { |k, v| ["riskdata.#{k}", v] }]
327
+ post[:additionalData].merge!(risk_data)
328
+ end
329
+ end
330
+
331
+ def add_splits(post, options)
332
+ return unless split_data = options[:splits]
333
+
334
+ splits = []
335
+ split_data.each do |split|
336
+ amount = {
337
+ value: split['amount']['value']
338
+ }
339
+ amount[:currency] = split['amount']['currency'] if split['amount']['currency']
340
+
341
+ split_hash = {
342
+ amount: amount,
343
+ type: split['type'],
344
+ reference: split['reference']
345
+ }
346
+ split_hash['account'] = split['account'] if split['account']
347
+ splits.push(split_hash)
348
+ end
349
+ post[:splits] = splits
350
+ end
351
+
352
+ def add_stored_credentials(post, payment, options)
353
+ add_shopper_interaction(post, payment, options)
354
+ add_recurring_processing_model(post, options)
355
+ end
356
+
357
+ def add_merchant_account(post, options)
358
+ post[:merchantAccount] = options[:merchant_account] || @merchant_account
359
+ end
360
+
361
+ def add_shopper_reference(post, options)
362
+ post[:shopperReference] = options[:shopper_reference] if options[:shopper_reference]
363
+ end
364
+
365
+ def add_shopper_interaction(post, payment, options = {})
366
+ if (options.dig(:stored_credential, :initial_transaction) && options.dig(:stored_credential, :initiator) == 'cardholder') ||
367
+ (payment.respond_to?(:verification_value) && payment.verification_value && options.dig(:stored_credential, :initial_transaction).nil?) ||
368
+ payment.is_a?(NetworkTokenizationCreditCard)
369
+ shopper_interaction = 'Ecommerce'
370
+ else
371
+ shopper_interaction = 'ContAuth'
372
+ end
373
+
374
+ post[:shopperInteraction] = options[:shopper_interaction] || shopper_interaction
375
+ end
376
+
377
+ def add_recurring_processing_model(post, options)
378
+ return unless options.dig(:stored_credential, :reason_type) || options[:recurring_processing_model]
379
+
380
+ if options.dig(:stored_credential, :reason_type) == 'unscheduled'
381
+ if options.dig(:stored_credential, :initiator) == 'merchant'
382
+ recurring_processing_model = 'UnscheduledCardOnFile'
383
+ else
384
+ recurring_processing_model = 'CardOnFile'
385
+ end
386
+ else
387
+ recurring_processing_model = 'Subscription'
388
+ end
389
+
390
+ post[:recurringProcessingModel] = options[:recurring_processing_model] || recurring_processing_model
391
+ end
392
+
393
+ def add_address(post, options)
394
+ if address = options[:shipping_address]
395
+ post[:deliveryAddress] = {}
396
+ post[:deliveryAddress][:street] = address[:address1] || 'NA'
397
+ post[:deliveryAddress][:houseNumberOrName] = address[:address2] || 'NA'
398
+ post[:deliveryAddress][:postalCode] = address[:zip] if address[:zip]
399
+ post[:deliveryAddress][:city] = address[:city] || 'NA'
400
+ post[:deliveryAddress][:stateOrProvince] = get_state(address)
401
+ post[:deliveryAddress][:country] = address[:country] if address[:country]
402
+ end
403
+ return unless post[:bankAccount]&.kind_of?(Hash) || post[:card]&.kind_of?(Hash)
404
+
405
+ if (address = options[:billing_address] || options[:address]) && address[:country]
406
+ post[:billingAddress] = {}
407
+ post[:billingAddress][:street] = address[:address1] || 'NA'
408
+ post[:billingAddress][:houseNumberOrName] = address[:address2] || 'NA'
409
+ post[:billingAddress][:postalCode] = address[:zip] if address[:zip]
410
+ post[:billingAddress][:city] = address[:city] || 'NA'
411
+ post[:billingAddress][:stateOrProvince] = get_state(address)
412
+ post[:billingAddress][:country] = address[:country] if address[:country]
413
+ end
414
+ end
415
+
416
+ def get_state(address)
417
+ address[:state] && !address[:state].blank? ? address[:state] : 'NA'
418
+ end
419
+
420
+ def add_invoice(post, money, options)
421
+ currency = options[:currency] || currency(money)
422
+ amount = {
423
+ value: localized_amount(money, currency),
424
+ currency: currency
425
+ }
426
+
427
+ post[:amount] = amount
428
+ end
429
+
430
+ def add_invoice_for_modification(post, money, options)
431
+ currency = options[:currency] || currency(money)
432
+ amount = {
433
+ value: localized_amount(money, currency),
434
+ currency: currency
435
+ }
436
+ post[:modificationAmount] = amount
437
+ end
438
+
439
+ def add_payment(post, payment, options, action = nil)
440
+ if payment.is_a?(String)
441
+ _, _, recurring_detail_reference = payment.split('#')
442
+ post[:selectedRecurringDetailReference] = recurring_detail_reference
443
+ options[:recurring_contract_type] ||= 'RECURRING'
444
+ elsif payment.is_a?(Check)
445
+ add_bank_account(post, payment, options, action)
446
+ else
447
+ add_mpi_data_for_network_tokenization_card(post, payment, options) if payment.is_a?(NetworkTokenizationCreditCard)
448
+ add_card(post, payment)
449
+ end
450
+ end
451
+
452
+ def add_bank_account(post, bank_account, options, action)
453
+ bank = {
454
+ bankAccountNumber: bank_account.account_number,
455
+ ownerName: bank_account.name,
456
+ countryCode: options[:billing_address].try(:[], :country)
457
+ }
458
+
459
+ action == 'refundWithData' ? bank[:iban] = bank_account.routing_number : bank[:bankLocationId] = bank_account.routing_number
460
+
461
+ requires!(bank, :bankAccountNumber, :ownerName, :countryCode)
462
+ post[:bankAccount] = bank
463
+ end
464
+
465
+ def add_card(post, credit_card)
466
+ card = {
467
+ expiryMonth: credit_card.month,
468
+ expiryYear: credit_card.year,
469
+ holderName: credit_card.name,
470
+ number: credit_card.number,
471
+ cvc: credit_card.verification_value
472
+ }
473
+
474
+ card.delete_if { |_k, v| v.blank? }
475
+ card[:holderName] ||= 'Not Provided'
476
+ requires!(card, :expiryMonth, :expiryYear, :holderName, :number)
477
+ post[:card] = card
478
+ end
479
+
480
+ def capture_options(options)
481
+ return options.merge(idempotency_key: "#{options[:idempotency_key]}-cap") if options[:idempotency_key]
482
+
483
+ options
484
+ end
485
+
486
+ def add_network_transaction_reference(post, options)
487
+ return unless ntid = options[:network_transaction_id] || options.dig(:stored_credential, :network_transaction_id)
488
+
489
+ post[:additionalData] = {} unless post[:additionalData]
490
+ post[:additionalData][:networkTxReference] = ntid
491
+ end
492
+
493
+ def add_reference(post, authorization, options = {})
494
+ original_reference = authorization.split('#').reject(&:empty?).first
495
+ post[:originalReference] = original_reference
496
+ end
497
+
498
+ def add_mpi_data_for_network_tokenization_card(post, payment, options)
499
+ return if options[:skip_mpi_data] == 'Y'
500
+
501
+ post[:mpiData] = {}
502
+ post[:mpiData][:authenticationResponse] = 'Y'
503
+ post[:mpiData][:cavv] = payment.payment_cryptogram
504
+ post[:mpiData][:directoryResponse] = 'Y'
505
+ post[:mpiData][:eci] = payment.eci || '07'
506
+ end
507
+
508
+ def add_recurring_contract(post, options = {})
509
+ return unless options[:recurring_contract_type]
510
+
511
+ recurring = {
512
+ contract: options[:recurring_contract_type]
513
+ }
514
+
515
+ post[:recurring] = recurring
516
+ end
517
+
518
+ def add_application_info(post, options)
519
+ post[:applicationInfo] ||= {}
520
+ add_external_platform(post, options)
521
+ add_merchant_application(post, options)
522
+ end
523
+
524
+ def add_external_platform(post, options)
525
+ options.update(externalPlatform: application_id) if application_id
526
+
527
+ return unless options[:externalPlatform]
528
+
529
+ post[:applicationInfo][:externalPlatform] = {
530
+ name: options[:externalPlatform][:name],
531
+ version: options[:externalPlatform][:version]
532
+ }
533
+ end
534
+
535
+ def add_merchant_application(post, options)
536
+ return unless options[:merchantApplication]
537
+
538
+ post[:applicationInfo][:merchantApplication] = {
539
+ name: options[:merchantApplication][:name],
540
+ version: options[:merchantApplication][:version]
541
+ }
542
+ end
543
+
544
+ def add_installments(post, options)
545
+ post[:installments] = {
546
+ value: options[:installments]
547
+ }
548
+ end
549
+
550
+ def add_3ds(post, options)
551
+ if three_ds_2_options = options[:three_ds_2]
552
+ device_channel = three_ds_2_options[:channel]
553
+ if device_channel == 'app'
554
+ post[:threeDS2RequestData] = { deviceChannel: device_channel }
555
+ else
556
+ add_browser_info(three_ds_2_options[:browser_info], post)
557
+ post[:threeDS2RequestData] = { deviceChannel: device_channel, notificationURL: three_ds_2_options[:notification_url] }
558
+ end
559
+
560
+ if options.has_key?(:execute_threed)
561
+ post[:additionalData][:executeThreeD] = options[:execute_threed]
562
+ post[:additionalData][:scaExemption] = options[:sca_exemption] if options[:sca_exemption]
563
+ end
564
+ else
565
+ return unless !options[:execute_threed].nil? || !options[:threed_dynamic].nil?
566
+
567
+ post[:browserInfo] = { userAgent: options[:user_agent], acceptHeader: options[:accept_header] } if options[:execute_threed] || options[:threed_dynamic]
568
+ post[:additionalData] ||= {}
569
+ post[:additionalData][:executeThreeD] = options[:execute_threed] if !options[:execute_threed].nil?
570
+ end
571
+ end
572
+
573
+ def add_3ds_authenticated_data(post, options)
574
+ if options[:three_d_secure] && options[:three_d_secure][:eci] && options[:three_d_secure][:xid]
575
+ add_3ds1_authenticated_data(post, options)
576
+ elsif options[:three_d_secure]
577
+ add_3ds2_authenticated_data(post, options)
578
+ end
579
+ end
580
+
581
+ def add_3ds1_authenticated_data(post, options)
582
+ three_d_secure_options = options[:three_d_secure]
583
+ post[:mpiData] = {
584
+ cavv: three_d_secure_options[:cavv],
585
+ cavvAlgorithm: three_d_secure_options[:cavv_algorithm],
586
+ eci: three_d_secure_options[:eci],
587
+ xid: three_d_secure_options[:xid],
588
+ directoryResponse: three_d_secure_options[:enrolled],
589
+ authenticationResponse: three_d_secure_options[:authentication_response_status]
590
+ }
591
+ end
592
+
593
+ def add_3ds2_authenticated_data(post, options)
594
+ three_d_secure_options = options[:three_d_secure]
595
+ # If the transaction was authenticated in a frictionless flow, send the transStatus from the ARes.
596
+ if three_d_secure_options[:authentication_response_status].nil?
597
+ authentication_response = three_d_secure_options[:directory_response_status]
598
+ else
599
+ authentication_response = three_d_secure_options[:authentication_response_status]
600
+ end
601
+ post[:mpiData] = {
602
+ threeDSVersion: three_d_secure_options[:version],
603
+ eci: three_d_secure_options[:eci],
604
+ cavv: three_d_secure_options[:cavv],
605
+ dsTransID: three_d_secure_options[:ds_transaction_id],
606
+ directoryResponse: three_d_secure_options[:directory_response_status],
607
+ authenticationResponse: authentication_response
608
+ }
609
+ end
610
+
611
+ def parse(body)
612
+ return {} if body.blank?
613
+
614
+ JSON.parse(body)
615
+ end
616
+
617
+ def commit(action, parameters, options)
618
+ begin
619
+ raw_response = ssl_post(url(action), post_data(action, parameters), request_headers(options))
620
+ response = parse(raw_response)
621
+ rescue ResponseError => e
622
+ raw_response = e.response.body
623
+ response = parse(raw_response)
624
+ end
625
+
626
+ success = success_from(action, response, options)
627
+ Response.new(
628
+ success,
629
+ message_from(action, response),
630
+ response,
631
+ authorization: authorization_from(action, parameters, response),
632
+ test: test?,
633
+ error_code: success ? nil : error_code_from(response),
634
+ network_transaction_id: network_transaction_id_from(response),
635
+ avs_result: AVSResult.new(code: avs_code_from(response)),
636
+ cvv_result: CVVResult.new(cvv_result_from(response))
637
+ )
638
+ end
639
+
640
+ def avs_code_from(response)
641
+ AVS_MAPPING[response['additionalData']['avsResult'][0..1].strip] if response.dig('additionalData', 'avsResult')
642
+ end
643
+
644
+ def cvv_result_from(response)
645
+ CVC_MAPPING[response['additionalData']['cvcResult'][0]] if response.dig('additionalData', 'cvcResult')
646
+ end
647
+
648
+ def endpoint(action)
649
+ recurring = %w(disable storeToken).include?(action)
650
+ recurring ? "Recurring/#{RECURRING_API_VERSION}/#{action}" : "Payment/#{PAYMENT_API_VERSION}/#{action}"
651
+ end
652
+
653
+ def url(action)
654
+ if test?
655
+ "#{test_url}#{endpoint(action)}"
656
+ elsif @options[:subdomain]
657
+ "https://#{@options[:subdomain]}-pal-live.adyenpayments.com/pal/servlet/#{endpoint(action)}"
658
+ else
659
+ "#{live_url}#{endpoint(action)}"
660
+ end
661
+ end
662
+
663
+ def basic_auth
664
+ Base64.strict_encode64("#{@username}:#{@password}")
665
+ end
666
+
667
+ def request_headers(options)
668
+ headers = {
669
+ 'Content-Type' => 'application/json',
670
+ 'Authorization' => "Basic #{basic_auth}"
671
+ }
672
+ headers['Idempotency-Key'] = options[:idempotency_key] if options[:idempotency_key]
673
+ headers
674
+ end
675
+
676
+ def success_from(action, response, options)
677
+ if %w[RedirectShopper ChallengeShopper].include?(response.dig('resultCode')) && !options[:execute_threed] && !options[:threed_dynamic]
678
+ response['refusalReason'] = 'Received unexpected 3DS authentication response, but a 3DS initiation flag was not included in the request.'
679
+ return false
680
+ end
681
+ case action.to_s
682
+ when 'authorise', 'authorise3d'
683
+ %w[Authorised Received RedirectShopper].include?(response['resultCode'])
684
+ when 'capture', 'refund', 'cancel', 'cancelOrRefund'
685
+ response['response'] == "[#{action}-received]"
686
+ when 'adjustAuthorisation'
687
+ response['response'] == 'Authorised' || response['response'] == '[adjustAuthorisation-received]'
688
+ when 'storeToken'
689
+ response['result'] == 'Success'
690
+ when 'disable'
691
+ response['response'] == '[detail-successfully-disabled]'
692
+ when 'refundWithData'
693
+ response['resultCode'] == 'Received'
694
+ else
695
+ false
696
+ end
697
+ end
698
+
699
+ def message_from(action, response)
700
+ return authorize_message_from(response) if %w(authorise authorise3d authorise3ds2).include?(action.to_s)
701
+
702
+ response['response'] || response['message'] || response['result'] || response['resultCode']
703
+ end
704
+
705
+ def authorize_message_from(response)
706
+ if response['refusalReason'] && response['additionalData'] && (response['additionalData']['merchantAdviceCode'] || response['additionalData']['refusalReasonRaw'])
707
+ "#{response['refusalReason']} | #{response['additionalData']['merchantAdviceCode'] || response['additionalData']['refusalReasonRaw']}"
708
+ else
709
+ response['refusalReason'] || response['resultCode'] || response['message'] || response['result']
710
+ end
711
+ end
712
+
713
+ def authorization_from(action, parameters, response)
714
+ return nil if response['pspReference'].nil?
715
+
716
+ recurring = response['additionalData']['recurring.recurringDetailReference'] if response['additionalData']
717
+ recurring = response['recurringDetailReference'] if action == 'storeToken'
718
+
719
+ "#{parameters[:originalReference]}##{response['pspReference']}##{recurring}"
720
+ end
721
+
722
+ def init_post(options = {})
723
+ post = {}
724
+ add_merchant_account(post, options)
725
+ post[:reference] = options[:order_id][0..79] if options[:order_id]
726
+ post
727
+ end
728
+
729
+ def post_data(action, parameters = {})
730
+ JSON.generate(parameters)
731
+ end
732
+
733
+ def error_code_from(response)
734
+ STANDARD_ERROR_CODE_MAPPING[response['errorCode']] || response['errorCode']
735
+ end
736
+
737
+ def network_transaction_id_from(response)
738
+ response.dig('additionalData', 'networkTxReference')
739
+ end
740
+
741
+ def add_browser_info(browser_info, post)
742
+ return unless browser_info
743
+
744
+ post[:browserInfo] = {
745
+ acceptHeader: browser_info[:accept_header],
746
+ colorDepth: browser_info[:depth],
747
+ javaEnabled: browser_info[:java],
748
+ language: browser_info[:language],
749
+ screenHeight: browser_info[:height],
750
+ screenWidth: browser_info[:width],
751
+ timeZoneOffset: browser_info[:timezone],
752
+ userAgent: browser_info[:user_agent]
753
+ }
754
+ end
755
+
756
+ def unsupported_failure_response(initial_response)
757
+ Response.new(
758
+ false,
759
+ 'Recurring transactions are not supported for this card type.',
760
+ initial_response.params,
761
+ authorization: initial_response.authorization,
762
+ test: initial_response.test,
763
+ error_code: initial_response.error_code,
764
+ avs_result: initial_response.avs_result,
765
+ cvv_result: initial_response.cvv_result[:code]
766
+ )
767
+ end
768
+
769
+ def card_not_stored?(response)
770
+ response.authorization ? response.authorization.split('#')[2].nil? : true
771
+ end
772
+ end
773
+ end
774
+ end