activemerchant 1.45.0 → 1.126.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (288) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG +2167 -2
  3. data/CONTRIBUTORS +57 -0
  4. data/README.md +62 -41
  5. data/lib/active_merchant/billing/avs_result.rb +25 -28
  6. data/lib/active_merchant/billing/base.rb +11 -35
  7. data/lib/active_merchant/billing/check.rb +28 -24
  8. data/lib/active_merchant/billing/compatibility.rb +10 -12
  9. data/lib/active_merchant/billing/credit_card.rb +141 -69
  10. data/lib/active_merchant/billing/credit_card_formatting.rb +4 -4
  11. data/lib/active_merchant/billing/credit_card_methods.rb +348 -52
  12. data/lib/active_merchant/billing/cvv_result.rb +0 -1
  13. data/lib/active_merchant/billing/gateway.rb +125 -61
  14. data/lib/active_merchant/billing/gateways/adyen.rb +633 -127
  15. data/lib/active_merchant/billing/gateways/airwallex.rb +341 -0
  16. data/lib/active_merchant/billing/gateways/allied_wallet.rb +205 -0
  17. data/lib/active_merchant/billing/gateways/authorize_net.rb +883 -195
  18. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +31 -24
  19. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +104 -103
  20. data/lib/active_merchant/billing/gateways/axcessms.rb +179 -0
  21. data/lib/active_merchant/billing/gateways/balanced.rb +72 -65
  22. data/lib/active_merchant/billing/gateways/bambora_apac.rb +222 -0
  23. data/lib/active_merchant/billing/gateways/bank_frick.rb +16 -16
  24. data/lib/active_merchant/billing/gateways/banwire.rb +24 -13
  25. data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +397 -0
  26. data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +7 -7
  27. data/lib/active_merchant/billing/gateways/be2bill.rb +7 -7
  28. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +143 -62
  29. data/lib/active_merchant/billing/gateways/beanstream.rb +45 -13
  30. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +13 -10
  31. data/lib/active_merchant/billing/gateways/blue_pay.rb +549 -506
  32. data/lib/active_merchant/billing/gateways/blue_snap.rb +623 -0
  33. data/lib/active_merchant/billing/gateways/bogus.rb +82 -36
  34. data/lib/active_merchant/billing/gateways/borgun.rb +61 -40
  35. data/lib/active_merchant/billing/gateways/bpoint.rb +277 -0
  36. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +21 -2
  37. data/lib/active_merchant/billing/gateways/braintree/token_nonce.rb +113 -0
  38. data/lib/active_merchant/billing/gateways/braintree.rb +3 -3
  39. data/lib/active_merchant/billing/gateways/braintree_blue.rb +592 -203
  40. data/lib/active_merchant/billing/gateways/braintree_orange.rb +3 -4
  41. data/lib/active_merchant/billing/gateways/bridge_pay.rb +116 -61
  42. data/lib/active_merchant/billing/gateways/cams.rb +230 -0
  43. data/lib/active_merchant/billing/gateways/card_connect.rb +320 -0
  44. data/lib/active_merchant/billing/gateways/card_save.rb +7 -9
  45. data/lib/active_merchant/billing/gateways/card_stream.rb +248 -97
  46. data/lib/active_merchant/billing/gateways/cardknox.rb +327 -0
  47. data/lib/active_merchant/billing/gateways/cardprocess.rb +256 -0
  48. data/lib/active_merchant/billing/gateways/cashnet.rb +70 -26
  49. data/lib/active_merchant/billing/gateways/cc5.rb +14 -17
  50. data/lib/active_merchant/billing/gateways/cecabank.rb +73 -53
  51. data/lib/active_merchant/billing/gateways/cenpos.rb +328 -0
  52. data/lib/active_merchant/billing/gateways/checkout.rb +32 -33
  53. data/lib/active_merchant/billing/gateways/checkout_v2.rb +340 -0
  54. data/lib/active_merchant/billing/gateways/citrus_pay.rb +21 -0
  55. data/lib/active_merchant/billing/gateways/clearhaus.rb +219 -0
  56. data/lib/active_merchant/billing/gateways/commercegate.rb +11 -12
  57. data/lib/active_merchant/billing/gateways/conekta.rb +55 -34
  58. data/lib/active_merchant/billing/gateways/creditcall.rb +272 -0
  59. data/lib/active_merchant/billing/gateways/credorax.rb +506 -0
  60. data/lib/active_merchant/billing/gateways/ct_payment.rb +269 -0
  61. data/lib/active_merchant/billing/gateways/culqi.rb +279 -0
  62. data/lib/active_merchant/billing/gateways/cyber_source.rb +637 -221
  63. data/lib/active_merchant/billing/gateways/d_local.rb +303 -0
  64. data/lib/active_merchant/billing/gateways/data_cash.rb +57 -355
  65. data/lib/active_merchant/billing/gateways/decidir.rb +347 -0
  66. data/lib/active_merchant/billing/gateways/decidir_plus.rb +344 -0
  67. data/lib/active_merchant/billing/gateways/dibs.rb +199 -0
  68. data/lib/active_merchant/billing/gateways/digitzs.rb +295 -0
  69. data/lib/active_merchant/billing/gateways/ebanx.rb +334 -0
  70. data/lib/active_merchant/billing/gateways/efsnet.rb +46 -50
  71. data/lib/active_merchant/billing/gateways/elavon.rb +377 -250
  72. data/lib/active_merchant/billing/gateways/element.rb +386 -0
  73. data/lib/active_merchant/billing/gateways/epay.rb +92 -71
  74. data/lib/active_merchant/billing/gateways/evo_ca.rb +13 -14
  75. data/lib/active_merchant/billing/gateways/eway.rb +85 -73
  76. data/lib/active_merchant/billing/gateways/eway_managed.rb +85 -87
  77. data/lib/active_merchant/billing/gateways/eway_rapid.rb +134 -80
  78. data/lib/active_merchant/billing/gateways/exact.rb +37 -36
  79. data/lib/active_merchant/billing/gateways/ezic.rb +195 -0
  80. data/lib/active_merchant/billing/gateways/fat_zebra.rb +124 -74
  81. data/lib/active_merchant/billing/gateways/federated_canada.rb +11 -13
  82. data/lib/active_merchant/billing/gateways/finansbank.rb +4 -5
  83. data/lib/active_merchant/billing/gateways/first_giving.rb +23 -23
  84. data/lib/active_merchant/billing/gateways/first_pay.rb +45 -23
  85. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +184 -87
  86. data/lib/active_merchant/billing/gateways/firstdata_e4_v27.rb +505 -0
  87. data/lib/active_merchant/billing/gateways/flo2cash.rb +215 -0
  88. data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +20 -0
  89. data/lib/active_merchant/billing/gateways/forte.rb +286 -0
  90. data/lib/active_merchant/billing/gateways/garanti.rb +31 -32
  91. data/lib/active_merchant/billing/gateways/global_collect.rb +507 -0
  92. data/lib/active_merchant/billing/gateways/global_transport.rb +25 -15
  93. data/lib/active_merchant/billing/gateways/hdfc.rb +55 -57
  94. data/lib/active_merchant/billing/gateways/hps.rb +252 -68
  95. data/lib/active_merchant/billing/gateways/iats_payments.rb +99 -38
  96. data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +15 -0
  97. data/lib/active_merchant/billing/gateways/inspire.rb +48 -48
  98. data/lib/active_merchant/billing/gateways/instapay.rb +10 -14
  99. data/lib/active_merchant/billing/gateways/ipg.rb +415 -0
  100. data/lib/active_merchant/billing/gateways/ipp.rb +176 -0
  101. data/lib/active_merchant/billing/gateways/iridium.rb +254 -244
  102. data/lib/active_merchant/billing/gateways/itransact.rb +14 -14
  103. data/lib/active_merchant/billing/gateways/iveri.rb +254 -0
  104. data/lib/active_merchant/billing/gateways/ixopay.rb +320 -0
  105. data/lib/active_merchant/billing/gateways/jetpay.rb +200 -80
  106. data/lib/active_merchant/billing/gateways/jetpay_v2.rb +432 -0
  107. data/lib/active_merchant/billing/gateways/komoju.rb +115 -0
  108. data/lib/active_merchant/billing/gateways/kushki.rb +277 -0
  109. data/lib/active_merchant/billing/gateways/latitude19.rb +412 -0
  110. data/lib/active_merchant/billing/gateways/linkpoint.rb +95 -85
  111. data/lib/active_merchant/billing/gateways/litle.rb +371 -94
  112. data/lib/active_merchant/billing/gateways/mastercard.rb +293 -0
  113. data/lib/active_merchant/billing/gateways/maxipago.rb +146 -123
  114. data/lib/active_merchant/billing/gateways/mercado_pago.rb +331 -0
  115. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +47 -23
  116. data/lib/active_merchant/billing/gateways/merchant_one.rb +16 -20
  117. data/lib/active_merchant/billing/gateways/merchant_partners.rb +245 -0
  118. data/lib/active_merchant/billing/gateways/merchant_ware.rb +54 -60
  119. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +60 -44
  120. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +76 -23
  121. data/lib/active_merchant/billing/gateways/mercury.rb +73 -54
  122. data/lib/active_merchant/billing/gateways/metrics_global.rb +33 -43
  123. data/lib/active_merchant/billing/gateways/micropayment.rb +182 -0
  124. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +7 -7
  125. data/lib/active_merchant/billing/gateways/migs.rb +101 -37
  126. data/lib/active_merchant/billing/gateways/mit.rb +260 -0
  127. data/lib/active_merchant/billing/gateways/modern_payments.rb +3 -3
  128. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +30 -34
  129. data/lib/active_merchant/billing/gateways/moka.rb +290 -0
  130. data/lib/active_merchant/billing/gateways/monei.rb +422 -0
  131. data/lib/active_merchant/billing/gateways/moneris.rb +236 -72
  132. data/lib/active_merchant/billing/gateways/money_movers.rb +11 -13
  133. data/lib/active_merchant/billing/gateways/mundipagg.rb +363 -0
  134. data/lib/active_merchant/billing/gateways/nab_transact.rb +87 -68
  135. data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +163 -0
  136. data/lib/active_merchant/billing/gateways/net_registry.rb +12 -12
  137. data/lib/active_merchant/billing/gateways/netaxept.rb +33 -34
  138. data/lib/active_merchant/billing/gateways/netbanx.rb +376 -0
  139. data/lib/active_merchant/billing/gateways/netbilling.rb +82 -43
  140. data/lib/active_merchant/billing/gateways/netpay.rb +10 -10
  141. data/lib/active_merchant/billing/gateways/network_merchants.rb +7 -11
  142. data/lib/active_merchant/billing/gateways/nmi.rb +279 -174
  143. data/lib/active_merchant/billing/gateways/ogone.rb +96 -50
  144. data/lib/active_merchant/billing/gateways/omise.rb +323 -0
  145. data/lib/active_merchant/billing/gateways/openpay.rb +58 -23
  146. data/lib/active_merchant/billing/gateways/opp.rb +394 -0
  147. data/lib/active_merchant/billing/gateways/optimal_payment.rb +87 -69
  148. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +5 -7
  149. data/lib/active_merchant/billing/gateways/orbital.rb +771 -328
  150. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +31 -32
  151. data/lib/active_merchant/billing/gateways/pagarme.rb +239 -0
  152. data/lib/active_merchant/billing/gateways/pago_facil.rb +12 -14
  153. data/lib/active_merchant/billing/gateways/pay_arc.rb +392 -0
  154. data/lib/active_merchant/billing/gateways/pay_conex.rb +245 -0
  155. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +84 -68
  156. data/lib/active_merchant/billing/gateways/pay_hub.rb +213 -0
  157. data/lib/active_merchant/billing/gateways/pay_junction.rb +37 -37
  158. data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +206 -0
  159. data/lib/active_merchant/billing/gateways/pay_secure.rb +15 -17
  160. data/lib/active_merchant/billing/gateways/pay_trace.rb +404 -0
  161. data/lib/active_merchant/billing/gateways/paybox_direct.rb +85 -49
  162. data/lib/active_merchant/billing/gateways/payeezy.rb +458 -0
  163. data/lib/active_merchant/billing/gateways/payex.rb +39 -42
  164. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +67 -41
  165. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +11 -8
  166. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +3 -3
  167. data/lib/active_merchant/billing/gateways/payflow.rb +215 -46
  168. data/lib/active_merchant/billing/gateways/payflow_express.rb +64 -68
  169. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +2 -3
  170. data/lib/active_merchant/billing/gateways/payflow_uk.rb +5 -6
  171. data/lib/active_merchant/billing/gateways/payment_express.rb +78 -58
  172. data/lib/active_merchant/billing/gateways/paymentez.rb +353 -0
  173. data/lib/active_merchant/billing/gateways/paymill.rb +163 -75
  174. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +55 -7
  175. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +1 -1
  176. data/lib/active_merchant/billing/gateways/paypal.rb +37 -18
  177. data/lib/active_merchant/billing/gateways/paypal_ca.rb +2 -2
  178. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +5 -5
  179. data/lib/active_merchant/billing/gateways/paypal_express.rb +12 -6
  180. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +3 -3
  181. data/lib/active_merchant/billing/gateways/paysafe.rb +412 -0
  182. data/lib/active_merchant/billing/gateways/payscout.rb +10 -13
  183. data/lib/active_merchant/billing/gateways/paystation.rb +96 -91
  184. data/lib/active_merchant/billing/gateways/payu_in.rb +249 -0
  185. data/lib/active_merchant/billing/gateways/payu_latam.rb +479 -0
  186. data/lib/active_merchant/billing/gateways/payway.rb +27 -27
  187. data/lib/active_merchant/billing/gateways/payway_dot_com.rb +253 -0
  188. data/lib/active_merchant/billing/gateways/pin.rb +113 -37
  189. data/lib/active_merchant/billing/gateways/plugnpay.rb +82 -82
  190. data/lib/active_merchant/billing/gateways/priority.rb +369 -0
  191. data/lib/active_merchant/billing/gateways/pro_pay.rb +325 -0
  192. data/lib/active_merchant/billing/gateways/psigate.rb +55 -44
  193. data/lib/active_merchant/billing/gateways/psl_card.rb +32 -40
  194. data/lib/active_merchant/billing/gateways/qbms.rb +86 -76
  195. data/lib/active_merchant/billing/gateways/quantum.rb +21 -23
  196. data/lib/active_merchant/billing/gateways/quickbooks.rb +377 -0
  197. data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +184 -0
  198. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +297 -0
  199. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +226 -0
  200. data/lib/active_merchant/billing/gateways/quickpay.rb +10 -353
  201. data/lib/active_merchant/billing/gateways/qvalent.rb +305 -0
  202. data/lib/active_merchant/billing/gateways/rapyd.rb +258 -0
  203. data/lib/active_merchant/billing/gateways/realex.rb +154 -52
  204. data/lib/active_merchant/billing/gateways/redsys.rb +488 -161
  205. data/lib/active_merchant/billing/gateways/s5.rb +247 -0
  206. data/lib/active_merchant/billing/gateways/safe_charge.rb +298 -0
  207. data/lib/active_merchant/billing/gateways/sage.rb +404 -133
  208. data/lib/active_merchant/billing/gateways/sage_pay.rb +145 -109
  209. data/lib/active_merchant/billing/gateways/sallie_mae.rb +13 -15
  210. data/lib/active_merchant/billing/gateways/secure_net.rb +62 -54
  211. data/lib/active_merchant/billing/gateways/secure_pay.rb +32 -42
  212. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +36 -27
  213. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +14 -16
  214. data/lib/active_merchant/billing/gateways/securion_pay.rb +265 -0
  215. data/lib/active_merchant/billing/gateways/simetrik.rb +362 -0
  216. data/lib/active_merchant/billing/gateways/skip_jack.rb +52 -54
  217. data/lib/active_merchant/billing/gateways/smart_ps.rb +51 -60
  218. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +29 -29
  219. data/lib/active_merchant/billing/gateways/spreedly_core.rb +108 -43
  220. data/lib/active_merchant/billing/gateways/stripe.rb +536 -120
  221. data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +516 -0
  222. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +19 -25
  223. data/lib/active_merchant/billing/gateways/telr.rb +273 -0
  224. data/lib/active_merchant/billing/gateways/tns.rb +16 -217
  225. data/lib/active_merchant/billing/gateways/trans_first.rb +148 -34
  226. data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +612 -0
  227. data/lib/active_merchant/billing/gateways/transact_pro.rb +222 -0
  228. data/lib/active_merchant/billing/gateways/transax.rb +6 -8
  229. data/lib/active_merchant/billing/gateways/transnational.rb +1 -2
  230. data/lib/active_merchant/billing/gateways/trexle.rb +221 -0
  231. data/lib/active_merchant/billing/gateways/trust_commerce.rb +162 -89
  232. data/lib/active_merchant/billing/gateways/usa_epay.rb +5 -6
  233. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +332 -236
  234. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +185 -72
  235. data/lib/active_merchant/billing/gateways/vanco.rb +294 -0
  236. data/lib/active_merchant/billing/gateways/verifi.rb +52 -53
  237. data/lib/active_merchant/billing/gateways/viaklix.rb +19 -31
  238. data/lib/active_merchant/billing/gateways/visanet_peru.rb +250 -0
  239. data/lib/active_merchant/billing/gateways/vpos.rb +220 -0
  240. data/lib/active_merchant/billing/gateways/webpay.rb +9 -9
  241. data/lib/active_merchant/billing/gateways/wepay.rb +108 -62
  242. data/lib/active_merchant/billing/gateways/wirecard.rb +52 -43
  243. data/lib/active_merchant/billing/gateways/wompi.rb +193 -0
  244. data/lib/active_merchant/billing/gateways/world_net.rb +345 -0
  245. data/lib/active_merchant/billing/gateways/worldpay.rb +725 -121
  246. data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +208 -0
  247. data/lib/active_merchant/billing/gateways/worldpay_us.rb +79 -39
  248. data/lib/active_merchant/billing/gateways.rb +8 -11
  249. data/lib/active_merchant/billing/model.rb +2 -2
  250. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +39 -0
  251. data/lib/active_merchant/billing/payment_token.rb +1 -1
  252. data/lib/active_merchant/billing/rails.rb +1 -1
  253. data/lib/active_merchant/billing/response.rb +19 -13
  254. data/lib/active_merchant/billing/three_d_secure_eci_mapper.rb +27 -0
  255. data/lib/active_merchant/billing.rb +3 -0
  256. data/lib/active_merchant/connection.rb +196 -0
  257. data/lib/active_merchant/country.rb +13 -8
  258. data/lib/active_merchant/errors.rb +6 -0
  259. data/lib/active_merchant/net_http_ssl_connection.rb +11 -0
  260. data/lib/active_merchant/network_connection_retries.rb +78 -0
  261. data/lib/active_merchant/post_data.rb +26 -0
  262. data/lib/active_merchant/posts_data.rb +92 -0
  263. data/lib/active_merchant/version.rb +1 -1
  264. data/lib/active_merchant.rb +14 -59
  265. data/lib/activemerchant.rb +1 -1
  266. data/lib/certs/cacert.pem +3214 -0
  267. data/lib/support/gateway_support.rb +8 -10
  268. data/lib/support/outbound_hosts.rb +13 -10
  269. data/lib/support/ssl_verify.rb +9 -14
  270. data/lib/support/ssl_version.rb +86 -0
  271. metadata +136 -94
  272. checksums.yaml.gz.sig +0 -1
  273. data/lib/active_merchant/billing/gateways/app55.rb +0 -176
  274. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +0 -314
  275. data/lib/active_merchant/billing/gateways/certo_direct.rb +0 -278
  276. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +0 -246
  277. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +0 -13
  278. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +0 -29
  279. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +0 -66
  280. data/lib/active_merchant/billing/gateways/moneris_us.rb +0 -291
  281. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +0 -87
  282. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +0 -114
  283. data/lib/active_merchant/billing/gateways/sage/sage_vault.rb +0 -149
  284. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +0 -102
  285. data/lib/active_merchant/billing/gateways/vindicia.rb +0 -385
  286. data/lib/active_merchant/offsite_payments_shim.rb +0 -19
  287. data.tar.gz.sig +0 -0
  288. metadata.gz.sig +0 -0
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+
2
3
  require 'nokogiri'
