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,482 @@
1
+ require 'digest/md5'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class PayuLatamGateway < Gateway
6
+ self.display_name = 'PayU Latam'
7
+ self.homepage_url = 'http://www.payulatam.com'
8
+
9
+ self.test_url = 'https://sandbox.api.payulatam.com/payments-api/4.0/service.cgi'
10
+ self.live_url = 'https://api.payulatam.com/payments-api/4.0/service.cgi'
11
+
12
+ self.supported_countries = %w[AR BR CL CO MX PA PE]
13
+ self.default_currency = 'USD'
14
+ self.money_format = :dollars
15
+ self.supported_cardtypes = %i[visa master american_express diners_club naranja cabal]
16
+
17
+ BRAND_MAP = {
18
+ 'visa' => 'VISA',
19
+ 'master' => 'MASTERCARD',
20
+ 'maestro' => 'MASTERCARD',
21
+ 'american_express' => 'AMEX',
22
+ 'diners_club' => 'DINERS',
23
+ 'naranja' => 'NARANJA',
24
+ 'cabal' => 'CABAL'
25
+ }
26
+
27
+ MINIMUMS = {
28
+ 'ARS' => 1700,
29
+ 'BRL' => 600,
30
+ 'MXN' => 3900,
31
+ 'PEN' => 500
32
+ }
33
+
34
+ def initialize(options = {})
35
+ requires!(options, :merchant_id, :account_id, :api_login, :api_key, :payment_country)
36
+ super
37
+ end
38
+
39
+ def purchase(amount, payment_method, options = {})
40
+ post = {}
41
+ auth_or_sale(post, 'AUTHORIZATION_AND_CAPTURE', amount, payment_method, options)
42
+ commit('purchase', post)
43
+ end
44
+
45
+ def authorize(amount, payment_method, options = {})
46
+ post = {}
47
+ auth_or_sale(post, 'AUTHORIZATION', amount, payment_method, options)
48
+ commit('auth', post)
49
+ end
50
+
51
+ def capture(amount, authorization, options = {})
52
+ post = {}
53
+
54
+ add_credentials(post, 'SUBMIT_TRANSACTION', options)
55
+ add_transaction_elements(post, 'CAPTURE', options)
56
+ add_reference(post, authorization)
57
+
58
+ if !amount.nil? && amount.to_f != 0.0
59
+ post[:transaction][:additionalValues] ||= {}
60
+ post[:transaction][:additionalValues][:TX_VALUE] = invoice_for(amount, options)[:TX_VALUE]
61
+ end
62
+
63
+ commit('capture', post)
64
+ end
65
+
66
+ def void(authorization, options = {})
67
+ post = {}
68
+
69
+ add_credentials(post, 'SUBMIT_TRANSACTION', options)
70
+ add_transaction_elements(post, 'VOID', options)
71
+ add_reference(post, authorization)
72
+
73
+ commit('void', post)
74
+ end
75
+
76
+ def refund(amount, authorization, options = {})
77
+ post = {}
78
+
79
+ add_credentials(post, 'SUBMIT_TRANSACTION', options)
80
+
81
+ if options[:partial_refund]
82
+ add_transaction_elements(post, 'PARTIAL_REFUND', options)
83
+ post[:transaction][:additionalValues] ||= {}
84
+ post[:transaction][:additionalValues][:TX_VALUE] = invoice_for(amount, options)[:TX_VALUE]
85
+ else
86
+ add_transaction_elements(post, 'REFUND', options)
87
+ end
88
+
89
+ add_reference(post, authorization)
90
+ commit('refund', post)
91
+ end
92
+
93
+ def verify(credit_card, options = {})
94
+ minimum = MINIMUMS[options[:currency].upcase] if options[:currency]
95
+ amount = options[:verify_amount] || minimum || 100
96
+
97
+ MultiResponse.run(:use_first_response) do |r|
98
+ r.process { authorize(amount, credit_card, options) }
99
+ r.process(:ignore_result) { void(r.authorization, options) }
100
+ end
101
+ end
102
+
103
+ def store(payment_method, options = {})
104
+ post = {}
105
+
106
+ add_credentials(post, 'CREATE_TOKEN')
107
+ add_payment_method_to_be_tokenized(post, payment_method, options)
108
+
109
+ commit('store', post)
110
+ end
111
+
112
+ def verify_credentials
113
+ post = {}
114
+ add_credentials(post, 'GET_PAYMENT_METHODS')
115
+ response = commit('verify_credentials', post)
116
+ response.success?
117
+ end
118
+
119
+ def supports_scrubbing?
120
+ true
121
+ end
122
+
123
+ def scrub(transcript)
124
+ transcript.
125
+ gsub(%r((\"creditCard\\\":{\\\"number\\\":\\\")\d+), '\1[FILTERED]').
126
+ gsub(%r((\"securityCode\\\":\\\")\d+), '\1[FILTERED]').
127
+ gsub(%r((\"apiKey\\\":\\\")\w+), '\1[FILTERED]')
128
+ end
129
+
130
+ private
131
+
132
+ def auth_or_sale(post, transaction_type, amount, payment_method, options)
133
+ add_credentials(post, 'SUBMIT_TRANSACTION', options)
134
+ add_transaction_elements(post, transaction_type, options)
135
+ add_order(post, options)
136
+ add_buyer(post, payment_method, options)
137
+ add_invoice(post, amount, options)
138
+ add_signature(post)
139
+ add_payment_method(post, payment_method, options)
140
+ add_payer(post, payment_method, options)
141
+ add_extra_parameters(post, options)
142
+ end
143
+
144
+ def add_credentials(post, command, options = {})
145
+ post[:test] = test? unless command == 'CREATE_TOKEN'
146
+ post[:language] = options[:language] || 'en'
147
+ post[:command] = command
148
+ merchant = {}
149
+ merchant[:apiLogin] = @options[:api_login]
150
+ merchant[:apiKey] = @options[:api_key]
151
+ post[:merchant] = merchant
152
+ end
153
+
154
+ def add_transaction_elements(post, type, options)
155
+ transaction = {}
156
+ transaction[:paymentCountry] = @options[:payment_country]
157
+ transaction[:type] = type
158
+ transaction[:ipAddress] = options[:ip] || ''
159
+ transaction[:userAgent] = options[:user_agent] if options[:user_agent]
160
+ transaction[:cookie] = options[:cookie] if options[:cookie]
161
+ transaction[:deviceSessionId] = options[:device_session_id] if options[:device_session_id]
162
+ post[:transaction] = transaction
163
+ end
164
+
165
+ def add_order(post, options)
166
+ order = {}
167
+ order[:accountId] = @options[:account_id]
168
+ order[:partnerId] = options[:partner_id] if options[:partner_id]
169
+ order[:referenceCode] = options[:order_id] || generate_unique_id
170
+ order[:description] = options[:description] || 'Compra en ' + @options[:merchant_id]
171
+ order[:language] = options[:language] || 'en'
172
+ order[:shippingAddress] = shipping_address_fields(options) if options[:shipping_address]
173
+ post[:transaction][:order] = order
174
+ end
175
+
176
+ def add_payer(post, payment_method, options)
177
+ address = options[:billing_address]
178
+ payer = {}
179
+ payer[:fullName] = payment_method.name.strip
180
+ payer[:contactPhone] = address[:phone] if address && address[:phone]
181
+ payer[:dniNumber] = options[:dni_number] if options[:dni_number]
182
+ payer[:dniType] = options[:dni_type] if options[:dni_type]
183
+ payer[:emailAddress] = options[:email] if options[:email]
184
+ payer[:birthdate] = options[:birth_date] if options[:birth_date] && @options[:payment_country] == 'MX'
185
+ payer[:billingAddress] = billing_address_fields(options)
186
+ post[:transaction][:payer] = payer
187
+ end
188
+
189
+ def billing_address_fields(options)
190
+ return unless address = options[:billing_address]
191
+
192
+ billing_address = {}
193
+ billing_address[:street1] = address[:address1]
194
+ billing_address[:street2] = address[:address2]
195
+ billing_address[:city] = address[:city]
196
+ billing_address[:state] = address[:state]
197
+ billing_address[:country] = address[:country] unless address[:country].blank?
198
+ billing_address[:postalCode] = address[:zip] if @options[:payment_country] == 'MX'
199
+ billing_address[:phone] = address[:phone]
200
+ billing_address
201
+ end
202
+
203
+ def add_buyer(post, payment_method, options)
204
+ buyer = {}
205
+ if buyer_hash = options[:buyer]
206
+ buyer[:fullName] = buyer_hash[:name]
207
+ buyer[:dniNumber] = buyer_hash[:dni_number]
208
+ buyer[:dniType] = buyer_hash[:dni_type]
209
+ buyer[:merchantBuyerId] = buyer_hash[:merchant_buyer_id]
210
+ buyer[:cnpj] = buyer_hash[:cnpj] if @options[:payment_country] == 'BR'
211
+ buyer[:emailAddress] = buyer_hash[:email]
212
+ buyer[:contactPhone] = (options[:billing_address][:phone] if options[:billing_address]) || (options[:shipping_address][:phone_number] if options[:shipping_address]) || ''
213
+ buyer[:shippingAddress] = shipping_address_fields(options) if options[:shipping_address]
214
+ else
215
+ buyer[:fullName] = payment_method.name.strip
216
+ buyer[:dniNumber] = options[:dni_number]
217
+ buyer[:dniType] = options[:dni_type]
218
+ buyer[:merchantBuyerId] = options[:merchant_buyer_id]
219
+ buyer[:cnpj] = options[:cnpj] if @options[:payment_country] == 'BR'
220
+ buyer[:emailAddress] = options[:email]
221
+ buyer[:contactPhone] = (options[:billing_address][:phone] if options[:billing_address]) || (options[:shipping_address][:phone_number] if options[:shipping_address]) || ''
222
+ buyer[:shippingAddress] = shipping_address_fields(options) if options[:shipping_address]
223
+ end
224
+ post[:transaction][:order][:buyer] = buyer
225
+ end
226
+
227
+ def shipping_address_fields(options)
228
+ return unless address = options[:shipping_address]
229
+
230
+ shipping_address = {}
231
+ shipping_address[:street1] = address[:address1]
232
+ shipping_address[:street2] = address[:address2]
233
+ shipping_address[:city] = address[:city]
234
+ shipping_address[:state] = address[:state]
235
+ shipping_address[:country] = address[:country]
236
+ shipping_address[:postalCode] = address[:zip]
237
+ shipping_address[:phone] = address[:phone_number]
238
+ shipping_address
239
+ end
240
+
241
+ def add_invoice(post, money, options)
242
+ post[:transaction][:order][:additionalValues] = invoice_for(money, options)
243
+ end
244
+
245
+ def invoice_for(money, options)
246
+ tx_value = {}
247
+ tx_value[:value] = amount(money)
248
+ tx_value[:currency] = options[:currency] || currency(money)
249
+
250
+ tx_tax = {}
251
+ tx_tax[:value] = options[:tax] || '0'
252
+ tx_tax[:currency] = options[:currency] || currency(money)
253
+
254
+ tx_tax_return_base = {}
255
+ tx_tax_return_base[:value] = options[:tax_return_base] || '0'
256
+ tx_tax_return_base[:currency] = options[:currency] || currency(money)
257
+
258
+ additional_values = {}
259
+ additional_values[:TX_VALUE] = tx_value
260
+ additional_values[:TX_TAX] = tx_tax if @options[:payment_country] == 'CO'
261
+ additional_values[:TX_TAX_RETURN_BASE] = tx_tax_return_base if @options[:payment_country] == 'CO'
262
+
263
+ additional_values
264
+ end
265
+
266
+ def add_signature(post)
267
+ post[:transaction][:order][:signature] = signature_from(post)
268
+ end
269
+
270
+ def signature_from(post)
271
+ signature_string = [
272
+ @options[:api_key],
273
+ @options[:merchant_id],
274
+ post[:transaction][:order][:referenceCode],
275
+ post[:transaction][:order][:additionalValues][:TX_VALUE][:value],
276
+ post[:transaction][:order][:additionalValues][:TX_VALUE][:currency]
277
+ ].compact.join('~')
278
+
279
+ Digest::MD5.hexdigest(signature_string)
280
+ end
281
+
282
+ def codensa_bin?(number)
283
+ number.start_with?('590712')
284
+ end
285
+
286
+ def add_payment_method(post, payment_method, options)
287
+ if payment_method.is_a?(String)
288
+ brand, token = split_authorization(payment_method)
289
+ credit_card = {}
290
+ credit_card[:securityCode] = options[:cvv] if options[:cvv]
291
+ credit_card[:processWithoutCvv2] = true if options[:cvv].blank?
292
+ post[:transaction][:creditCard] = credit_card
293
+ post[:transaction][:creditCardTokenId] = token
294
+ post[:transaction][:paymentMethod] = brand.upcase
295
+ else
296
+ credit_card = {}
297
+ credit_card[:number] = payment_method.number
298
+ credit_card[:securityCode] = payment_method.verification_value || options[:cvv]
299
+ credit_card[:expirationDate] = format(payment_method.year, :four_digits).to_s + '/' + format(payment_method.month, :two_digits).to_s
300
+ credit_card[:name] = payment_method.name.strip
301
+ credit_card[:processWithoutCvv2] = true if add_process_without_cvv2(payment_method, options)
302
+ post[:transaction][:creditCard] = credit_card
303
+ post[:transaction][:paymentMethod] = codensa_bin?(payment_method.number) ? 'CODENSA' : BRAND_MAP[payment_method.brand.to_s]
304
+ end
305
+ end
306
+
307
+ def add_process_without_cvv2(payment_method, options)
308
+ return true if payment_method.verification_value.blank? && options[:cvv].blank?
309
+
310
+ false
311
+ end
312
+
313
+ def add_extra_parameters(post, options)
314
+ extra_parameters = {}
315
+ extra_parameters[:INSTALLMENTS_NUMBER] = options[:installments_number] || 1
316
+ extra_parameters[:EXTRA1] = options[:extra_1] if options[:extra_1]
317
+ extra_parameters[:EXTRA2] = options[:extra_2] if options[:extra_2]
318
+ extra_parameters[:EXTRA3] = options[:extra_3] if options[:extra_3]
319
+ post[:transaction][:extraParameters] = extra_parameters
320
+ end
321
+
322
+ def add_reference(post, authorization)
323
+ order_id, transaction_id = split_authorization(authorization)
324
+ order = {}
325
+ order[:id] = order_id
326
+ post[:transaction][:order] = order
327
+ post[:transaction][:parentTransactionId] = transaction_id
328
+ post[:transaction][:reason] = 'n/a'
329
+ end
330
+
331
+ def add_payment_method_to_be_tokenized(post, payment_method, options)
332
+ credit_card_token = {}
333
+ credit_card_token[:payerId] = options[:payer_id] || generate_unique_id
334
+ credit_card_token[:name] = payment_method.name.strip
335
+ credit_card_token[:identificationNumber] = options[:dni_number]
336
+ credit_card_token[:paymentMethod] = BRAND_MAP[payment_method.brand.to_s]
337
+ credit_card_token[:number] = payment_method.number
338
+ credit_card_token[:expirationDate] = format(payment_method.year, :four_digits).to_s + '/' + format(payment_method.month, :two_digits).to_s
339
+ post[:creditCardToken] = credit_card_token
340
+ end
341
+
342
+ def commit(action, params)
343
+ raw_response = ssl_post(url, post_data(params), headers)
344
+ response = parse(raw_response)
345
+ rescue ResponseError => e
346
+ raw_response = e.response.body
347
+ response_error(raw_response)
348
+ rescue JSON::ParserError
349
+ unparsable_response(raw_response)
350
+ else
351
+ success = success_from(action, response)
352
+ Response.new(
353
+ success,
354
+ message_from(action, success, response),
355
+ response,
356
+ authorization: success ? authorization_from(action, response) : nil,
357
+ error_code: success ? nil : error_from(action, response),
358
+ test: test?
359
+ )
360
+ end
361
+
362
+ def headers
363
+ {
364
+ 'Content-Type' => 'application/json',
365
+ 'Accept' => 'application/json'
366
+ }
367
+ end
368
+
369
+ def post_data(params)
370
+ params.merge(test: test?)
371
+ params.to_json
372
+ end
373
+
374
+ def url
375
+ test? ? test_url : live_url
376
+ end
377
+
378
+ def parse(body)
379
+ JSON.parse(body)
380
+ end
381
+
382
+ def success_from(action, response)
383
+ case action
384
+ when 'store'
385
+ response['code'] == 'SUCCESS' && response['creditCardToken'] && response['creditCardToken']['creditCardTokenId'].present?
386
+ when 'verify_credentials'
387
+ response['code'] == 'SUCCESS'
388
+ when 'refund', 'void'
389
+ response['code'] == 'SUCCESS' && response['transactionResponse'] && (response['transactionResponse']['state'] == 'PENDING' || response['transactionResponse']['state'] == 'APPROVED')
390
+ else
391
+ response['code'] == 'SUCCESS' && response['transactionResponse'] && (response['transactionResponse']['state'] == 'APPROVED')
392
+ end
393
+ end
394
+
395
+ def message_from(action, success, response)
396
+ case action
397
+ when 'store'
398
+ message_from_store(success, response)
399
+ when 'verify_credentials'
400
+ message_from_verify_credentials(success)
401
+ else
402
+ message_from_transaction_response(success, response)
403
+ end
404
+ end
405
+
406
+ def message_from_store(success, response)
407
+ return response['code'] if success
408
+
409
+ error_description = response['creditCardToken']['errorDescription'] if response['creditCardToken']
410
+ response['error'] || error_description || 'FAILED'
411
+ end
412
+
413
+ def message_from_verify_credentials(success)
414
+ return 'VERIFIED' if success
415
+
416
+ 'FAILED'
417
+ end
418
+
419
+ def message_from_transaction_response(success, response)
420
+ response_code = response.dig('transactionResponse', 'responseCode') || response.dig('transactionResponse', 'pendingReason')
421
+ return response_code if success
422
+ return response_code + ' | ' + response.dig('transactionResponse', 'paymentNetworkResponseErrorMessage') if response.dig('transactionResponse', 'paymentNetworkResponseErrorMessage')
423
+ return response.dig('transactionResponse', 'responseMessage') if response.dig('transactionResponse', 'responseMessage')
424
+ return response['error'] if response['error']
425
+ return response_code if response_code
426
+
427
+ 'FAILED'
428
+ end
429
+
430
+ def authorization_from(action, response)
431
+ case action
432
+ when 'store'
433
+ [
434
+ response['creditCardToken']['paymentMethod'],
435
+ response['creditCardToken']['creditCardTokenId']
436
+ ].compact.join('|')
437
+ when 'verify_credentials'
438
+ nil
439
+ else
440
+ [
441
+ response['transactionResponse']['orderId'],
442
+ response['transactionResponse']['transactionId']
443
+ ].compact.join('|')
444
+ end
445
+ end
446
+
447
+ def split_authorization(authorization)
448
+ authorization.split('|')
449
+ end
450
+
451
+ def error_from(action, response)
452
+ case action
453
+ when 'store'
454
+ response['creditCardToken']['errorDescription'] if response['creditCardToken']
455
+ when 'verify_credentials'
456
+ response['error'] || 'FAILED'
457
+ else
458
+ response['transactionResponse']['paymentNetworkResponseCode'] || response['transactionResponse']['errorCode'] if response['transactionResponse']
459
+ end
460
+ end
461
+
462
+ def response_error(raw_response)
463
+ response = parse(raw_response)
464
+ rescue JSON::ParserError
465
+ unparsable_response(raw_response)
466
+ else
467
+ return Response.new(
468
+ false,
469
+ message_from('', false, response),
470
+ response,
471
+ test: test?
472
+ )
473
+ end
474
+
475
+ def unparsable_response(raw_response)
476
+ message = 'Invalid JSON response received from PayuLatamGateway. Please contact PayuLatamGateway if you continue to receive this message.'
477
+ message += " (The raw response returned by the API was #{raw_response.inspect})"
478
+ return Response.new(false, message)
479
+ end
480
+ end
481
+ end
482
+ end
@@ -0,0 +1,207 @@
1
+ module ActiveMerchant
2
+ module Billing
3
+ class PaywayGateway < Gateway
4
+ self.live_url = self.test_url = 'https://ccapi.client.qvalent.com/payway/ccapi'
5
+
6
+ self.supported_countries = ['AU']
7
+ self.supported_cardtypes = %i[visa master diners_club american_express bankcard]
8
+ self.display_name = 'Pay Way'
9
+ self.homepage_url = 'http://www.payway.com.au'
10
+ self.default_currency = 'AUD'
11
+ self.money_format = :cents
12
+
13
+ SUMMARY_CODES = {
14
+ '0' => 'Approved',
15
+ '1' => 'Declined',
16
+ '2' => 'Erred',
17
+ '3' => 'Rejected'
18
+ }
19
+
20
+ RESPONSE_CODES = {
21
+ '00' => 'Completed Successfully',
22
+ '01' => 'Refer to card issuer',
23
+ '03' => 'Invalid merchant',
24
+ '04' => 'Pick-up card',
25
+ '05' => 'Do not honour',
26
+ '08' => 'Honour only with identification',
27
+ '12' => 'Invalid transaction',
28
+ '13' => 'Invalid amount',
29
+ '14' => 'Invalid card number (no such number)',
30
+ '30' => 'Format error',
31
+ '36' => 'Restricted card',
32
+ '41' => 'Lost card',
33
+ '42' => 'No universal card',
34
+ '43' => 'Stolen card',
35
+ '51' => 'Not sufficient funds',
36
+ '54' => 'Expired card',
37
+ '61' => 'Exceeds withdrawal amount limits',
38
+ '62' => 'Restricted card',
39
+ '65' => 'Exceeds withdrawal frequency limit',
40
+ '91' => 'Issuer or switch is inoperative',
41
+ '92' => 'Financial institution or intermediate network facility cannot be found for routing',
42
+ '94' => 'Duplicate transmission',
43
+ 'Q1' => 'Unknown Buyer',
44
+ 'Q2' => 'Transaction Pending',
45
+ 'Q3' => 'Payment Gateway Connection Error',
46
+ 'Q4' => 'Payment Gateway Unavailable',
47
+ 'Q5' => 'Invalid Transaction',
48
+ 'Q6' => 'Duplicate Transaction - requery to determine status',
49
+ 'QA' => 'Invalid parameters or Initialisation failed',
50
+ 'QB' => 'Order type not currently supported',
51
+ 'QC' => 'Invalid Order Type',
52
+ 'QD' => 'Invalid Payment Amount - Payment amount less than minimum/exceeds maximum allowed limit',
53
+ 'QE' => 'Internal Error',
54
+ 'QF' => 'Transaction Failed',
55
+ 'QG' => 'Unknown Customer Order Number',
56
+ 'QH' => 'Unknown Customer Username or Password',
57
+ 'QI' => 'Transaction incomplete - contact Westpac to confirm reconciliation',
58
+ 'QJ' => 'Invalid Client Certificate',
59
+ 'QK' => 'Unknown Customer Merchant',
60
+ 'QL' => 'Business Group not configured for customer',
61
+ 'QM' => 'Payment Instrument not configured for customer',
62
+ 'QN' => 'Configuration Error',
63
+ 'QO' => 'Missing Payment Instrument',
64
+ 'QP' => 'Missing Supplier Account',
65
+ 'QQ' => 'Invalid Credit Card Verification Number',
66
+ 'QR' => 'Transaction Retry',
67
+ 'QS' => 'Transaction Successful',
68
+ 'QT' => 'Invalid currency',
69
+ 'QU' => 'Unknown Customer IP Address',
70
+ 'QV' => 'Invalid Original Order Number specified for Refund, Refund amount exceeds capture amount, or Previous capture was not approved',
71
+ 'QW' => 'Invalid Reference Number',
72
+ 'QX' => 'Network Error has occurred',
73
+ 'QY' => 'Card Type Not Accepted',
74
+ 'QZ' => 'Zero value transaction'
75
+ }
76
+
77
+ TRANSACTIONS = {
78
+ authorize: 'preauth',
79
+ purchase: 'capture',
80
+ capture: 'captureWithoutAuth',
81
+ status: 'query',
82
+ refund: 'refund',
83
+ store: 'registerAccount'
84
+ }
85
+
86
+ def initialize(options = {})
87
+ @options = options
88
+
89
+ @options[:merchant] ||= 'TEST' if test?
90
+ requires!(options, :username, :password, :merchant, :pem)
91
+
92
+ @options[:eci] ||= 'SSL'
93
+ end
94
+
95
+ def authorize(amount, payment_method, options = {})
96
+ requires!(options, :order_id)
97
+
98
+ post = {}
99
+ add_payment_method(post, payment_method)
100
+ add_order(post, amount, options)
101
+ commit(:authorize, post)
102
+ end
103
+
104
+ def capture(amount, authorization, options = {})
105
+ requires!(options, :order_id)
106
+
107
+ post = {}
108
+ add_reference(post, authorization)
109
+ add_order(post, amount, options)
110
+ commit(:capture, post)
111
+ end
112
+
113
+ def purchase(amount, payment_method, options = {})
114
+ requires!(options, :order_id)
115
+
116
+ post = {}
117
+ add_payment_method(post, payment_method)
118
+ add_order(post, amount, options)
119
+ commit(:purchase, post)
120
+ end
121
+
122
+ def refund(amount, authorization, options = {})
123
+ requires!(options, :order_id)
124
+
125
+ post = {}
126
+ add_reference(post, authorization)
127
+ add_order(post, amount, options)
128
+ commit(:refund, post)
129
+ end
130
+
131
+ def store(credit_card, options = {})
132
+ requires!(options, :billing_id)
133
+
134
+ post = {}
135
+ add_payment_method(post, credit_card)
136
+ add_payment_method(post, options[:billing_id])
137
+ commit(:store, post)
138
+ end
139
+
140
+ def status(options = {})
141
+ requires!(options, :order_id)
142
+
143
+ commit(:status, 'customer.orderNumber' => options[:order_id])
144
+ end
145
+
146
+ private
147
+
148
+ def add_payment_method(post, payment_method)
149
+ if payment_method.respond_to?(:number)
150
+ post['card.cardHolderName'] = "#{payment_method.first_name} #{payment_method.last_name}"
151
+ post['card.PAN'] = payment_method.number
152
+ post['card.CVN'] = payment_method.verification_value
153
+ post['card.expiryYear'] = payment_method.year.to_s[-2, 2]
154
+ post['card.expiryMonth'] = sprintf('%02d', payment_method.month)
155
+ else
156
+ post['customer.customerReferenceNumber'] = payment_method
157
+ end
158
+ end
159
+
160
+ def add_reference(post, reference)
161
+ post['customer.originalOrderNumber'] = reference
162
+ end
163
+
164
+ def add_order(post, amount, options)
165
+ post['order.ECI'] = @options[:eci]
166
+ post['order.amount'] = amount
167
+ post['card.currency'] = (options[:currency] || currency(amount))
168
+ post['customer.orderNumber'] = options[:order_id][0...20]
169
+ end
170
+
171
+ def add_auth(post)
172
+ post['customer.username'] = @options[:username]
173
+ post['customer.password'] = @options[:password]
174
+ post['customer.merchant'] = @options[:merchant]
175
+ end
176
+
177
+ # Creates the request and returns the summarized result
178
+ def commit(action, post)
179
+ add_auth(post)
180
+ post['order.type'] = TRANSACTIONS[action]
181
+
182
+ request = post.map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&')
183
+ response = ssl_post(self.live_url, request)
184
+
185
+ params = {}
186
+ CGI.parse(response).each_pair do |key, value|
187
+ actual_key = key.split('.').last
188
+ params[actual_key.underscore.to_sym] = value[0]
189
+ end
190
+
191
+ message = "#{SUMMARY_CODES[params[:summary_code]]} - #{RESPONSE_CODES[params[:response_code]]}"
192
+
193
+ success = (params[:summary_code] ? (params[:summary_code] == '0') : (params[:response_code] == '00'))
194
+
195
+ Response.new(success, message, params,
196
+ test: (@options[:merchant].to_s == 'TEST'),
197
+ authorization: post[:order_number])
198
+ rescue ActiveMerchant::ResponseError => e
199
+ raise unless e.response.code == '403'
200
+
201
+ return Response.new(false, 'Invalid credentials', {}, test: test?)
202
+ rescue ActiveMerchant::ClientCertificateError
203
+ return Response.new(false, 'Invalid certificate', {}, test: test?)
204
+ end
205
+ end
206
+ end
207
+ end