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,712 @@
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.supported_cardtypes = %i[visa master american_express diners_club jcb dankort maestro discover elo naranja cabal unionpay]
13
+
14
+ self.money_format = :cents
15
+
16
+ self.homepage_url = 'https://www.adyen.com/'
17
+ self.display_name = 'Adyen'
18
+
19
+ PAYMENT_API_VERSION = 'v64'
20
+ RECURRING_API_VERSION = 'v49'
21
+
22
+ STANDARD_ERROR_CODE_MAPPING = {
23
+ '101' => STANDARD_ERROR_CODE[:incorrect_number],
24
+ '103' => STANDARD_ERROR_CODE[:invalid_cvc],
25
+ '131' => STANDARD_ERROR_CODE[:incorrect_address],
26
+ '132' => STANDARD_ERROR_CODE[:incorrect_address],
27
+ '133' => STANDARD_ERROR_CODE[:incorrect_address],
28
+ '134' => STANDARD_ERROR_CODE[:incorrect_address],
29
+ '135' => STANDARD_ERROR_CODE[:incorrect_address]
30
+ }
31
+
32
+ def initialize(options = {})
33
+ requires!(options, :username, :password, :merchant_account)
34
+ @username, @password, @merchant_account = options.values_at(:username, :password, :merchant_account)
35
+ super
36
+ end
37
+
38
+ def purchase(money, payment, options = {})
39
+ if options[:execute_threed] || options[:threed_dynamic]
40
+ authorize(money, payment, options)
41
+ else
42
+ MultiResponse.run do |r|
43
+ r.process { authorize(money, payment, options) }
44
+ r.process { capture(money, r.authorization, capture_options(options)) }
45
+ end
46
+ end
47
+ end
48
+
49
+ def authorize(money, payment, options = {})
50
+ requires!(options, :order_id)
51
+ post = init_post(options)
52
+ add_invoice(post, money, options)
53
+ add_payment(post, payment, options)
54
+ add_extra_data(post, payment, options)
55
+ add_stored_credentials(post, payment, options)
56
+ add_address(post, options)
57
+ add_installments(post, options) if options[:installments]
58
+ add_3ds(post, options)
59
+ add_3ds_authenticated_data(post, options)
60
+ add_splits(post, options)
61
+ add_recurring_contract(post, options)
62
+ add_network_transaction_reference(post, options)
63
+ add_application_info(post, options)
64
+ commit('authorise', post, options)
65
+ end
66
+
67
+ def capture(money, authorization, options = {})
68
+ post = init_post(options)
69
+ add_invoice_for_modification(post, money, options)
70
+ add_reference(post, authorization, options)
71
+ add_splits(post, options)
72
+ add_network_transaction_reference(post, options)
73
+ commit('capture', post, options)
74
+ end
75
+
76
+ def refund(money, authorization, options = {})
77
+ post = init_post(options)
78
+ add_invoice_for_modification(post, money, options)
79
+ add_reference(post, authorization, options)
80
+ add_splits(post, options)
81
+ add_network_transaction_reference(post, options)
82
+ commit('refund', post, options)
83
+ end
84
+
85
+ def credit(money, payment, options = {})
86
+ action = 'refundWithData'
87
+ post = init_post(options)
88
+ add_invoice(post, money, options)
89
+ add_payment(post, payment, options, action)
90
+ add_shopper_reference(post, options)
91
+ add_network_transaction_reference(post, options)
92
+ commit(action, post, options)
93
+ end
94
+
95
+ def void(authorization, options = {})
96
+ post = init_post(options)
97
+ endpoint = options[:cancel_or_refund] ? 'cancelOrRefund' : 'cancel'
98
+ add_reference(post, authorization, options)
99
+ add_network_transaction_reference(post, options)
100
+ commit(endpoint, post, options)
101
+ end
102
+
103
+ def adjust(money, authorization, options = {})
104
+ post = init_post(options)
105
+ add_invoice_for_modification(post, money, options)
106
+ add_reference(post, authorization, options)
107
+ add_extra_data(post, nil, options)
108
+ commit('adjustAuthorisation', post, options)
109
+ end
110
+
111
+ def store(credit_card, options = {})
112
+ requires!(options, :order_id)
113
+ post = init_post(options)
114
+ add_invoice(post, 0, options)
115
+ add_payment(post, credit_card, options)
116
+ add_extra_data(post, credit_card, options)
117
+ add_stored_credentials(post, credit_card, options)
118
+ add_address(post, options)
119
+
120
+ options[:recurring_contract_type] ||= 'RECURRING'
121
+ add_recurring_contract(post, options)
122
+
123
+ action = options[:tokenize_only] ? 'storeToken' : 'authorise'
124
+
125
+ initial_response = commit(action, post, options)
126
+
127
+ if initial_response.success? && card_not_stored?(initial_response)
128
+ unsupported_failure_response(initial_response)
129
+ else
130
+ initial_response
131
+ end
132
+ end
133
+
134
+ def unstore(options = {})
135
+ requires!(options, :shopper_reference, :recurring_detail_reference)
136
+ post = {}
137
+
138
+ add_shopper_reference(post, options)
139
+ add_merchant_account(post, options)
140
+ post[:recurringDetailReference] = options[:recurring_detail_reference]
141
+
142
+ commit('disable', post, options)
143
+ end
144
+
145
+ def verify(credit_card, options = {})
146
+ MultiResponse.run(:use_first_response) do |r|
147
+ r.process { authorize(0, credit_card, options) }
148
+ options[:idempotency_key] = nil
149
+ r.process(:ignore_result) { void(r.authorization, options) }
150
+ end
151
+ end
152
+
153
+ def supports_scrubbing?
154
+ true
155
+ end
156
+
157
+ def supports_network_tokenization?
158
+ true
159
+ end
160
+
161
+ def scrub(transcript)
162
+ transcript.
163
+ gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
164
+ gsub(%r(("number\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
165
+ gsub(%r(("cvc\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
166
+ gsub(%r(("cavv\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
167
+ gsub(%r(("bankLocationId\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
168
+ gsub(%r(("iban\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
169
+ gsub(%r(("bankAccountNumber\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]')
170
+ end
171
+
172
+ private
173
+
174
+ AVS_MAPPING = {
175
+ '0' => 'R', # Unknown
176
+ '1' => 'A', # Address matches, postal code doesn't
177
+ '2' => 'N', # Neither postal code nor address match
178
+ '3' => 'R', # AVS unavailable
179
+ '4' => 'E', # AVS not supported for this card type
180
+ '5' => 'U', # No AVS data provided
181
+ '6' => 'Z', # Postal code matches, address doesn't match
182
+ '7' => 'D', # Both postal code and address match
183
+ '8' => 'U', # Address not checked, postal code unknown
184
+ '9' => 'B', # Address matches, postal code unknown
185
+ '10' => 'N', # Address doesn't match, postal code unknown
186
+ '11' => 'U', # Postal code not checked, address unknown
187
+ '12' => 'B', # Address matches, postal code not checked
188
+ '13' => 'U', # Address doesn't match, postal code not checked
189
+ '14' => 'P', # Postal code matches, address unknown
190
+ '15' => 'P', # Postal code matches, address not checked
191
+ '16' => 'N', # Postal code doesn't match, address unknown
192
+ '17' => 'U', # Postal code doesn't match, address not checked
193
+ '18' => 'I', # Neither postal code nor address were checked
194
+ '19' => 'L', # Name and postal code matches.
195
+ '20' => 'V', # Name, address and postal code matches.
196
+ '21' => 'O', # Name and address matches.
197
+ '22' => 'K', # Name matches.
198
+ '23' => 'F', # Postal code matches, name doesn't match.
199
+ '24' => 'H', # Both postal code and address matches, name doesn't match.
200
+ '25' => 'T', # Address matches, name doesn't match.
201
+ '26' => 'N' # Neither postal code, address nor name matches.
202
+ }
203
+
204
+ CVC_MAPPING = {
205
+ '0' => 'P', # Unknown
206
+ '1' => 'M', # Matches
207
+ '2' => 'N', # Does not match
208
+ '3' => 'P', # Not checked
209
+ '4' => 'S', # No CVC/CVV provided, but was required
210
+ '5' => 'U', # Issuer not certifed by CVC/CVV
211
+ '6' => 'P' # No CVC/CVV provided
212
+ }
213
+
214
+ NETWORK_TOKENIZATION_CARD_SOURCE = {
215
+ 'apple_pay' => 'applepay',
216
+ 'android_pay' => 'androidpay',
217
+ 'google_pay' => 'paywithgoogle'
218
+ }
219
+
220
+ def add_extra_data(post, payment, options)
221
+ post[:telephoneNumber] = (options[:billing_address][:phone_number] if options.dig(:billing_address, :phone_number)) || (options[:billing_address][:phone] if options.dig(:billing_address, :phone)) || ''
222
+ post[:fraudOffset] = options[:fraud_offset] if options[:fraud_offset]
223
+ post[:selectedBrand] = options[:selected_brand] if options[:selected_brand]
224
+ post[:selectedBrand] ||= NETWORK_TOKENIZATION_CARD_SOURCE[payment.source.to_s] if payment.is_a?(NetworkTokenizationCreditCard)
225
+ post[:deliveryDate] = options[:delivery_date] if options[:delivery_date]
226
+ post[:merchantOrderReference] = options[:merchant_order_reference] if options[:merchant_order_reference]
227
+ post[:captureDelayHours] = options[:capture_delay_hours] if options[:capture_delay_hours]
228
+ post[:additionalData] ||= {}
229
+ post[:additionalData][:overwriteBrand] = normalize(options[:overwrite_brand]) if options[:overwrite_brand]
230
+ post[:additionalData][:customRoutingFlag] = options[:custom_routing_flag] if options[:custom_routing_flag]
231
+ post[:additionalData]['paymentdatasource.type'] = NETWORK_TOKENIZATION_CARD_SOURCE[payment.source.to_s] if payment.is_a?(NetworkTokenizationCreditCard)
232
+ post[:additionalData][:authorisationType] = options[:authorisation_type] if options[:authorisation_type]
233
+ post[:additionalData][:adjustAuthorisationData] = options[:adjust_authorisation_data] if options[:adjust_authorisation_data]
234
+ post[:additionalData][:industryUsage] = options[:industry_usage] if options[:industry_usage]
235
+ post[:additionalData][:RequestedTestAcquirerResponseCode] = options[:requested_test_acquirer_response_code] if options[:requested_test_acquirer_response_code] && test?
236
+ post[:deviceFingerprint] = options[:device_fingerprint] if options[:device_fingerprint]
237
+ add_shopper_data(post, options)
238
+ add_risk_data(post, options)
239
+ add_shopper_reference(post, options)
240
+ add_merchant_data(post, options)
241
+ end
242
+
243
+ def add_shopper_data(post, options)
244
+ post[:shopperEmail] = options[:email] if options[:email]
245
+ post[:shopperEmail] = options[:shopper_email] if options[:shopper_email]
246
+ post[:shopperIP] = options[:ip] if options[:ip]
247
+ post[:shopperIP] = options[:shopper_ip] if options[:shopper_ip]
248
+ post[:shopperStatement] = options[:shopper_statement] if options[:shopper_statement]
249
+ post[:additionalData][:updateShopperStatement] = options[:update_shopper_statement] if options[:update_shopper_statement]
250
+ end
251
+
252
+ def add_merchant_data(post, options)
253
+ post[:additionalData][:subMerchantID] = options[:sub_merchant_id] if options[:sub_merchant_id]
254
+ post[:additionalData][:subMerchantName] = options[:sub_merchant_name] if options[:sub_merchant_name]
255
+ post[:additionalData][:subMerchantStreet] = options[:sub_merchant_street] if options[:sub_merchant_street]
256
+ post[:additionalData][:subMerchantCity] = options[:sub_merchant_city] if options[:sub_merchant_city]
257
+ post[:additionalData][:subMerchantState] = options[:sub_merchant_state] if options[:sub_merchant_state]
258
+ post[:additionalData][:subMerchantPostalCode] = options[:sub_merchant_postal_code] if options[:sub_merchant_postal_code]
259
+ post[:additionalData][:subMerchantCountry] = options[:sub_merchant_country] if options[:sub_merchant_country]
260
+ post[:additionalData][:subMerchantTaxId] = options[:sub_merchant_tax_id] if options[:sub_merchant_tax_id]
261
+ post[:additionalData][:subMerchantMCC] = options[:sub_merchant_mcc] if options[:sub_merchant_mcc]
262
+ post[:additionalData] = post[:additionalData].merge(options[:sub_merchant_data]) if options[:sub_merchant_data]
263
+ end
264
+
265
+ def add_risk_data(post, options)
266
+ if (risk_data = options[:risk_data])
267
+ risk_data = Hash[risk_data.map { |k, v| ["riskdata.#{k}", v] }]
268
+ post[:additionalData].merge!(risk_data)
269
+ end
270
+ end
271
+
272
+ def add_splits(post, options)
273
+ return unless split_data = options[:splits]
274
+
275
+ splits = []
276
+ split_data.each do |split|
277
+ amount = {
278
+ value: split['amount']['value']
279
+ }
280
+ amount[:currency] = split['amount']['currency'] if split['amount']['currency']
281
+
282
+ split_hash = {
283
+ amount: amount,
284
+ type: split['type'],
285
+ reference: split['reference']
286
+ }
287
+ split_hash['account'] = split['account'] if split['account']
288
+ splits.push(split_hash)
289
+ end
290
+ post[:splits] = splits
291
+ end
292
+
293
+ def add_stored_credentials(post, payment, options)
294
+ add_shopper_interaction(post, payment, options)
295
+ add_recurring_processing_model(post, options)
296
+ end
297
+
298
+ def add_merchant_account(post, options)
299
+ post[:merchantAccount] = options[:merchant_account] || @merchant_account
300
+ end
301
+
302
+ def add_shopper_reference(post, options)
303
+ post[:shopperReference] = options[:shopper_reference] if options[:shopper_reference]
304
+ end
305
+
306
+ def add_shopper_interaction(post, payment, options = {})
307
+ if (options.dig(:stored_credential, :initial_transaction) && options.dig(:stored_credential, :initiator) == 'cardholder') ||
308
+ (payment.respond_to?(:verification_value) && payment.verification_value && options.dig(:stored_credential, :initial_transaction).nil?) ||
309
+ payment.is_a?(NetworkTokenizationCreditCard)
310
+ shopper_interaction = 'Ecommerce'
311
+ else
312
+ shopper_interaction = 'ContAuth'
313
+ end
314
+
315
+ post[:shopperInteraction] = options[:shopper_interaction] || shopper_interaction
316
+ end
317
+
318
+ def add_recurring_processing_model(post, options)
319
+ return unless options.dig(:stored_credential, :reason_type) || options[:recurring_processing_model]
320
+
321
+ if options.dig(:stored_credential, :reason_type) == 'unscheduled'
322
+ if options.dig(:stored_credential, :initiator) == 'merchant'
323
+ recurring_processing_model = 'UnscheduledCardOnFile'
324
+ else
325
+ recurring_processing_model = 'CardOnFile'
326
+ end
327
+ else
328
+ recurring_processing_model = 'Subscription'
329
+ end
330
+
331
+ post[:recurringProcessingModel] = options[:recurring_processing_model] || recurring_processing_model
332
+ end
333
+
334
+ def add_address(post, options)
335
+ if address = options[:shipping_address]
336
+ post[:deliveryAddress] = {}
337
+ post[:deliveryAddress][:street] = address[:address1] || 'NA'
338
+ post[:deliveryAddress][:houseNumberOrName] = address[:address2] || 'NA'
339
+ post[:deliveryAddress][:postalCode] = address[:zip] if address[:zip]
340
+ post[:deliveryAddress][:city] = address[:city] || 'NA'
341
+ post[:deliveryAddress][:stateOrProvince] = get_state(address)
342
+ post[:deliveryAddress][:country] = address[:country] if address[:country]
343
+ end
344
+ return unless post[:bankAccount]&.kind_of?(Hash) || post[:card]&.kind_of?(Hash)
345
+
346
+ if (address = options[:billing_address] || options[:address]) && address[:country]
347
+ post[:billingAddress] = {}
348
+ post[:billingAddress][:street] = address[:address1] || 'NA'
349
+ post[:billingAddress][:houseNumberOrName] = address[:address2] || 'NA'
350
+ post[:billingAddress][:postalCode] = address[:zip] if address[:zip]
351
+ post[:billingAddress][:city] = address[:city] || 'NA'
352
+ post[:billingAddress][:stateOrProvince] = get_state(address)
353
+ post[:billingAddress][:country] = address[:country] if address[:country]
354
+ end
355
+ end
356
+
357
+ def get_state(address)
358
+ address[:state] && !address[:state].blank? ? address[:state] : 'NA'
359
+ end
360
+
361
+ def add_invoice(post, money, options)
362
+ currency = options[:currency] || currency(money)
363
+ amount = {
364
+ value: localized_amount(money, currency),
365
+ currency: currency
366
+ }
367
+
368
+ post[:amount] = amount
369
+ end
370
+
371
+ def add_invoice_for_modification(post, money, options)
372
+ currency = options[:currency] || currency(money)
373
+ amount = {
374
+ value: localized_amount(money, currency),
375
+ currency: currency
376
+ }
377
+ post[:modificationAmount] = amount
378
+ end
379
+
380
+ def add_payment(post, payment, options, action = nil)
381
+ if payment.is_a?(String)
382
+ _, _, recurring_detail_reference = payment.split('#')
383
+ post[:selectedRecurringDetailReference] = recurring_detail_reference
384
+ options[:recurring_contract_type] ||= 'RECURRING'
385
+ elsif payment.is_a?(Check)
386
+ add_bank_account(post, payment, options, action)
387
+ else
388
+ add_mpi_data_for_network_tokenization_card(post, payment) if payment.is_a?(NetworkTokenizationCreditCard)
389
+ add_card(post, payment)
390
+ end
391
+ end
392
+
393
+ def add_bank_account(post, bank_account, options, action)
394
+ bank = {
395
+ bankAccountNumber: bank_account.account_number,
396
+ ownerName: bank_account.name,
397
+ countryCode: options[:billing_address][:country]
398
+ }
399
+
400
+ action == 'refundWithData' ? bank[:iban] = bank_account.routing_number : bank[:bankLocationId] = bank_account.routing_number
401
+
402
+ requires!(bank, :bankAccountNumber, :ownerName, :countryCode)
403
+ post[:bankAccount] = bank
404
+ end
405
+
406
+ def add_card(post, credit_card)
407
+ card = {
408
+ expiryMonth: credit_card.month,
409
+ expiryYear: credit_card.year,
410
+ holderName: credit_card.name,
411
+ number: credit_card.number,
412
+ cvc: credit_card.verification_value
413
+ }
414
+
415
+ card.delete_if { |_k, v| v.blank? }
416
+ card[:holderName] ||= 'Not Provided'
417
+ requires!(card, :expiryMonth, :expiryYear, :holderName, :number)
418
+ post[:card] = card
419
+ end
420
+
421
+ def capture_options(options)
422
+ return options.merge(idempotency_key: "#{options[:idempotency_key]}-cap") if options[:idempotency_key]
423
+
424
+ options
425
+ end
426
+
427
+ def add_network_transaction_reference(post, options)
428
+ return unless ntid = options[:network_transaction_id] || options.dig(:stored_credential, :network_transaction_id)
429
+
430
+ post[:additionalData] = {} unless post[:additionalData]
431
+ post[:additionalData][:networkTxReference] = ntid
432
+ end
433
+
434
+ def add_reference(post, authorization, options = {})
435
+ original_reference = authorization.split('#').reject(&:empty?).first
436
+ post[:originalReference] = original_reference
437
+ end
438
+
439
+ def add_mpi_data_for_network_tokenization_card(post, payment)
440
+ post[:mpiData] = {}
441
+ post[:mpiData][:authenticationResponse] = 'Y'
442
+ post[:mpiData][:cavv] = payment.payment_cryptogram
443
+ post[:mpiData][:directoryResponse] = 'Y'
444
+ post[:mpiData][:eci] = payment.eci || '07'
445
+ end
446
+
447
+ def add_recurring_contract(post, options = {})
448
+ return unless options[:recurring_contract_type]
449
+
450
+ recurring = {
451
+ contract: options[:recurring_contract_type]
452
+ }
453
+
454
+ post[:recurring] = recurring
455
+ end
456
+
457
+ def add_application_info(post, options)
458
+ post[:applicationInfo] ||= {}
459
+ add_external_platform(post, options)
460
+ add_merchant_application(post, options)
461
+ end
462
+
463
+ def add_external_platform(post, options)
464
+ return unless options[:externalPlatform]
465
+
466
+ post[:applicationInfo][:externalPlatform] = {
467
+ name: options[:externalPlatform][:name],
468
+ version: options[:externalPlatform][:version],
469
+ integrator: options[:externalPlatform][:integrator]
470
+ }
471
+ end
472
+
473
+ def add_merchant_application(post, options)
474
+ return unless options[:merchantApplication]
475
+
476
+ post[:applicationInfo][:merchantApplication] = {
477
+ name: options[:merchantApplication][:name],
478
+ version: options[:merchantApplication][:version]
479
+ }
480
+ end
481
+
482
+ def add_installments(post, options)
483
+ post[:installments] = {
484
+ value: options[:installments]
485
+ }
486
+ end
487
+
488
+ def add_3ds(post, options)
489
+ if three_ds_2_options = options[:three_ds_2]
490
+ device_channel = three_ds_2_options[:channel]
491
+ if device_channel == 'app'
492
+ post[:threeDS2RequestData] = { deviceChannel: device_channel }
493
+ else
494
+ add_browser_info(three_ds_2_options[:browser_info], post)
495
+ post[:threeDS2RequestData] = { deviceChannel: device_channel, notificationURL: three_ds_2_options[:notification_url] }
496
+ end
497
+
498
+ if options.has_key?(:execute_threed)
499
+ post[:additionalData][:executeThreeD] = options[:execute_threed]
500
+ post[:additionalData][:scaExemption] = options[:sca_exemption] if options[:sca_exemption]
501
+ end
502
+ else
503
+ return unless !options[:execute_threed].nil? || !options[:threed_dynamic].nil?
504
+
505
+ post[:browserInfo] = { userAgent: options[:user_agent], acceptHeader: options[:accept_header] } if options[:execute_threed] || options[:threed_dynamic]
506
+ post[:additionalData] ||= {}
507
+ post[:additionalData][:executeThreeD] = options[:execute_threed] if !options[:execute_threed].nil?
508
+ end
509
+ end
510
+
511
+ def add_3ds_authenticated_data(post, options)
512
+ if options[:three_d_secure] && options[:three_d_secure][:eci] && options[:three_d_secure][:xid]
513
+ add_3ds1_authenticated_data(post, options)
514
+ elsif options[:three_d_secure]
515
+ add_3ds2_authenticated_data(post, options)
516
+ end
517
+ end
518
+
519
+ def add_3ds1_authenticated_data(post, options)
520
+ three_d_secure_options = options[:three_d_secure]
521
+ post[:mpiData] = {
522
+ cavv: three_d_secure_options[:cavv],
523
+ cavvAlgorithm: three_d_secure_options[:cavv_algorithm],
524
+ eci: three_d_secure_options[:eci],
525
+ xid: three_d_secure_options[:xid],
526
+ directoryResponse: three_d_secure_options[:enrolled],
527
+ authenticationResponse: three_d_secure_options[:authentication_response_status]
528
+ }
529
+ end
530
+
531
+ def add_3ds2_authenticated_data(post, options)
532
+ three_d_secure_options = options[:three_d_secure]
533
+ # If the transaction was authenticated in a frictionless flow, send the transStatus from the ARes.
534
+ if three_d_secure_options[:authentication_response_status].nil?
535
+ authentication_response = three_d_secure_options[:directory_response_status]
536
+ else
537
+ authentication_response = three_d_secure_options[:authentication_response_status]
538
+ end
539
+ post[:mpiData] = {
540
+ threeDSVersion: three_d_secure_options[:version],
541
+ eci: three_d_secure_options[:eci],
542
+ cavv: three_d_secure_options[:cavv],
543
+ dsTransID: three_d_secure_options[:ds_transaction_id],
544
+ directoryResponse: three_d_secure_options[:directory_response_status],
545
+ authenticationResponse: authentication_response
546
+ }
547
+ end
548
+
549
+ def parse(body)
550
+ return {} if body.blank?
551
+
552
+ JSON.parse(body)
553
+ end
554
+
555
+ def commit(action, parameters, options)
556
+ begin
557
+ raw_response = ssl_post(url(action), post_data(action, parameters), request_headers(options))
558
+ response = parse(raw_response)
559
+ rescue ResponseError => e
560
+ raw_response = e.response.body
561
+ response = parse(raw_response)
562
+ end
563
+
564
+ success = success_from(action, response, options)
565
+ Response.new(
566
+ success,
567
+ message_from(action, response),
568
+ response,
569
+ authorization: authorization_from(action, parameters, response),
570
+ test: test?,
571
+ error_code: success ? nil : error_code_from(response),
572
+ network_transaction_id: network_transaction_id_from(response),
573
+ avs_result: AVSResult.new(code: avs_code_from(response)),
574
+ cvv_result: CVVResult.new(cvv_result_from(response))
575
+ )
576
+ end
577
+
578
+ def avs_code_from(response)
579
+ AVS_MAPPING[response['additionalData']['avsResult'][0..1].strip] if response.dig('additionalData', 'avsResult')
580
+ end
581
+
582
+ def cvv_result_from(response)
583
+ CVC_MAPPING[response['additionalData']['cvcResult'][0]] if response.dig('additionalData', 'cvcResult')
584
+ end
585
+
586
+ def endpoint(action)
587
+ recurring = %w(disable storeToken).include?(action)
588
+ recurring ? "Recurring/#{RECURRING_API_VERSION}/#{action}" : "Payment/#{PAYMENT_API_VERSION}/#{action}"
589
+ end
590
+
591
+ def url(action)
592
+ if test?
593
+ "#{test_url}#{endpoint(action)}"
594
+ elsif @options[:subdomain]
595
+ "https://#{@options[:subdomain]}-pal-live.adyenpayments.com/pal/servlet/#{endpoint(action)}"
596
+ else
597
+ "#{live_url}#{endpoint(action)}"
598
+ end
599
+ end
600
+
601
+ def basic_auth
602
+ Base64.strict_encode64("#{@username}:#{@password}")
603
+ end
604
+
605
+ def request_headers(options)
606
+ headers = {
607
+ 'Content-Type' => 'application/json',
608
+ 'Authorization' => "Basic #{basic_auth}"
609
+ }
610
+ headers['Idempotency-Key'] = options[:idempotency_key] if options[:idempotency_key]
611
+ headers
612
+ end
613
+
614
+ def success_from(action, response, options)
615
+ if %w[RedirectShopper ChallengeShopper].include?(response.dig('resultCode')) && !options[:execute_threed] && !options[:threed_dynamic]
616
+ response['refusalReason'] = 'Received unexpected 3DS authentication response. Use the execute_threed and/or threed_dynamic options to initiate a proper 3DS flow.'
617
+ return false
618
+ end
619
+ case action.to_s
620
+ when 'authorise', 'authorise3d'
621
+ %w[Authorised Received RedirectShopper].include?(response['resultCode'])
622
+ when 'capture', 'refund', 'cancel', 'cancelOrRefund'
623
+ response['response'] == "[#{action}-received]"
624
+ when 'adjustAuthorisation'
625
+ response['response'] == 'Authorised' || response['response'] == '[adjustAuthorisation-received]'
626
+ when 'storeToken'
627
+ response['result'] == 'Success'
628
+ when 'disable'
629
+ response['response'] == '[detail-successfully-disabled]'
630
+ when 'refundWithData'
631
+ response['resultCode'] == 'Received'
632
+ else
633
+ false
634
+ end
635
+ end
636
+
637
+ def message_from(action, response)
638
+ return authorize_message_from(response) if %w(authorise authorise3d authorise3ds2).include?(action.to_s)
639
+
640
+ response['response'] || response['message'] || response['result'] || response['resultCode']
641
+ end
642
+
643
+ def authorize_message_from(response)
644
+ if response['refusalReason'] && response['additionalData'] && response['additionalData']['refusalReasonRaw']
645
+ "#{response['refusalReason']} | #{response['additionalData']['refusalReasonRaw']}"
646
+ else
647
+ response['refusalReason'] || response['resultCode'] || response['message'] || response['result']
648
+ end
649
+ end
650
+
651
+ def authorization_from(action, parameters, response)
652
+ return nil if response['pspReference'].nil?
653
+
654
+ recurring = response['additionalData']['recurring.recurringDetailReference'] if response['additionalData']
655
+ recurring = response['recurringDetailReference'] if action == 'storeToken'
656
+
657
+ "#{parameters[:originalReference]}##{response['pspReference']}##{recurring}"
658
+ end
659
+
660
+ def init_post(options = {})
661
+ post = {}
662
+ add_merchant_account(post, options)
663
+ post[:reference] = options[:order_id][0..79] if options[:order_id]
664
+ post
665
+ end
666
+
667
+ def post_data(action, parameters = {})
668
+ JSON.generate(parameters)
669
+ end
670
+
671
+ def error_code_from(response)
672
+ STANDARD_ERROR_CODE_MAPPING[response['errorCode']]
673
+ end
674
+
675
+ def network_transaction_id_from(response)
676
+ response.dig('additionalData', 'networkTxReference')
677
+ end
678
+
679
+ def add_browser_info(browser_info, post)
680
+ return unless browser_info
681
+
682
+ post[:browserInfo] = {
683
+ acceptHeader: browser_info[:accept_header],
684
+ colorDepth: browser_info[:depth],
685
+ javaEnabled: browser_info[:java],
686
+ language: browser_info[:language],
687
+ screenHeight: browser_info[:height],
688
+ screenWidth: browser_info[:width],
689
+ timeZoneOffset: browser_info[:timezone],
690
+ userAgent: browser_info[:user_agent]
691
+ }
692
+ end
693
+
694
+ def unsupported_failure_response(initial_response)
695
+ Response.new(
696
+ false,
697
+ 'Recurring transactions are not supported for this card type.',
698
+ initial_response.params,
699
+ authorization: initial_response.authorization,
700
+ test: initial_response.test,
701
+ error_code: initial_response.error_code,
702
+ avs_result: initial_response.avs_result,
703
+ cvv_result: initial_response.cvv_result[:code]
704
+ )
705
+ end
706
+
707
+ def card_not_stored?(response)
708
+ response.authorization ? response.authorization.split('#')[2].nil? : true
709
+ end
710
+ end
711
+ end
712
+ end