3
4
 
4
5
  module ActiveMerchant #:nodoc:
@@ -24,124 +25,156 @@ module ActiveMerchant #:nodoc:
24
25
  #
25
26
  # Written by Samuel Lown for Cabify. For implementation questions, or
26
27
  # test access details please get in touch: sam@cabify.com.
28
+ #
29
+ # *** SHA256 Authentication Update ***
30
+ #
31
+ # Redsys is dropping support for the SHA1 authentication method. This
32
+ # adapter has been updated to work with the new SHA256 authentication
33
+ # method, however in your initialization options hash you will need to
34
+ # specify the key/value :signature_algorithm => "sha256" to use the
35
+ # SHA256 method. Otherwise it will default to using the SHA1.
36
+ #
37
+ #
27
38
  class RedsysGateway < Gateway
28
- self.live_url = "https://sis.sermepa.es/sis/operaciones"
29
- self.test_url = "https://sis-t.sermepa.es:25443/sis/operaciones"
39
+ self.live_url = 'https://sis.redsys.es/sis/operaciones'
40
+ self.test_url = 'https://sis-t.redsys.es:25443/sis/operaciones'
30
41
 
31
42
  self.supported_countries = ['ES']
32
43
  self.default_currency = 'EUR'
33
44
  self.money_format = :cents
