swiss-activemerchant 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (287) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +4033 -0
  3. data/CONTRIBUTORS +568 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +249 -0
  6. data/lib/active_merchant/billing/apple_pay_payment_token.rb +22 -0
  7. data/lib/active_merchant/billing/avs_result.rb +95 -0
  8. data/lib/active_merchant/billing/base.rb +48 -0
  9. data/lib/active_merchant/billing/check.rb +112 -0
  10. data/lib/active_merchant/billing/compatibility.rb +118 -0
  11. data/lib/active_merchant/billing/credit_card.rb +451 -0
  12. data/lib/active_merchant/billing/credit_card_formatting.rb +24 -0
  13. data/lib/active_merchant/billing/credit_card_methods.rb +512 -0
  14. data/lib/active_merchant/billing/cvv_result.rb +37 -0
  15. data/lib/active_merchant/billing/gateway.rb +332 -0
  16. data/lib/active_merchant/billing/gateways/adyen.rb +774 -0
  17. data/lib/active_merchant/billing/gateways/airwallex.rb +370 -0
  18. data/lib/active_merchant/billing/gateways/alelo.rb +256 -0
  19. data/lib/active_merchant/billing/gateways/allied_wallet.rb +205 -0
  20. data/lib/active_merchant/billing/gateways/authorize_net.rb +1125 -0
  21. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +424 -0
  22. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +977 -0
  23. data/lib/active_merchant/billing/gateways/axcessms.rb +243 -0
  24. data/lib/active_merchant/billing/gateways/balanced.rb +263 -0
  25. data/lib/active_merchant/billing/gateways/bambora_apac.rb +222 -0
  26. data/lib/active_merchant/billing/gateways/bank_frick.rb +225 -0
  27. data/lib/active_merchant/billing/gateways/banwire.rb +116 -0
  28. data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +397 -0
  29. data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +15 -0
  30. data/lib/active_merchant/billing/gateways/be2bill.rb +131 -0
  31. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +474 -0
  32. data/lib/active_merchant/billing/gateways/beanstream.rb +238 -0
  33. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +57 -0
  34. data/lib/active_merchant/billing/gateways/blue_pay.rb +549 -0
  35. data/lib/active_merchant/billing/gateways/blue_snap.rb +644 -0
  36. data/lib/active_merchant/billing/gateways/bogus.rb +190 -0
  37. data/lib/active_merchant/billing/gateways/borgun.rb +272 -0
  38. data/lib/active_merchant/billing/gateways/bpoint.rb +277 -0
  39. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +28 -0
  40. data/lib/active_merchant/billing/gateways/braintree/token_nonce.rb +113 -0
  41. data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
  42. data/lib/active_merchant/billing/gateways/braintree_blue.rb +952 -0
  43. data/lib/active_merchant/billing/gateways/braintree_orange.rb +19 -0
  44. data/lib/active_merchant/billing/gateways/bridge_pay.rb +244 -0
  45. data/lib/active_merchant/billing/gateways/cams.rb +230 -0
  46. data/lib/active_merchant/billing/gateways/card_connect.rb +338 -0
  47. data/lib/active_merchant/billing/gateways/card_save.rb +21 -0
  48. data/lib/active_merchant/billing/gateways/card_stream.rb +394 -0
  49. data/lib/active_merchant/billing/gateways/cardknox.rb +327 -0
  50. data/lib/active_merchant/billing/gateways/cardprocess.rb +256 -0
  51. data/lib/active_merchant/billing/gateways/cashnet.rb +235 -0
  52. data/lib/active_merchant/billing/gateways/cc5.rb +198 -0
  53. data/lib/active_merchant/billing/gateways/cecabank.rb +249 -0
  54. data/lib/active_merchant/billing/gateways/cenpos.rb +328 -0
  55. data/lib/active_merchant/billing/gateways/checkout.rb +212 -0
  56. data/lib/active_merchant/billing/gateways/checkout_v2.rb +587 -0
  57. data/lib/active_merchant/billing/gateways/citrus_pay.rb +21 -0
  58. data/lib/active_merchant/billing/gateways/clearhaus.rb +219 -0
  59. data/lib/active_merchant/billing/gateways/commerce_hub.rb +366 -0
  60. data/lib/active_merchant/billing/gateways/commercegate.rb +142 -0
  61. data/lib/active_merchant/billing/gateways/conekta.rb +230 -0
  62. data/lib/active_merchant/billing/gateways/creditcall.rb +272 -0
  63. data/lib/active_merchant/billing/gateways/credorax.rb +526 -0
  64. data/lib/active_merchant/billing/gateways/ct_payment.rb +269 -0
  65. data/lib/active_merchant/billing/gateways/culqi.rb +279 -0
  66. data/lib/active_merchant/billing/gateways/cyber_source/cyber_source_common.rb +36 -0
  67. data/lib/active_merchant/billing/gateways/cyber_source.rb +1148 -0
  68. data/lib/active_merchant/billing/gateways/cyber_source_rest.rb +454 -0
  69. data/lib/active_merchant/billing/gateways/d_local.rb +343 -0
  70. data/lib/active_merchant/billing/gateways/data_cash.rb +302 -0
  71. data/lib/active_merchant/billing/gateways/decidir.rb +358 -0
  72. data/lib/active_merchant/billing/gateways/decidir_plus.rb +344 -0
  73. data/lib/active_merchant/billing/gateways/dibs.rb +199 -0
  74. data/lib/active_merchant/billing/gateways/digitzs.rb +295 -0
  75. data/lib/active_merchant/billing/gateways/ebanx.rb +346 -0
  76. data/lib/active_merchant/billing/gateways/efsnet.rb +215 -0
  77. data/lib/active_merchant/billing/gateways/elavon.rb +475 -0
  78. data/lib/active_merchant/billing/gateways/element.rb +406 -0
  79. data/lib/active_merchant/billing/gateways/epay.rb +296 -0
  80. data/lib/active_merchant/billing/gateways/evo_ca.rb +307 -0
  81. data/lib/active_merchant/billing/gateways/eway.rb +226 -0
  82. data/lib/active_merchant/billing/gateways/eway_managed.rb +289 -0
  83. data/lib/active_merchant/billing/gateways/eway_rapid.rb +578 -0
  84. data/lib/active_merchant/billing/gateways/exact.rb +219 -0
  85. data/lib/active_merchant/billing/gateways/ezic.rb +195 -0
  86. data/lib/active_merchant/billing/gateways/fat_zebra.rb +223 -0
  87. data/lib/active_merchant/billing/gateways/federated_canada.rb +158 -0
  88. data/lib/active_merchant/billing/gateways/finansbank.rb +22 -0
  89. data/lib/active_merchant/billing/gateways/first_giving.rb +143 -0
  90. data/lib/active_merchant/billing/gateways/first_pay.rb +182 -0
  91. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +452 -0
  92. data/lib/active_merchant/billing/gateways/firstdata_e4_v27.rb +505 -0
  93. data/lib/active_merchant/billing/gateways/flo2cash.rb +215 -0
  94. data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +20 -0
  95. data/lib/active_merchant/billing/gateways/fluidpay.rb +275 -0
  96. data/lib/active_merchant/billing/gateways/forte.rb +286 -0
  97. data/lib/active_merchant/billing/gateways/garanti.rb +256 -0
  98. data/lib/active_merchant/billing/gateways/global_collect.rb +580 -0
  99. data/lib/active_merchant/billing/gateways/global_transport.rb +193 -0
  100. data/lib/active_merchant/billing/gateways/hdfc.rb +205 -0
  101. data/lib/active_merchant/billing/gateways/hps.rb +472 -0
  102. data/lib/active_merchant/billing/gateways/iats_payments.rb +312 -0
  103. data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +15 -0
  104. data/lib/active_merchant/billing/gateways/inspire.rb +213 -0
  105. data/lib/active_merchant/billing/gateways/instapay.rb +159 -0
  106. data/lib/active_merchant/billing/gateways/ipg.rb +420 -0
  107. data/lib/active_merchant/billing/gateways/ipp.rb +176 -0
  108. data/lib/active_merchant/billing/gateways/iridium.rb +467 -0
  109. data/lib/active_merchant/billing/gateways/itransact.rb +448 -0
  110. data/lib/active_merchant/billing/gateways/iveri.rb +290 -0
  111. data/lib/active_merchant/billing/gateways/ixopay.rb +320 -0
  112. data/lib/active_merchant/billing/gateways/jetpay.rb +395 -0
  113. data/lib/active_merchant/billing/gateways/jetpay_v2.rb +432 -0
  114. data/lib/active_merchant/billing/gateways/klarna.rb +317 -0
  115. data/lib/active_merchant/billing/gateways/komoju.rb +115 -0
  116. data/lib/active_merchant/billing/gateways/kushki.rb +297 -0
  117. data/lib/active_merchant/billing/gateways/latitude19.rb +412 -0
  118. data/lib/active_merchant/billing/gateways/linkpoint.rb +448 -0
  119. data/lib/active_merchant/billing/gateways/litle.rb +643 -0
  120. data/lib/active_merchant/billing/gateways/mastercard.rb +286 -0
  121. data/lib/active_merchant/billing/gateways/maxipago.rb +220 -0
  122. data/lib/active_merchant/billing/gateways/mercado_pago.rb +348 -0
  123. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +228 -0
  124. data/lib/active_merchant/billing/gateways/merchant_one.rb +110 -0
  125. data/lib/active_merchant/billing/gateways/merchant_partners.rb +245 -0
  126. data/lib/active_merchant/billing/gateways/merchant_ware.rb +313 -0
  127. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +284 -0
  128. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +248 -0
  129. data/lib/active_merchant/billing/gateways/mercury.rb +352 -0
  130. data/lib/active_merchant/billing/gateways/metrics_global.rb +293 -0
  131. data/lib/active_merchant/billing/gateways/micropayment.rb +182 -0
  132. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  133. data/lib/active_merchant/billing/gateways/migs.rb +329 -0
  134. data/lib/active_merchant/billing/gateways/mit.rb +260 -0
  135. data/lib/active_merchant/billing/gateways/modern_payments.rb +37 -0
  136. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +215 -0
  137. data/lib/active_merchant/billing/gateways/moka.rb +290 -0
  138. data/lib/active_merchant/billing/gateways/monei.rb +424 -0
  139. data/lib/active_merchant/billing/gateways/moneris.rb +488 -0
  140. data/lib/active_merchant/billing/gateways/money_movers.rb +150 -0
  141. data/lib/active_merchant/billing/gateways/mundipagg.rb +366 -0
  142. data/lib/active_merchant/billing/gateways/nab_transact.rb +299 -0
  143. data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +163 -0
  144. data/lib/active_merchant/billing/gateways/net_registry.rb +198 -0
  145. data/lib/active_merchant/billing/gateways/netaxept.rb +180 -0
  146. data/lib/active_merchant/billing/gateways/netbanx.rb +376 -0
  147. data/lib/active_merchant/billing/gateways/netbilling.rb +229 -0
  148. data/lib/active_merchant/billing/gateways/netpay.rb +223 -0
  149. data/lib/active_merchant/billing/gateways/network_merchants.rb +238 -0
  150. data/lib/active_merchant/billing/gateways/nmi.rb +396 -0
  151. data/lib/active_merchant/billing/gateways/ogone.rb +509 -0
  152. data/lib/active_merchant/billing/gateways/omise.rb +323 -0
  153. data/lib/active_merchant/billing/gateways/openpay.rb +246 -0
  154. data/lib/active_merchant/billing/gateways/opp.rb +394 -0
  155. data/lib/active_merchant/billing/gateways/optimal_payment.rb +331 -0
  156. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +45 -0
  157. data/lib/active_merchant/billing/gateways/orbital.rb +1267 -0
  158. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +206 -0
  159. data/lib/active_merchant/billing/gateways/pagarme.rb +239 -0
  160. data/lib/active_merchant/billing/gateways/pago_facil.rb +120 -0
  161. data/lib/active_merchant/billing/gateways/pay_arc.rb +392 -0
  162. data/lib/active_merchant/billing/gateways/pay_conex.rb +245 -0
  163. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +277 -0
  164. data/lib/active_merchant/billing/gateways/pay_hub.rb +213 -0
  165. data/lib/active_merchant/billing/gateways/pay_junction.rb +390 -0
  166. data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +206 -0
  167. data/lib/active_merchant/billing/gateways/pay_secure.rb +110 -0
  168. data/lib/active_merchant/billing/gateways/pay_trace.rb +450 -0
  169. data/lib/active_merchant/billing/gateways/paybox_direct.rb +224 -0
  170. data/lib/active_merchant/billing/gateways/payeezy.rb +513 -0
  171. data/lib/active_merchant/billing/gateways/payex.rb +409 -0
  172. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +235 -0
  173. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +42 -0
  174. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  175. data/lib/active_merchant/billing/gateways/payflow.rb +473 -0
  176. data/lib/active_merchant/billing/gateways/payflow_express.rb +220 -0
  177. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +14 -0
  178. data/lib/active_merchant/billing/gateways/payflow_uk.rb +20 -0
  179. data/lib/active_merchant/billing/gateways/payment_express.rb +373 -0
  180. data/lib/active_merchant/billing/gateways/paymentez.rb +365 -0
  181. data/lib/active_merchant/billing/gateways/paymill.rb +369 -0
  182. data/lib/active_merchant/billing/gateways/paynetworx.rb +227 -0
  183. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +718 -0
  184. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +69 -0
  185. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +262 -0
  186. data/lib/active_merchant/billing/gateways/paypal.rb +136 -0
  187. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  188. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +44 -0
  189. data/lib/active_merchant/billing/gateways/paypal_express.rb +272 -0
  190. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  191. data/lib/active_merchant/billing/gateways/paypal_standard.rb +281 -0
  192. data/lib/active_merchant/billing/gateways/paysafe.rb +420 -0
  193. data/lib/active_merchant/billing/gateways/payscout.rb +159 -0
  194. data/lib/active_merchant/billing/gateways/paystation.rb +204 -0
  195. data/lib/active_merchant/billing/gateways/payu_in.rb +249 -0
  196. data/lib/active_merchant/billing/gateways/payu_latam.rb +482 -0
  197. data/lib/active_merchant/billing/gateways/payway.rb +207 -0
  198. data/lib/active_merchant/billing/gateways/payway_dot_com.rb +253 -0
  199. data/lib/active_merchant/billing/gateways/pin.rb +273 -0
  200. data/lib/active_merchant/billing/gateways/pixxels.rb +263 -0
  201. data/lib/active_merchant/billing/gateways/plexo.rb +308 -0
  202. data/lib/active_merchant/billing/gateways/plugnpay.rb +283 -0
  203. data/lib/active_merchant/billing/gateways/priority.rb +392 -0
  204. data/lib/active_merchant/billing/gateways/pro_pay.rb +325 -0
  205. data/lib/active_merchant/billing/gateways/psigate.rb +227 -0
  206. data/lib/active_merchant/billing/gateways/psl_card.rb +295 -0
  207. data/lib/active_merchant/billing/gateways/qbms.rb +302 -0
  208. data/lib/active_merchant/billing/gateways/quantum.rb +274 -0
  209. data/lib/active_merchant/billing/gateways/quickbooks.rb +377 -0
  210. data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +184 -0
  211. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +297 -0
  212. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +226 -0
  213. data/lib/active_merchant/billing/gateways/quickpay.rb +24 -0
  214. data/lib/active_merchant/billing/gateways/qvalent.rb +305 -0
  215. data/lib/active_merchant/billing/gateways/rapyd.rb +319 -0
  216. data/lib/active_merchant/billing/gateways/reach.rb +277 -0
  217. data/lib/active_merchant/billing/gateways/realex.rb +400 -0
  218. data/lib/active_merchant/billing/gateways/redsys.rb +723 -0
  219. data/lib/active_merchant/billing/gateways/s5.rb +247 -0
  220. data/lib/active_merchant/billing/gateways/safe_charge.rb +298 -0
  221. data/lib/active_merchant/billing/gateways/sage.rb +446 -0
  222. data/lib/active_merchant/billing/gateways/sage_pay.rb +434 -0
  223. data/lib/active_merchant/billing/gateways/sallie_mae.rb +141 -0
  224. data/lib/active_merchant/billing/gateways/secure_net.rb +260 -0
  225. data/lib/active_merchant/billing/gateways/secure_pay.rb +191 -0
  226. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +290 -0
  227. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +103 -0
  228. data/lib/active_merchant/billing/gateways/securion_pay.rb +305 -0
  229. data/lib/active_merchant/billing/gateways/shift4.rb +345 -0
  230. data/lib/active_merchant/billing/gateways/simetrik.rb +368 -0
  231. data/lib/active_merchant/billing/gateways/skip_jack.rb +450 -0
  232. data/lib/active_merchant/billing/gateways/smart_ps.rb +274 -0
  233. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
  234. data/lib/active_merchant/billing/gateways/spreedly_core.rb +312 -0
  235. data/lib/active_merchant/billing/gateways/stripe.rb +866 -0
  236. data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +602 -0
  237. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +151 -0
  238. data/lib/active_merchant/billing/gateways/telr.rb +273 -0
  239. data/lib/active_merchant/billing/gateways/tns.rb +23 -0
  240. data/lib/active_merchant/billing/gateways/trans_first.rb +240 -0
  241. data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +612 -0
  242. data/lib/active_merchant/billing/gateways/transact_pro.rb +222 -0
  243. data/lib/active_merchant/billing/gateways/transax.rb +21 -0
  244. data/lib/active_merchant/billing/gateways/transnational.rb +9 -0
  245. data/lib/active_merchant/billing/gateways/trexle.rb +221 -0
  246. data/lib/active_merchant/billing/gateways/trust_commerce.rb +500 -0
  247. data/lib/active_merchant/billing/gateways/usa_epay.rb +24 -0
  248. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1612 -0
  249. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +367 -0
  250. data/lib/active_merchant/billing/gateways/vanco.rb +303 -0
  251. data/lib/active_merchant/billing/gateways/verifi.rb +224 -0
  252. data/lib/active_merchant/billing/gateways/viaklix.rb +171 -0
  253. data/lib/active_merchant/billing/gateways/visanet_peru.rb +250 -0
  254. data/lib/active_merchant/billing/gateways/vpos.rb +223 -0
  255. data/lib/active_merchant/billing/gateways/webpay.rb +97 -0
  256. data/lib/active_merchant/billing/gateways/wepay.rb +235 -0
  257. data/lib/active_merchant/billing/gateways/wirecard.rb +430 -0
  258. data/lib/active_merchant/billing/gateways/wompi.rb +197 -0
  259. data/lib/active_merchant/billing/gateways/world_net.rb +345 -0
  260. data/lib/active_merchant/billing/gateways/worldpay.rb +1050 -0
  261. data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +208 -0
  262. data/lib/active_merchant/billing/gateways/worldpay_us.rb +221 -0
  263. data/lib/active_merchant/billing/gateways.rb +14 -0
  264. data/lib/active_merchant/billing/model.rb +30 -0
  265. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +39 -0
  266. data/lib/active_merchant/billing/payment_token.rb +21 -0
  267. data/lib/active_merchant/billing/rails.rb +3 -0
  268. data/lib/active_merchant/billing/response.rb +120 -0
  269. data/lib/active_merchant/billing/three_d_secure_eci_mapper.rb +27 -0
  270. data/lib/active_merchant/billing.rb +16 -0
  271. data/lib/active_merchant/connection.rb +194 -0
  272. data/lib/active_merchant/country.rb +338 -0
  273. data/lib/active_merchant/empty.rb +20 -0
  274. data/lib/active_merchant/errors.rb +38 -0
  275. data/lib/active_merchant/net_http_ssl_connection.rb +11 -0
  276. data/lib/active_merchant/network_connection_retries.rb +78 -0
  277. data/lib/active_merchant/post_data.rb +26 -0
  278. data/lib/active_merchant/posts_data.rb +92 -0
  279. data/lib/active_merchant/version.rb +3 -0
  280. data/lib/active_merchant.rb +63 -0
  281. data/lib/activemerchant.rb +1 -0
  282. data/lib/certs/cacert.pem +3214 -0
  283. data/lib/support/gateway_support.rb +69 -0
  284. data/lib/support/outbound_hosts.rb +28 -0
  285. data/lib/support/ssl_verify.rb +88 -0
  286. data/lib/support/ssl_version.rb +86 -0
  287. metadata +506 -0