34
45
 
35
46
  # Not all card types may be activated by the bank!
36
- self.supported_cardtypes = [:visa, :master, :american_express, :jcb, :diners_club]
37
- self.homepage_url = "http://www.redsys.es/"
38
- self.display_name = "Redsys"
47
+ self.supported_cardtypes = %i[visa master american_express jcb diners_club unionpay]
48
+ self.homepage_url = 'http://www.redsys.es/'
49
+ self.display_name = 'Redsys'
39
50
 
40
51
  CURRENCY_CODES = {
41
- "ARS" => '032',
42
- "AUD" => '036',
43
- "BRL" => '986',
44
- "BOB" => '068',
45
- "CAD" => '124',
46
- "CHF" => '756',
47
- "CLP" => '152',
48
- "COP" => '170',
49
- "EUR" => '978',
50
- "GBP" => '826',
51
- "GTQ" => '320',
52
- "JPY" => '392',
53
- "MXN" => '484',
54
- "NZD" => '554',
55
- "PEN" => '604',
56
- "RUB" => '643',
57
- "SGD" => '702',
58
- "USD" => '840',
59
- "UYU" => '858'
52
+ 'AED' => '784',
53
+ 'ARS' => '32',
54
+ 'AUD' => '36',
55
+ 'BRL' => '986',
56
+ 'BOB' => '68',
57
+ 'CAD' => '124',
58
+ 'CHF' => '756',
59
+ 'CLP' => '152',
60
+ 'CNY' => '156',
61
+ 'COP' => '170',
62
+ 'CRC' => '188',
63
+ 'CZK' => '203',
64
+ 'DKK' => '208',
65
+ 'DOP' => '214',
66
+ 'EUR' => '978',
67
+ 'GBP' => '826',
68
+ 'GTQ' => '320',
69
+ 'HUF' => '348',
70
+ 'IDR' => '360',
71
+ 'INR' => '356',
72
+ 'JPY' => '392',
73
+ 'KRW' => '410',
74
+ 'MYR' => '458',
75
+ 'MXN' => '484',
76
+ 'NOK' => '578',
77
+ 'NZD' => '554',
78
+ 'PEN' => '604',
79
+ 'PLN' => '985',
80
+ 'RUB' => '643',
81
+ 'SAR' => '682',
82
+ 'SEK' => '752',
83
+ 'SGD' => '702',
84
+ 'THB' => '764',
85
+ 'TWD' => '901',
86
+ 'USD' => '840',
87
+ 'UYU' => '858'
60
88
  }
61
89
 
62
90
  # The set of supported transactions for this gateway.
63
91
  # More operations are supported by the gateway itself, but
64
92
  # are not supported in this library.
65
93
  SUPPORTED_TRANSACTIONS = {
66
- :purchase => 'A',
67
- :authorize => '1',
68
- :capture => '2',
69
- :refund => '3',
70
- :cancel => '9'
94
+ purchase: 'A',
95
+ authorize: '1',
96
+ capture: '2',
97
+ refund: '3',
98
+ cancel: '9'
71
99
  }
72
100
 
73
101
  # These are the text meanings sent back by the acquirer when
74
102
  # a card has been rejected. Syntax or general request errors
75
103
  # are not covered here.
76
104
  RESPONSE_TEXTS = {
77
- 0 => "Transaction Approved",
78
- 400 => "Cancellation Accepted",
79
- 481 => "Cancellation Accepted",
80
- 500 => "Reconciliation Accepted",
81
- 900 => "Refund / Confirmation approved",
82
-
83
- 101 => "Card expired",
84
- 102 => "Card blocked temporarily or under susciption of fraud",
85
- 104 => "Transaction not permitted",
86
- 107 => "Contact the card issuer",
87
- 109 => "Invalid identification by merchant or POS terminal",
88
- 110 => "Invalid amount",
89
- 114 => "Card cannot be used to the requested transaction",
90
- 116 => "Insufficient credit",
91
- 118 => "Non-registered card",
92
- 125 => "Card not effective",
93
- 129 => "CVV2/CVC2 Error",
94
- 167 => "Contact the card issuer: suspected fraud",
95
- 180 => "Card out of service",
96
- 181 => "Card with credit or debit restrictions",
97
- 182 => "Card with credit or debit restrictions",
98
- 184 => "Authentication error",
99
- 190 => "Refusal with no specific reason",
100
- 191 => "Expiry date incorrect",
101
-
102
- 201 => "Card expired",
103
- 202 => "Card blocked temporarily or under suscipition of fraud",
104
- 204 => "Transaction not permitted",
105
- 207 => "Contact the card issuer",
106
- 208 => "Lost or stolen card",
107
- 209 => "Lost or stolen card",
108
- 280 => "CVV2/CVC2 Error",
109
- 290 => "Declined with no specific reason",
110
-
111
- 480 => "Original transaction not located, or time-out exceeded",
112
- 501 => "Original transaction not located, or time-out exceeded",
113
- 502 => "Original transaction not located, or time-out exceeded",
114
- 503 => "Original transaction not located, or time-out exceeded",
115
-
116
- 904 => "Merchant not registered at FUC",
117
- 909 => "System error",
118
- 912 => "Issuer not available",
119
- 913 => "Duplicate transmission",
120
- 916 => "Amount too low",
121
- 928 => "Time-out exceeded",
122
- 940 => "Transaction cancelled previously",
123
- 941 => "Authorization operation already cancelled",
124
- 942 => "Original authorization declined",
125
- 943 => "Different details from origin transaction",
126
- 944 => "Session error",
127
- 945 => "Duplicate transmission",
128
- 946 => "Cancellation of transaction while in progress",
129
- 947 => "Duplicate tranmission while in progress",
130
- 949 => "POS Inoperative",
131
- 950 => "Refund not possible",
132
- 9064 => "Card number incorrect",
133
- 9078 => "No payment method available",
134
- 9093 => "Non-existent card",
135
- 9218 => "Recursive transaction in bad gateway",
136
- 9253 => "Check-digit incorrect",
137
- 9256 => "Preauth not allowed for merchant",
138
- 9257 => "Preauth not allowed for card",
139
- 9261 => "Operating limit exceeded",
140
- 9912 => "Issuer not available",
141
- 9913 => "Confirmation error",
142
- 9914 => "KO Confirmation"
105
+ 0 => 'Transaction Approved',
106
+ 400 => 'Cancellation Accepted',
107
+ 481 => 'Cancellation Accepted',
108
+ 500 => 'Reconciliation Accepted',
109
+ 900 => 'Refund / Confirmation approved',
110
+
111
+ 101 => 'Card expired',
112
+ 102 => 'Card blocked temporarily or under susciption of fraud',
113
+ 104 => 'Transaction not permitted',
114
+ 107 => 'Contact the card issuer',
115
+ 109 => 'Invalid identification by merchant or POS terminal',
116
+ 110 => 'Invalid amount',
117
+ 114 => 'Card cannot be used to the requested transaction',
118
+ 116 => 'Insufficient credit',
119
+ 118 => 'Non-registered card',
120
+ 125 => 'Card not effective',
121
+ 129 => 'CVV2/CVC2 Error',
122
+ 167 => 'Contact the card issuer: suspected fraud',
123
+ 180 => 'Card out of service',
124
+ 181 => 'Card with credit or debit restrictions',
125
+ 182 => 'Card with credit or debit restrictions',
126
+ 184 => 'Authentication error',
127
+ 190 => 'Refusal with no specific reason',
128
+ 191 => 'Expiry date incorrect',
129
+ 195 => 'Requires SCA authentication',
130
+
131
+ 201 => 'Card expired',
132
+ 202 => 'Card blocked temporarily or under suspicion of fraud',
133
+ 204 => 'Transaction not permitted',
134
+ 207 => 'Contact the card issuer',
135
+ 208 => 'Lost or stolen card',
136
+ 209 => 'Lost or stolen card',
137
+ 280 => 'CVV2/CVC2 Error',
138
+ 290 => 'Declined with no specific reason',
139
+
140
+ 480 => 'Original transaction not located, or time-out exceeded',
141
+ 501 => 'Original transaction not located, or time-out exceeded',
142
+ 502 => 'Original transaction not located, or time-out exceeded',
143
+ 503 => 'Original transaction not located, or time-out exceeded',
144
+
145
+ 904 => 'Merchant not registered at FUC',
146
+ 909 => 'System error',
147
+ 912 => 'Issuer not available',
148
+ 913 => 'Duplicate transmission',
149
+ 916 => 'Amount too low',
150
+ 928 => 'Time-out exceeded',
151
+ 940 => 'Transaction cancelled previously',
152
+ 941 => 'Authorization operation already cancelled',
153
+ 942 => 'Original authorization declined',
154
+ 943 => 'Different details from origin transaction',
155
+ 944 => 'Session error',
156
+ 945 => 'Duplicate transmission',
157
+ 946 => 'Cancellation of transaction while in progress',
158
+ 947 => 'Duplicate tranmission while in progress',
159
+ 949 => 'POS Inoperative',
160
+ 950 => 'Refund not possible',
161
+ 9064 => 'Card number incorrect',
162
+ 9078 => 'No payment method available',
163
+ 9093 => 'Non-existent card',
164
+ 9218 => 'Recursive transaction in bad gateway',
165
+ 9253 => 'Check-digit incorrect',
166
+ 9256 => 'Preauth not allowed for merchant',
167
+ 9257 => 'Preauth not allowed for card',
168
+ 9261 => 'Operating limit exceeded',
169
+ 9912 => 'Issuer not available',
170
+ 9913 => 'Confirmation error',
171
+ 9914 => 'KO Confirmation'
143
172
  }