@@ -0,0 +1,277 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class ReachGateway < Gateway
4
+ self.test_url = 'https://checkout.rch.how/'
5
+ self.live_url = 'https://checkout.rch.io/'
6
+
7
+ self.supported_countries = ['US']
8
+ self.default_currency = 'USD'
9
+ self.supported_cardtypes = %i[visa diners_club american_express jcb master discover maestro]
10
+
11
+ self.homepage_url = 'https://www.withreach.com/'
12
+ self.display_name = 'Reach'
13
+ self.currencies_without_fractions = %w(BIF BYR CLF CLP CVE DJF GNF ISK JPY KMF KRW PYG RWF UGX UYI VND VUV XAF XOF XPF IDR MGA MRO)
14
+
15
+ API_VERSION = 'v2.22'.freeze
16
+ STANDARD_ERROR_CODE_MAPPING = {}
17
+ PAYMENT_METHOD_MAP = {
18
+ american_express: 'AMEX',
19
+ cabal: 'CABAL',
20
+ check: 'ACH',
21
+ dankort: 'DANKORT',
22
+ diners_club: 'DINERS',
23
+ discover: 'DISC',
24
+ elo: 'ELO',
25
+ jcb: 'JCB',
26
+ maestro: 'MAESTRO',
27
+ master: 'MC',
28
+ naranja: 'NARANJA',
29
+ union_pay: 'UNIONPAY',
30
+ visa: 'VISA'
31
+ }
32
+
33
+ def initialize(options = {})
34
+ requires!(options, :merchant_id, :secret)
35
+ super
36
+ end
37
+
38
+ def authorize(money, payment, options = {})
39
+ request = build_checkout_request(money, payment, options)
40
+ add_custom_fields_data(request, options)
41
+ add_customer_data(request, options, payment)
42
+ add_stored_credentials(request, options)
43
+ post = { request: request, card: add_payment(payment, options) }
44
+ if options[:stored_credential]
45
+ MultiResponse.run(:use_first_response) do |r|
46
+ r.process { commit('checkout', post) }
47
+ r.process do
48
+ r2 = get_network_payment_reference(r.responses[0])
49
+ r.params[:network_transaction_id] = r2.message
50
+ r2
51
+ end
52
+ end
53
+ else
54
+ commit('checkout', post)
55
+ end
56
+ end
57
+
58
+ def purchase(money, payment, options = {})
59
+ options[:capture] = true
60
+ authorize(money, payment, options)
61
+ end
62
+
63
+ def capture(money, authorization, options = {})
64
+ post = { request: { MerchantId: @options[:merchant_id], OrderId: authorization } }
65
+ commit('capture', post)
66
+ end
67
+
68
+ def supports_scrubbing?
69
+ true
70
+ end
71
+
72
+ def scrub(transcript)
73
+ transcript.
74
+ gsub(%r(((MerchantId)[% \w]+[%]\d{2})[\w -]+), '\1[FILTERED]').
75
+ gsub(%r((signature=)[\w%]+), '\1[FILTERED]\2').
76
+ gsub(%r((Number%22%3A%22)[\d]+), '\1[FILTERED]\2').
77
+ gsub(%r((VerificationCode%22%3A)[\d]+), '\1[FILTERED]\2')
78
+ end
79
+
80
+ def refund(amount, authorization, options = {})
81
+ currency = options[:currency] || currency(options[:amount])
82
+ post = {
83
+ request: {
84
+ MerchantId: @options[:merchant_id],
85
+ OrderId: authorization,
86
+ ReferenceId: options[:order_id] || options[:reference_id],
87
+ Amount: localized_amount(amount, currency)
88
+ }
89
+ }
90
+ commit('refund', post)
91
+ end
92
+
93
+ def void(authorization, options = {})
94
+ post = {
95
+ request: {
96
+ MerchantId: @options[:merchant_id],
97
+ OrderId: authorization
98
+ }
99
+ }
100
+
101
+ commit('cancel', post)
102
+ end
103
+
104
+ def verify(credit_card, options = {})
105
+ MultiResponse.run(:use_first_response) do |r|
106
+ r.process { authorize(100, credit_card, options) }
107
+ r.process(:ignore_result) { void(r.authorization, options) }
108
+ end
109
+ end
110
+
111
+ private
112
+
113
+ def build_checkout_request(amount, payment, options)
114
+ currency = options[:currency] || currency(options[:amount])
115
+ {
116
+ MerchantId: @options[:merchant_id],
117
+ ReferenceId: options[:order_id],
118
+ ConsumerCurrency: currency,
119
+ Capture: options[:capture] || false,
120
+ PaymentMethod: PAYMENT_METHOD_MAP.fetch(payment.brand.to_sym, 'unsupported'),
121
+ Items: [
122
+ Sku: options[:item_sku] || SecureRandom.alphanumeric,
123
+ ConsumerPrice: localized_amount(amount, currency),
124
+ Quantity: (options[:item_quantity] || 1)
125
+ ]
126
+ }
127
+ end
128
+
129
+ def add_payment(payment, options)
130
+ ntid = options.dig(:stored_credential, :network_transaction_id)
131
+ cvv_or_previos_reference = (ntid ? { PreviousNetworkPaymentReference: ntid } : { VerificationCode: payment.verification_value })
132
+ {
133
+ Name: payment.name,
134
+ Number: payment.number,
135
+ Expiry: { Month: payment.month, Year: payment.year }
136
+ }.merge!(cvv_or_previos_reference)
137
+ end
138
+
139
+ def add_customer_data(request, options, payment)
140
+ address = options[:billing_address] || options[:address]
141
+
142
+ return if address.blank?
143
+
144
+ request[:Consumer] = {
145
+ Name: payment.respond_to?(:name) ? payment.name : address[:name],
146
+ Email: options[:email],
147
+ Address: address[:address1],
148
+ City: address[:city],
149
+ Country: address[:country]
150
+ }.compact
151
+ end
152
+
153
+ def add_stored_credentials(request, options)
154
+ request[:PaymentModel] = payment_model(options) || ''
155
+ request[:DeviceFingerprint] = options[:device_fingerprint] if options[:device_fingerprint]
156
+ end
157
+
158
+ def payment_model(options)
159
+ stored_credential = options[:stored_credential]
160
+ return options[:payment_model] if options[:payment_model]
161
+ return 'CIT-One-Time' unless stored_credential
162
+
163
+ payment_model_options = {
164
+ initial_transaction: {
165
+ 'cardholder' => {
166
+ 'installment' => 'CIT-Setup-Scheduled',
167
+ 'unscheduled' => 'CIT-Setup-Unscheduled-MIT',
168
+ 'recurring' => 'CIT-Setup-Unscheduled'
169
+ }
170
+ },
171
+ no_initial_transaction: {
172
+ 'cardholder' => {
173
+ 'unscheduled' => 'CIT-Subsequent-Unscheduled'
174
+ },
175
+ 'merchant' => {
176
+ 'recurring' => 'MIT-Subsequent-Scheduled',
177
+ 'unscheduled' => 'MIT-Subsequent-Unscheduled'
178
+ }
179
+ }
180
+ }
181
+ initial = stored_credential[:initial_transaction] ? :initial_transaction : :no_initial_transaction
182
+ payment_model_options[initial].dig(stored_credential[:initiator], stored_credential[:reason_type])
183
+ end
184
+
185
+ def add_custom_fields_data(request, options)
186
+ add_shipping_data(request, options) if options[:taxes].present?
187
+ request[:RateOfferId] = options[:rate_offer_id] if options[:rate_offer_id].present?
188
+ request[:Items] = options[:items] if options[:items].present?
189
+ end
190
+
191
+ def add_shipping_data(request, options)
192
+ request[:Shipping] = {
193
+ ConsumerPrice: options[:price],
194
+ ConsumerTaxes: options[:taxes],
195
+ ConsumerDuty: options[:duty]
196
+ }
197
+ request[:Consignee] = {
198
+ Name: options[:consignee_name],
199
+ Address: options[:consignee_address],
200
+ City: options[:consignee_city],
201
+ Country: options[:consignee_country]
202
+ }
203
+ end
204
+
205
+ def sign_body(body)
206
+ Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', @options[:secret].encode('utf-8'), body.encode('utf-8')))
207
+ end
208
+
209
+ def parse(body)
210
+ hash_response = URI.decode_www_form(body).to_h
211
+ hash_response['response'] = JSON.parse(hash_response['response'])
212
+
213
+ hash_response
214
+ end
215
+
216
+ def format_and_sign(post)
217
+ post[:request] = post[:request].to_json
218
+ post[:card] = post[:card].to_json if post[:card].present?
219
+ post[:signature] = sign_body(post[:request])
220
+ post
221
+ end
222
+
223
+ def get_network_payment_reference(response)
224
+ parameters = { request: { MerchantId: @options[:merchant_id], OrderId: response.params['response']['OrderId'] } }
225
+ body = post_data format_and_sign(parameters)
226
+
227
+ raw_response = ssl_request :post, url('query'), body, {}
228
+ response = parse(raw_response)
229
+ message = response.dig('response', 'Payment', 'NetworkPaymentReference')
230
+ Response.new(true, message, {})
231
+ end
232
+
233
+ def commit(action, parameters)
234
+ body = post_data format_and_sign(parameters)
235
+ raw_response = ssl_post url(action), body
236
+ response = parse(raw_response)
237
+
238
+ Response.new(
239
+ success_from(response),
240
+ message_from(response) || '',
241
+ response,
242
+ authorization: authorization_from(response['response']),
243
+ # avs_result: AVSResult.new(code: response['some_avs_response_key']),
244
+ # cvv_result: CVVResult.new(response['some_cvv_response_key']),
245
+ test: test?,
246
+ error_code: error_code_from(response)
247
+ )
248
+ rescue ActiveMerchant::ResponseError => e
249
+ Response.new(false, (e.response.body.present? ? e.response.body : e.response.msg), {}, test: test?)
250
+ end
251
+
252
+ def success_from(response)
253
+ response.dig('response', 'Error').blank?
254
+ end
255
+
256
+ def message_from(response)
257
+ success_from(response) ? '' : response.dig('response', 'Error', 'ReasonCode')
258
+ end
259
+
260
+ def authorization_from(response)
261
+ response['OrderId']
262
+ end
263
+
264
+ def post_data(params)
265
+ params.map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&')
266
+ end
267
+
268
+ def error_code_from(response)
269
+ response['response']['Error']['Code'] unless success_from(response)
270
+ end
271
+
272
+ def url(action)
273
+ "#{test? ? test_url : live_url}#{API_VERSION}/#{action}"
274
+ end
275
+ end
276
+ end
277
+ end
@@ -0,0 +1,400 @@
1
+ require 'nokogiri'
2
+ require 'digest/sha1'
3
+
4
+ module ActiveMerchant
5
+ module Billing
6
+ # Realex is the leading CC gateway in Ireland
7
+ # see http://www.realexpayments.com
8
+ # Contributed by John Ward (john@ward.name)
9
+ # see http://thinedgeofthewedge.blogspot.com
10
+ #
11
+ # Realex works using the following
12
+ # login - The unique id of the merchant
13
+ # password - The secret is used to digitally sign the request
14
+ # account - This is an optional third part of the authentication process
15
+ # and is used if the merchant wishes do distinguish cc traffic from the different sources
16
+ # by using a different account. This must be created in advance
17
+ #
18
+ # the Realex team decided to make the orderid unique per request,
19
+ # so if validation fails you can not correct and resend using the
20
+ # same order id
21
+ class RealexGateway < Gateway
22
+ self.live_url = self.test_url = 'https://epage.payandshop.com/epage-remote.cgi'
23
+
24
+ CARD_MAPPING = {
25
+ 'master' => 'MC',
26
+ 'visa' => 'VISA',
27
+ 'american_express' => 'AMEX',
28
+ 'diners_club' => 'DINERS',
29
+ 'maestro' => 'MC'
30
+ }
31
+
32
+ self.money_format = :cents
33
+ self.default_currency = 'EUR'
34
+ self.supported_cardtypes = %i[visa master american_express diners_club]
35
+ self.supported_countries = %w(IE GB FR BE NL LU IT US CA ES)
36
+ self.homepage_url = 'http://www.realexpayments.com/'
37
+ self.display_name = 'Realex'
38
+
39
+ SUCCESS, DECLINED = 'Successful', 'Declined'
40
+ BANK_ERROR = REALEX_ERROR = 'Gateway is in maintenance. Please try again later.'
41
+ ERROR = CLIENT_DEACTIVATED = 'Gateway Error'
42
+
43
+ def initialize(options = {})
44
+ requires!(options, :login, :password)
45
+ options[:refund_hash] = Digest::SHA1.hexdigest(options[:rebate_secret]) if options[:rebate_secret].present?
46
+ options[:credit_hash] = Digest::SHA1.hexdigest(options[:refund_secret]) if options[:refund_secret].present?
47
+ super
48
+ end
49
+
50
+ def purchase(money, credit_card, options = {})
51
+ requires!(options, :order_id)
52
+
53
+ request = build_purchase_or_authorization_request(:purchase, money, credit_card, options)
54
+ commit(request)
55
+ end
56
+
57
+ def authorize(money, creditcard, options = {})
58
+ requires!(options, :order_id)
59
+
60
+ request = build_purchase_or_authorization_request(:authorization, money, creditcard, options)
61
+ commit(request)
62
+ end
63
+
64
+ def capture(money, authorization, options = {})
65
+ request = build_capture_request(money, authorization, options)
66
+ commit(request)
67
+ end
68
+
69
+ def refund(money, authorization, options = {})
70
+ request = build_refund_request(money, authorization, options)
71
+ commit(request)
72
+ end
73
+
74
+ def credit(money, creditcard, options = {})
75
+ request = build_credit_request(money, creditcard, options)
76
+ commit(request)
77
+ end
78
+
79
+ def void(authorization, options = {})
80
+ request = build_void_request(authorization, options)
81
+ commit(request)
82
+ end
83
+
84
+ def verify(credit_card, options = {})
85
+ requires!(options, :order_id)
86
+
87
+ request = build_verify_request(credit_card, options)
88
+ commit(request)
89
+ end
90
+
91
+ def supports_scrubbing
92
+ true
93
+ end
94
+
95
+ def scrub(transcript)
96
+ transcript.
97
+ gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
98
+ gsub(%r((<number>)\d+(</number>))i, '\1[FILTERED]\2')
99
+ end
100
+
101
+ private
102
+
103
+ def commit(request)
104
+ response = parse(ssl_post(self.live_url, request))
105
+
106
+ Response.new(
107
+ (response[:result] == '00'),
108
+ message_from(response),
109
+ response,
110
+ test: (response[:message] =~ %r{\[ test system \]}),
111
+ authorization: authorization_from(response),
112
+ avs_result: AVSResult.new(code: response[:avspostcoderesponse]),
113
+ cvv_result: CVVResult.new(response[:cvnresult])
114
+ )
115
+ end
116
+
117
+ def parse(xml)
118
+ response = {}
119
+
120
+ doc = Nokogiri::XML(xml)
121
+ doc.xpath('//response/*').each do |node|
122
+ if node.elements.size == 0
123
+ response[node.name.downcase.to_sym] = normalize(node.text)
124
+ else
125
+ node.elements.each do |childnode|
126
+ name = "#{node.name.downcase}_#{childnode.name.downcase}"
127
+ response[name.to_sym] = normalize(childnode.text)
128
+ end
129
+ end
130
+ end unless doc.root.nil?
131
+
132
+ response
133
+ end
134
+
135
+ def authorization_from(parsed)
136
+ [parsed[:orderid], parsed[:pasref], parsed[:authcode]].join(';')
137
+ end
138
+
139
+ def build_purchase_or_authorization_request(action, money, credit_card, options)
140
+ timestamp = new_timestamp
141
+ xml = Builder::XmlMarkup.new indent: 2
142
+ xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'auth' do
143
+ add_merchant_details(xml, options)
144
+ xml.tag! 'orderid', sanitize_order_id(options[:order_id])
145
+ add_amount(xml, money, options)
146
+ add_card(xml, credit_card)
147
+ xml.tag! 'autosettle', 'flag' => auto_settle_flag(action)
148
+ add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), amount(money), (options[:currency] || currency(money)), credit_card.number)
149
+ if credit_card.is_a?(NetworkTokenizationCreditCard)
150
+ add_network_tokenization_card(xml, credit_card)
151
+ else
152
+ add_three_d_secure(xml, options)
153
+ end
154
+ add_stored_credential(xml, options)
155
+ add_comments(xml, options)
156
+ add_address_and_customer_info(xml, options)
157
+ end
158
+ xml.target!
159
+ end
160
+
161
+ def build_capture_request(money, authorization, options)
162
+ timestamp = new_timestamp
163
+ xml = Builder::XmlMarkup.new indent: 2
164
+ xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'settle' do
165
+ add_merchant_details(xml, options)
166
+ add_amount(xml, money, options)
167
+ add_transaction_identifiers(xml, authorization, options)
168
+ add_comments(xml, options)
169
+ add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), amount(money), (options[:currency] || currency(money)), nil)
170
+ end
171
+ xml.target!
172
+ end
173
+
174
+ def build_refund_request(money, authorization, options)
175
+ timestamp = new_timestamp
176
+ xml = Builder::XmlMarkup.new indent: 2
177
+ xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'rebate' do
178
+ add_merchant_details(xml, options)
179
+ add_transaction_identifiers(xml, authorization, options)
180
+ xml.tag! 'amount', amount(money), 'currency' => options[:currency] || currency(money)
181
+ xml.tag! 'refundhash', @options[:refund_hash] if @options[:refund_hash]
182
+ xml.tag! 'autosettle', 'flag' => 1
183
+ add_comments(xml, options)
184
+ add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), amount(money), (options[:currency] || currency(money)), nil)
185
+ end
186
+ xml.target!
187
+ end
188
+
189
+ def build_credit_request(money, credit_card, options)
190
+ timestamp = new_timestamp
191
+ xml = Builder::XmlMarkup.new indent: 2
192
+ xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'credit' do
193
+ add_merchant_details(xml, options)
194
+ xml.tag! 'orderid', sanitize_order_id(options[:order_id])
195
+ add_amount(xml, money, options)
196
+ add_card(xml, credit_card)
197
+ xml.tag! 'refundhash', @options[:credit_hash] if @options[:credit_hash]
198
+ xml.tag! 'autosettle', 'flag' => 1
199
+ add_comments(xml, options)
200
+ add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), amount(money), (options[:currency] || currency(money)), credit_card.number)
201
+ end
202
+ xml.target!
203
+ end
204
+
205
+ def build_void_request(authorization, options)
206
+ timestamp = new_timestamp
207
+ xml = Builder::XmlMarkup.new indent: 2
208
+ xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'void' do
209
+ add_merchant_details(xml, options)
210
+ add_transaction_identifiers(xml, authorization, options)
211
+ add_comments(xml, options)
212
+ add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), nil, nil, nil)
213
+ end
214
+ xml.target!
215
+ end
216
+
217
+ # Verify initiates an OTB (Open To Buy) request
218
+ def build_verify_request(credit_card, options)
219
+ timestamp = new_timestamp
220
+ xml = Builder::XmlMarkup.new indent: 2
221
+ xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'otb' do
222
+ add_merchant_details(xml, options)
223
+ xml.tag! 'orderid', sanitize_order_id(options[:order_id])
224
+ add_card(xml, credit_card)
225
+ add_comments(xml, options)
226
+ add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), credit_card.number)
227
+ end
228
+ xml.target!
229
+ end
230
+
231
+ def add_address_and_customer_info(xml, options)
232
+ billing_address = options[:billing_address] || options[:address]
233
+ shipping_address = options[:shipping_address]
234
+ ipv4_address = ipv4?(options[:ip]) ? options[:ip] : nil
235
+
236
+ return unless billing_address || shipping_address || options[:customer] || options[:invoice] || ipv4_address
237
+
238
+ xml.tag! 'tssinfo' do
239
+ xml.tag! 'custnum', options[:customer] if options[:customer]
240
+ xml.tag! 'prodid', options[:invoice] if options[:invoice]
241
+ xml.tag! 'custipaddress', options[:ip] if ipv4_address
242
+
243
+ if billing_address
244
+ xml.tag! 'address', 'type' => 'billing' do
245
+ xml.tag! 'code', format_address_code(billing_address)
246
+ xml.tag! 'country', billing_address[:country]
247
+ end
248
+ end
249
+
250
+ if shipping_address
251
+ xml.tag! 'address', 'type' => 'shipping' do
252
+ xml.tag! 'code', format_address_code(shipping_address)
253
+ xml.tag! 'country', shipping_address[:country]
254
+ end
255
+ end
256
+ end
257
+ end
258
+
259
+ def add_merchant_details(xml, options)
260
+ xml.tag! 'merchantid', @options[:login]
261
+ xml.tag! 'account', (options[:account] || @options[:account]) if options[:account] || @options[:account]
262
+ end
263
+
264
+ def add_transaction_identifiers(xml, authorization, options)
265
+ options[:order_id], pasref, authcode = authorization.split(';')
266
+ xml.tag! 'orderid', sanitize_order_id(options[:order_id])
267
+ xml.tag! 'pasref', pasref
268
+ xml.tag! 'authcode', authcode
269
+ end
270
+
271
+ def add_comments(xml, options)
272
+ return unless options[:description]
273
+
274
+ xml.tag! 'comments' do
275
+ xml.tag! 'comment', options[:description], 'id' => 1
276
+ end
277
+ end
278
+
279
+ def add_amount(xml, money, options)
280
+ xml.tag! 'amount', amount(money), 'currency' => options[:currency] || currency(money)
281
+ end
282
+
283
+ def add_card(xml, credit_card)
284
+ xml.tag! 'card' do
285
+ xml.tag! 'number', credit_card.number
286
+ xml.tag! 'expdate', expiry_date(credit_card)
287
+ xml.tag! 'chname', credit_card.name
288
+ xml.tag! 'type', CARD_MAPPING[card_brand(credit_card).to_s]
289
+ xml.tag! 'issueno', ''
290
+ xml.tag! 'cvn' do
291
+ xml.tag! 'number', credit_card.verification_value
292
+ xml.tag! 'presind', (options['presind'] || (credit_card.verification_value? ? 1 : nil))
293
+ end
294
+ end
295
+ end
296
+
297
+ def add_network_tokenization_card(xml, payment)
298
+ xml.tag! 'mpi' do
299
+ xml.tag! 'cavv', payment.payment_cryptogram
300
+ xml.tag! 'eci', payment.eci
301
+ end
302
+ xml.tag! 'supplementarydata' do
303
+ xml.tag! 'item', 'type' => 'mobile' do
304
+ xml.tag! 'field01', payment.source.to_s.tr('_', '-')
305
+ end
306
+ end
307
+ end
308
+
309
+ def add_three_d_secure(xml, options)
310
+ return unless three_d_secure = options[:three_d_secure]
311
+
312
+ version = three_d_secure.fetch(:version, '')
313
+ xml.tag! 'mpi' do
314
+ if /^2/.match?(version)
315
+ xml.tag! 'authentication_value', three_d_secure[:cavv]
316
+ xml.tag! 'ds_trans_id', three_d_secure[:ds_transaction_id]
317
+ else
318
+ xml.tag! 'cavv', three_d_secure[:cavv]
319
+ xml.tag! 'xid', three_d_secure[:xid]
320
+ version = '1'
321
+ end
322
+ xml.tag! 'eci', three_d_secure[:eci]
323
+ xml.tag! 'message_version', version
324
+ end
325
+ end
326
+
327
+ def add_stored_credential(xml, options)
328
+ return unless stored_credential = options[:stored_credential]
329
+
330
+ xml.tag! 'storedcredential' do
331
+ xml.tag! 'type', stored_credential_type(stored_credential[:reason_type])
332
+ xml.tag! 'initiator', stored_credential[:initiator]
333
+ xml.tag! 'sequence', stored_credential[:initial_transaction] ? 'first' : 'subsequent'
334
+ xml.tag! 'srd', stored_credential[:network_transaction_id]
335
+ end
336
+ end
337
+
338
+ def stored_credential_type(reason)
339
+ return 'oneoff' if reason == 'unscheduled'
340
+
341
+ reason
342
+ end
343
+
344
+ def format_address_code(address)
345
+ code = [address[:zip].to_s, address[:address1].to_s + address[:address2].to_s]
346
+ code.collect { |e| e.gsub(/\D/, '') }.reject(&:empty?).join('|')
347
+ end
348
+
349
+ def new_timestamp
350
+ Time.now.strftime('%Y%m%d%H%M%S')
351
+ end
352
+
353
+ def add_signed_digest(xml, *values)
354
+ string = Digest::SHA1.hexdigest(values.join('.'))
355
+ xml.tag! 'sha1hash', Digest::SHA1.hexdigest([string, @options[:password]].join('.'))
356
+ end
357
+
358
+ def auto_settle_flag(action)
359
+ action == :authorization ? '0' : '1'
360
+ end
361
+
362
+ def expiry_date(credit_card)
363
+ "#{format(credit_card.month, :two_digits)}#{format(credit_card.year, :two_digits)}"
364
+ end
365
+
366
+ def message_from(response)
367
+ case response[:result]
368
+ when '00'
369
+ SUCCESS
370
+ when '101'
371
+ response[:message]
372
+ when '102', '103'
373
+ DECLINED
374
+ when /^2[0-9][0-9]/
375
+ BANK_ERROR
376
+ when /^3[0-9][0-9]/
377
+ REALEX_ERROR
378
+ when /^5[0-9][0-9]/
379
+ response[:message]
380
+ when '600', '601', '603'
381
+ ERROR
382
+ when '666'
383
+ CLIENT_DEACTIVATED
384
+ else
385
+ DECLINED
386
+ end
387
+ end
388
+
389
+ def sanitize_order_id(order_id)
390
+ order_id.to_s.gsub(/[^a-zA-Z0-9\-_]/, '')
391
+ end
392
+
393
+ def ipv4?(ip_address)
394
+ return false if ip_address.nil?
395
+
396
+ !ip_address.match(/\A\d+\.\d+\.\d+\.\d+\z/).nil?
397
+ end
398
+ end
399
+ end
400
+ end