144
173
 
174
+ # Expected values as per documentation
175
+ THREE_DS_V1 = '1.0.2'
176
+ THREE_DS_V2 = '2.1.0'
177
+
145
178
  # Creates a new instance
146
179
  #
147
180
  # Redsys requires a login and secret_key, and optionally also accepts a
@@ -153,69 +186,83 @@ module ActiveMerchant #:nodoc:
153
186
  # * <tt>:secret_key</tt> -- The Redsys Secret Key. (REQUIRED)
154
187
  # * <tt>:terminal</tt> -- The Redsys Terminal. Defaults to 1. (OPTIONAL)
155
188
  # * <tt>:test</tt> -- +true+ or +false+. Defaults to +false+. (OPTIONAL)
189
+ # * <tt>:signature_algorithm</tt> -- +"sha256"+ Defaults to +"sha1"+. (OPTIONAL)
156
190
  def initialize(options = {})
157
191
  requires!(options, :login, :secret_key)
158
192
  options[:terminal] ||= 1
193
+ options[:signature_algorithm] ||= 'sha1'
159
194
  super
160
195
  end
161
196
 
162
- def purchase(money, creditcard, options = {})
197
+ def purchase(money, payment, options = {})
163
198
  requires!(options, :order_id)
164
199
 
165
200
  data = {}
166
- add_action(data, :purchase)
201
+ add_action(data, :purchase, options)
167
202
  add_amount(data, money, options)
168
203
  add_order(data, options[:order_id])
169
- add_creditcard(data, creditcard)
204
+ add_payment(data, payment)
205
+ add_external_mpi_fields(data, options)
206
+ add_three_ds_data(data, options) if options[:execute_threed]
207
+ add_stored_credential_options(data, options)
170
208
  data[:description] = options[:description]
209
+ data[:store_in_vault] = options[:store]
210
+ data[:sca_exemption] = options[:sca_exemption]
211
+ data[:sca_exemption_direct_payment_enabled] = options[:sca_exemption_direct_payment_enabled]
171
212
 
172
- commit data
213
+ commit data, options
173
214
  end
174
215
 
175
- def authorize(money, creditcard, options = {})
216
+ def authorize(money, payment, options = {})
176
217
  requires!(options, :order_id)
177
218
 
178
219
  data = {}
179
- add_action(data, :authorize)
220
+ add_action(data, :authorize, options)
180
221
  add_amount(data, money, options)
181
222
  add_order(data, options[:order_id])
182
- add_creditcard(data, creditcard)
223
+ add_payment(data, payment)
224
+ add_external_mpi_fields(data, options)
225
+ add_three_ds_data(data, options) if options[:execute_threed]
226
+ add_stored_credential_options(data, options)
183
227
  data[:description] = options[:description]
228
+ data[:store_in_vault] = options[:store]
229
+ data[:sca_exemption] = options[:sca_exemption]
230
+ data[:sca_exemption_direct_payment_enabled] = options[:sca_exemption_direct_payment_enabled]
184
231
 
185
- commit data
232
+ commit data, options
186
233
  end
187
234
 
188
235
  def capture(money, authorization, options = {})
189
236
  data = {}
190
237
  add_action(data, :capture)
191
238
  add_amount(data, money, options)
192
- order_id, _, _ = split_authorization(authorization)
239
+ order_id, = split_authorization(authorization)
193
240
  add_order(data, order_id)
194
241
  data[:description] = options[:description]
195
242
 
196
- commit data
243
+ commit data, options
197
244
  end
198
245
 
199
246
  def void(authorization, options = {})
200
247
  data = {}
201
248
  add_action(data, :cancel)
202
249
  order_id, amount, currency = split_authorization(authorization)
203
- add_amount(data, amount, :currency => currency)
250
+ add_amount(data, amount, currency: currency)
204
251
  add_order(data, order_id)
205
252
  data[:description] = options[:description]
206
253
 
207
- commit data
254
+ commit data, options
208
255
  end
209
256
 
210
257
  def refund(money, authorization, options = {})
211
258
  data = {}
212
259
  add_action(data, :refund)
213
260
  add_amount(data, money, options)
214
- order_id, _, _ = split_authorization(authorization)
261
+ order_id, = split_authorization(authorization)
215
262
  add_order(data, order_id)
216
263
  data[:description] = options[:description]
217
264
 
218
- commit data
265
+ commit data, options
219
266
  end
220
267
 
221
268
  def verify(creditcard, options = {})
@@ -225,10 +272,31 @@ module ActiveMerchant #:nodoc:
225
272
  end
226
273
  end
227
274
 
275
+ def supports_scrubbing
276
+ true
277
+ end
278
+
279
+ def scrub(transcript)
280
+ transcript.
281
+ gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
282
+ gsub(%r((%3CDS_MERCHANT_PAN%3E)\d+(%3C%2FDS_MERCHANT_PAN%3E))i, '\1[FILTERED]\2').
283
+ gsub(%r((%3CDS_MERCHANT_CVV2%3E)\d+(%3C%2FDS_MERCHANT_CVV2%3E))i, '\1[FILTERED]\2').
284
+ gsub(%r((&lt;DS_MERCHANT_PAN&gt;)\d+(&lt;/DS_MERCHANT_PAN&gt;))i, '\1[FILTERED]\2').
285
+ gsub(%r((<DS_MERCHANT_PAN>)\d+(</DS_MERCHANT_PAN>))i, '\1[FILTERED]\2').
286
+ gsub(%r((<DS_MERCHANT_CVV2>)\d+(</DS_MERCHANT_CVV2>))i, '\1[FILTERED]\2').
287
+ gsub(%r((&lt;DS_MERCHANT_CVV2&gt;)\d+(&lt;/DS_MERCHANT_CVV2&gt;))i, '\1[FILTERED]\2').
288
+ gsub(%r((DS_MERCHANT_CVV2)%2F%3E%0A%3C%2F)i, '\1[BLANK]').
289
+ gsub(%r((DS_MERCHANT_CVV2)%2F%3E%3C)i, '\1[BLANK]').
290
+ gsub(%r((DS_MERCHANT_CVV2%3E)(%3C%2FDS_MERCHANT_CVV2))i, '\1[BLANK]\2').
291
+ gsub(%r((<DS_MERCHANT_CVV2>)(</DS_MERCHANT_CVV2>))i, '\1[BLANK]\2').
292
+ gsub(%r((DS_MERCHANT_CVV2%3E)\++(%3C%2FDS_MERCHANT_CVV2))i, '\1[BLANK]\2').
293
+ gsub(%r((<DS_MERCHANT_CVV2>)\s+(</DS_MERCHANT_CVV2>))i, '\1[BLANK]\2')
294
+ end
295
+
228
296
  private
229
297
 
230
- def add_action(data, action)
231
- data[:action] = transaction_code(action)
298
+ def add_action(data, action, options = {})
299
+ data[:action] = options[:execute_threed].present? ? '0' : transaction_code(action)
232
300
  end
233
301
 
234
302
  def add_amount(data, money, options)
@@ -244,24 +312,125 @@ module ActiveMerchant #:nodoc:
244
312
  test? ? test_url : live_url
245
313
  end
246
314
 
247
- def add_creditcard(data, card)
248
- name = [card.first_name, card.last_name].join(' ').slice(0, 60)
249
- year = sprintf("%.4i", card.year)
250
- month = sprintf("%.2i", card.month)
251
- data[:card] = {
252
- :name => name,
253
- :pan => card.number,
254
- :date => "#{year[2..3]}#{month}",
255
- :cvv => card.verification_value
256
- }
315
+ def webservice_url
316
+ test? ? 'https://sis-t.redsys.es:25443/sis/services/SerClsWSEntradaV2' : 'https://sis.redsys.es/sis/services/SerClsWSEntradaV2'
317
+ end
318
+
319
+ def add_payment(data, card)
320
+ if card.is_a?(String)
321
+ data[:credit_card_token] = card
322
+ else
323
+ name = [card.first_name, card.last_name].join(' ').slice(0, 60)
324
+ year = sprintf('%.4i', card.year)
325
+ month = sprintf('%.2i', card.month)
326
+ data[:card] = {
327
+ name: name,
328
+ pan: card.number,
329
+ date: "#{year[2..3]}#{month}",
330
+ cvv: card.verification_value
331
+ }
332
+ end
333
+ end
334
+
335
+ def add_external_mpi_fields(data, options)
336
+ return unless options[:three_d_secure]
337
+
338
+ if options[:three_d_secure][:version] == THREE_DS_V2
339
+ data[:threeDSServerTransID] = options[:three_d_secure][:three_ds_server_trans_id] if options[:three_d_secure][:three_ds_server_trans_id]
340
+ data[:dsTransID] = options[:three_d_secure][:ds_transaction_id] if options[:three_d_secure][:ds_transaction_id]
341
+ data[:authenticacionValue] = options[:three_d_secure][:cavv] if options[:three_d_secure][:cavv]
342
+ data[:protocolVersion] = options[:three_d_secure][:version] if options[:three_d_secure][:version]
343
+ data[:authenticacionMethod] = options[:authentication_method] if options[:authentication_method]
344
+ data[:authenticacionType] = options[:authentication_type] if options[:authentication_type]
345
+ data[:authenticacionFlow] = options[:authentication_flow] if options[:authentication_flow]
346
+ data[:eci_v2] = options[:three_d_secure][:eci] if options[:three_d_secure][:eci]
347
+ elsif options[:three_d_secure][:version] == THREE_DS_V1
348
+ data[:txid] = options[:three_d_secure][:xid] if options[:three_d_secure][:xid]
349
+ data[:cavv] = options[:three_d_secure][:cavv] if options[:three_d_secure][:cavv]
350
+ data[:eci_v1] = options[:three_d_secure][:eci] if options[:three_d_secure][:eci]
351
+ end
352
+ end
353
+
354
+ def add_stored_credential_options(data, options)
355
+ return unless options[:stored_credential]
356
+
357
+ case options[:stored_credential][:initial_transaction]
358
+ when true
359
+ data[:DS_MERCHANT_COF_INI] = 'S'
360
+ when false
361
+ data[:DS_MERCHANT_COF_INI] = 'N'
362
+ data[:DS_MERCHANT_COF_TXNID] = options[:stored_credential][:network_transaction_id] if options[:stored_credential][:network_transaction_id]
363
+ end
364
+
365
+ case options[:stored_credential][:reason_type]
366
+ when 'recurring'
367
+ data[:DS_MERCHANT_COF_TYPE] = 'R'
368
+ when 'installment'
369
+ data[:DS_MERCHANT_COF_TYPE] = 'I'
370
+ when 'unscheduled'
371
+ return
372
+ end
373
+ end
374
+
375
+ def add_three_ds_data(data, options)
376
+ data[:three_ds_data] = { threeDSInfo: 'CardData' } if options[:execute_threed] == true
257
377
  end
258
378
 
259
- def commit(data)
260
- headers = {
261
- 'Content-Type' => 'application/x-www-form-urlencoded'
262
- }
263
- xml = build_xml_request(data)
264
- parse(ssl_post(url, "entrada=#{CGI.escape(xml)}", headers))
379
+ def determine_peticion_type(data)
380
+ three_ds_info = data.dig(:three_ds_data, :threeDSInfo)
381
+ return 'iniciaPeticion' if three_ds_info == 'CardData'
382
+ return 'trataPeticion' if three_ds_info == 'AuthenticationData' ||
383
+ three_ds_info == 'ChallengeResponse' ||
384
+ data[:sca_exemption] == 'MIT'
385
+ end
386
+
387
+ def use_webservice_endpoint?(data, options)
388
+ options[:use_webservice_endpoint].to_s == 'true' || data[:three_ds_data] || data[:sca_exemption] == 'MIT'
389
+ end
390
+
391
+ def commit(data, options = {})
392
+ xmlreq = xml_request_from(data, options)
393
+
394
+ if use_webservice_endpoint?(data, options)
395
+ peticion_type = determine_peticion_type(data)
396
+
397
+ request = <<-REQUEST
398
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://webservice.sis.sermepa.es" xmlns:intf="http://webservice.sis.sermepa.es" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
399
+ <soapenv:Header/>
400
+ <soapenv:Body>
401
+ <intf:#{peticion_type} xmlns:intf="http://webservice.sis.sermepa.es">
402
+ <intf:datoEntrada>
403
+ <![CDATA[#{xmlreq}]]>
404
+ </intf:datoEntrada>
405
+ </intf:#{peticion_type}>
406
+ </soapenv:Body>
407
+ </soapenv:Envelope>
408
+ REQUEST
409
+ parse(ssl_post(webservice_url, request, headers(peticion_type)), peticion_type)
410
+ else
411
+ parse(ssl_post(url, "entrada=#{CGI.escape(xmlreq)}", headers), peticion_type)
412
+ end
413
+ end
414
+
415
+ def headers(peticion_type = nil)
416
+ if peticion_type
417
+ {
418
+ 'Content-Type' => 'text/xml',
419
+ 'SOAPAction' => peticion_type
420
+ }
421
+ else
422
+ {
423
+ 'Content-Type' => 'application/x-www-form-urlencoded'
424
+ }
425
+ end
426
+ end
427
+
428
+ def xml_request_from(data, options = {})
429
+ if sha256_authentication?
430
+ build_sha256_xml_request(data, options)
431
+ else
432
+ build_sha1_xml_request(data, options)
433
+ end
265
434
  end
266
435
 
267
436
  def build_signature(data)
@@ -276,13 +445,42 @@ module ActiveMerchant #:nodoc:
276
445
  end
277
446
 
278
447
  str << data[:action]
448
+ if data[:store_in_vault]
449
+ str << 'REQUIRED'
450
+ elsif data[:credit_card_token]
451
+ str << data[:credit_card_token]
452
+ end
279
453
  str << @options[:secret_key]
280
454
 
281
455
  Digest::SHA1.hexdigest(str)
282
456
  end
283
457
 
284
- def build_xml_request(data)
285
- xml = Builder::XmlMarkup.new :indent => 2
458
+ def build_sha256_xml_request(data, options = {})
459
+ xml = Builder::XmlMarkup.new
460
+ xml.instruct!
461
+ xml.REQUEST do
462
+ build_merchant_data(xml, data, options)
463
+ xml.DS_SIGNATUREVERSION 'HMAC_SHA256_V1'
464
+ xml.DS_SIGNATURE sign_request(merchant_data_xml(data, options), data[:order_id])
465
+ end
466
+ xml.target!
467
+ end
468
+
469
+ def build_sha1_xml_request(data, options = {})
470
+ xml = Builder::XmlMarkup.new indent: 2
471
+ build_merchant_data(xml, data, options)
472
+ xml.target!
473
+ end
474
+
475
+ def merchant_data_xml(data, options = {})
476
+ xml = Builder::XmlMarkup.new
477
+ build_merchant_data(xml, data, options)
478
+ xml.target!
479
+ end
480
+
481
+ def build_merchant_data(xml, data, options = {})
482
+ # See https://sis-t.redsys.es:25443/sis/services/SerClsWSEntradaV2/wsdl/SerClsWSEntradaV2.wsdl
483
+ # (which results from calling #webservice_url + '?WSDL', https://sis-t.redsys.es:25443/sis/services/SerClsWSEntradaV2?WSDL)
286
484
  xml.DATOSENTRADA do
287
485
  # Basic elements
288
486
  xml.DS_Version 0.1
@@ -290,42 +488,108 @@ module ActiveMerchant #:nodoc:
290
488
  xml.DS_MERCHANT_AMOUNT data[:amount]
291
489
  xml.DS_MERCHANT_ORDER data[:order_id]
292
490
  xml.DS_MERCHANT_TRANSACTIONTYPE data[:action]
293
- xml.DS_MERCHANT_PRODUCTDESCRIPTION data[:description]
294
- xml.DS_MERCHANT_TERMINAL @options[:terminal]
491
+ if data[:description] && use_webservice_endpoint?(data, options)
492
+ xml.DS_MERCHANT_PRODUCTDESCRIPTION CGI.escape(data[:description])
493
+ else
494
+ xml.DS_MERCHANT_PRODUCTDESCRIPTION data[:description]
495
+ end
496
+ xml.DS_MERCHANT_TERMINAL options[:terminal] || @options[:terminal]
295
497
  xml.DS_MERCHANT_MERCHANTCODE @options[:login]
296
- xml.DS_MERCHANT_MERCHANTSIGNATURE build_signature(data)
498
+ xml.DS_MERCHANT_MERCHANTSIGNATURE build_signature(data) unless sha256_authentication?
499
+
500
+ peticion_type = determine_peticion_type(data) if data[:three_ds_data]
501
+ if peticion_type == 'iniciaPeticion' && data[:sca_exemption]
502
+ xml.DS_MERCHANT_EXCEP_SCA 'Y'
503
+ else
504
+ xml.DS_MERCHANT_EXCEP_SCA data[:sca_exemption] if data[:sca_exemption]
505
+ xml.DS_MERCHANT_DIRECTPAYMENT data[:sca_exemption_direct_payment_enabled] || 'true' if data[:sca_exemption] == 'MIT'
506
+ end
297
507
 
298
508
  # Only when card is present
299
509
  if data[:card]
300
- xml.DS_MERCHANT_TITULAR data[:card][:name]
510
+ if data[:card][:name] && use_webservice_endpoint?(data, options)
511
+ xml.DS_MERCHANT_TITULAR CGI.escape(data[:card][:name])
512
+ else
513
+ xml.DS_MERCHANT_TITULAR data[:card][:name]
514
+ end
301
515
  xml.DS_MERCHANT_PAN data[:card][:pan]
302
516
  xml.DS_MERCHANT_EXPIRYDATE data[:card][:date]
303
517
  xml.DS_MERCHANT_CVV2 data[:card][:cvv]
518
+ xml.DS_MERCHANT_IDENTIFIER 'REQUIRED' if data[:store_in_vault]
519
+
520
+ build_merchant_mpi_external(xml, data)
521
+
522
+ elsif data[:credit_card_token]
523
+ xml.DS_MERCHANT_IDENTIFIER data[:credit_card_token]
524
+ xml.DS_MERCHANT_DIRECTPAYMENT 'true'
525
+ end
526
+
527
+ # Set moto flag only if explicitly requested via moto field
528
+ # Requires account configuration to be able to use
529
+ xml.DS_MERCHANT_DIRECTPAYMENT 'moto' if options.dig(:moto) && options.dig(:metadata, :manual_entry)
530
+
531
+ xml.DS_MERCHANT_EMV3DS data[:three_ds_data].to_json if data[:three_ds_data]
532
+
533
+ if options[:stored_credential]
534
+ xml.DS_MERCHANT_COF_INI data[:DS_MERCHANT_COF_INI]
535
+ xml.DS_MERCHANT_COF_TYPE data[:DS_MERCHANT_COF_TYPE]
536
+ xml.DS_MERCHANT_COF_TXNID data[:DS_MERCHANT_COF_TXNID] if data[:DS_MERCHANT_COF_TXNID]
304
537
  end
305
538
  end
539
+ end
540
+
541
+ def build_merchant_mpi_external(xml, data)
542
+ return unless data[:txid] || data[:threeDSServerTransID]
543
+
544
+ ds_merchant_mpi_external = {}
545
+ ds_merchant_mpi_external[:TXID] = data[:txid] if data[:txid]
546
+ ds_merchant_mpi_external[:CAVV] = data[:cavv] if data[:cavv]
547
+ ds_merchant_mpi_external[:ECI] = data[:eci_v1] if data[:eci_v1]
548
+
549
+ ds_merchant_mpi_external[:threeDSServerTransID] = data[:threeDSServerTransID] if data[:threeDSServerTransID]
550
+ ds_merchant_mpi_external[:dsTransID] = data[:dsTransID] if data[:dsTransID]
551
+ ds_merchant_mpi_external[:authenticacionValue] = data[:authenticacionValue] if data[:authenticacionValue]
552
+ ds_merchant_mpi_external[:protocolVersion] = data[:protocolVersion] if data[:protocolVersion]
553
+ ds_merchant_mpi_external[:Eci] = data[:eci_v2] if data[:eci_v2]
554
+ ds_merchant_mpi_external[:authenticacionMethod] = data[:authenticacionMethod] if data[:authenticacionMethod]
555
+ ds_merchant_mpi_external[:authenticacionType] = data[:authenticacionType] if data[:authenticacionType]
556
+ ds_merchant_mpi_external[:authenticacionFlow] = data[:authenticacionFlow] if data[:authenticacionFlow]
557
+
558
+ xml.DS_MERCHANT_MPIEXTERNAL ds_merchant_mpi_external.to_json unless ds_merchant_mpi_external.empty?
306
559
  xml.target!
307
560
  end
308
561
 
309
- def parse(data)
562
+ def parse(data, action)
310
563
  params = {}
311
564
  success = false
312
- message = ""
313
- options = @options.merge(:test => test?)
565
+ message = ''
566
+ options = @options.merge(test: test?)
314
567
  xml = Nokogiri::XML(data)
315
- code = xml.xpath("//RETORNOXML/CODIGO").text
316
- if code == "0"
317
- op = xml.xpath("//RETORNOXML/OPERACION")
568
+ code = xml.xpath('//RETORNOXML/CODIGO').text
569
+
570
+ if code == '0' && xml.xpath('//RETORNOXML/OPERACION').present?
571
+ op = xml.xpath('//RETORNOXML/OPERACION')
318
572
  op.children.each do |element|
319
573
  params[element.name.downcase.to_sym] = element.text
320
574
  end
321
-
322
575
  if validate_signature(params)
323
576
  message = response_text(params[:ds_response])
324
577
  options[:authorization] = build_authorization(params)
325
- success = is_success_response?(params[:ds_response])
578
+ success = success_response?(params[:ds_response])
326
579
  else
327
- message = "Response failed validation check"
580
+ message = 'Response failed validation check'
581
+ end
582
+ elsif %w[iniciaPeticion trataPeticion].include?(action)
583
+ vxml = Nokogiri::XML(data).remove_namespaces!.xpath("//Envelope/Body/#{action}Response/#{action}Return").inner_text
584
+ xml = Nokogiri::XML(vxml)
585
+ node = (action == 'iniciaPeticion' ? 'INFOTARJETA' : 'OPERACION')
586
+ op = xml.xpath("//RETORNOXML/#{node}")
587
+ op.children.each do |element|
588
+ params[element.name.downcase.to_sym] = element.text
328
589
  end
590
+ message = response_text_3ds(xml, params)
591
+ options[:authorization] = build_authorization(params)
592
+ success = params.size > 0 && success_response?(params[:ds_response])
329
593
  else
330
594
  # Some kind of programmer error with the request!
331
595
  message = "#{code} ERROR"
@@ -335,32 +599,38 @@ module ActiveMerchant #:nodoc:
335
599
  end
336
600
 
337
601
  def validate_signature(data)
338
- str = data[:ds_amount] +
339
- data[:ds_order].to_s +
340
- data[:ds_merchantcode] +
341
- data[:ds_currency] +
342
- data[:ds_response] +
343
- data[:ds_cardnumber].to_s +
344
- data[:ds_transactiontype].to_s +
345
- data[:ds_securepayment].to_s +
346
- @options[:secret_key]
347
-
348
- sig = Digest::SHA1.hexdigest(str)
349
- data[:ds_signature].to_s.downcase == sig
602
+ if sha256_authentication?
603
+ sig = Base64.strict_encode64(mac256(get_key(data[:ds_order].to_s), xml_signed_fields(data)))
604
+ sig.casecmp(data[:ds_signature].to_s).zero?
605
+ else
606
+ str = data[:ds_amount] +
607
+ data[:ds_order].to_s +
608
+ data[:ds_merchantcode] +
609
+ data[:ds_currency] +
610
+ data[:ds_response] +
611
+ data[:ds_cardnumber].to_s +
612
+ data[:ds_transactiontype].to_s +
613
+ data[:ds_securepayment].to_s +
614
+ @options[:secret_key]
615
+
616
+ sig = Digest::SHA1.hexdigest(str)
617
+ data[:ds_signature].to_s.downcase == sig
618
+ end
350
619
  end
351
620
 
352
621
  def build_authorization(params)
353
- [params[:ds_order], params[:ds_amount], params[:ds_currency]].join("|")
622
+ [params[:ds_order], params[:ds_amount], params[:ds_currency]].join('|')
354
623
  end
355
624
 
356
625
  def split_authorization(authorization)
357
- order_id, amount, currency = authorization.split("|")
626
+ order_id, amount, currency = authorization.split('|')
358
627
  [order_id, amount.to_i, currency]
359
628
  end
360
629
 
361
630
  def currency_code(currency)
362
631
  return currency if currency =~ /^\d+$/
363
632
  raise ArgumentError, "Unknown currency #{currency}" unless CURRENCY_CODES[currency]
633
+
364
634
  CURRENCY_CODES[currency]
365
635
  end
366
636
 
@@ -371,21 +641,78 @@ module ActiveMerchant #:nodoc:
371
641
  def response_text(code)
372
642
  code = code.to_i
373
643
  code = 0 if code < 100
374
- RESPONSE_TEXTS[code] || "Unkown code, please check in manual"
644
+ RESPONSE_TEXTS[code] || 'Unknown code, please check in manual'
645
+ end
646
+
647
+ def response_text_3ds(xml, params)
648
+ code = xml.xpath('//RETORNOXML/CODIGO').text
649
+ message = ''
650
+ if code != '0'
651
+ message = "#{code} ERROR"
652
+ elsif params[:ds_emv3ds]
653
+ three_ds_data = JSON.parse(params[:ds_emv3ds])
654
+ message = three_ds_data['threeDSInfo']
655
+ elsif params[:ds_response]
656
+ message = response_text(params[:ds_response])
657
+ end
658
+ message
375
659
  end
376
660
 
377
- def is_success_response?(code)
661
+ def success_response?(code)
378
662
  (code.to_i < 100) || [400, 481, 500, 900].include?(code.to_i)
379
663
  end
380
664
 
381
665
  def clean_order_id(order_id)
382
666
  cleansed = order_id.gsub(/[^\da-zA-Z]/, '')
383
- if cleansed =~ /^\d{4}/
384
- cleansed[0..12]
667
+ if /^\d{4}/.match?(cleansed)
668
+ cleansed[0..11]
385
669
  else
386
- "%04d%s" % [rand(0..9999), cleansed[0...8]]
670
+ '%04d%s' % [rand(0..9999), cleansed[0...8]]
387
671
  end
388
672
  end
673
+
674
+ def sha256_authentication?
675
+ @options[:signature_algorithm] == 'sha256'
676
+ end
677
+
678
+ def sign_request(xml_request_string, order_id)
679
+ key = encrypt(@options[:secret_key], order_id)
680
+ Base64.strict_encode64(mac256(key, xml_request_string))
681
+ end
682
+
683
+ def encrypt(key, order_id)
684
+ block_length = 8
685
+ cipher = OpenSSL::Cipher.new('DES3')
686
+ cipher.encrypt
687
+
688
+ cipher.key = Base64.strict_decode64(key)
689
+ # The OpenSSL default of an all-zeroes ("\\0") IV is used.
690
+ cipher.padding = 0
691
+
692
+ order_id += "\0" until order_id.bytesize % block_length == 0 # Pad with zeros
693
+
694
+ output = cipher.update(order_id) + cipher.final
695
+ output
696
+ end
697
+
698
+ def mac256(key, data)
699
+ OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), key, data)
700
+ end
701
+
702
+ def xml_signed_fields(data)
703
+ xml_signed_fields = data[:ds_amount] + data[:ds_order] + data[:ds_merchantcode] +
704
+ data[:ds_currency] + data[:ds_response]
705
+
706
+ xml_signed_fields += data[:ds_cardnumber] if data[:ds_cardnumber]
707
+
708
+ xml_signed_fields += data[:ds_emv3ds] if data[:ds_emv3ds]
709
+
710
+ xml_signed_fields + data[:ds_transactiontype] + data[:ds_securepayment]
711
+ end
712
+
713
+ def get_key(order_id)
714
+ encrypt(@options[:secret_key], order_id)
715
+ end
389
716
  end
390
717
  end
391
718
  end