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,348 +1,475 @@
1
- require File.dirname(__FILE__) + '/viaklix'
1
+ require 'active_merchant/billing/gateways/viaklix'
2
+ require 'nokogiri'
2
3
 
3
4
  module ActiveMerchant #:nodoc:
4
5
  module Billing #:nodoc:
5
- # = Elavon Virtual Merchant Gateway
6
- #
7
- # == Example use:
8
- #
9
- # gateway = ActiveMerchant::Billing::ElavonGateway.new(
10
- # :login => "my_virtual_merchant_id",
11
- # :password => "my_virtual_merchant_pin",
12
- # :user => "my_virtual_merchant_user_id" # optional
13
- # )
14
- #
15
- # # set up credit card obj as in main ActiveMerchant example
16
- # creditcard = ActiveMerchant::Billing::CreditCard.new(
17
- # :type => 'visa',
18
- # :number => '41111111111111111',
19
- # :month => 10,
20
- # :year => 2011,
21
- # :first_name => 'Bob',
22
- # :last_name => 'Bobsen'
23
- # )
24
- #
25
- # # run request
26
- # response = gateway.purchase(1000, creditcard) # authorize and capture 10 USD
27
- #
28
- # puts response.success? # Check whether the transaction was successful
29
- # puts response.message # Retrieve the message returned by Elavon
30
- # puts response.authorization # Retrieve the unique transaction ID returned by Elavon
31
- #
32
6
  class ElavonGateway < Gateway
7
+ include Empty
8
+
33
9
  class_attribute :test_url, :live_url, :delimiter, :actions
34
10
 
35
- self.test_url = 'https://demo.myvirtualmerchant.com/VirtualMerchantDemo/process.do'
36
- self.live_url = 'https://www.myvirtualmerchant.com/VirtualMerchant/process.do'
11
+ self.test_url = 'https://api.demo.convergepay.com/VirtualMerchantDemo/processxml.do'
12
+ self.live_url = 'https://api.convergepay.com/VirtualMerchant/processxml.do'
37
13
 
38
14
  self.display_name = 'Elavon MyVirtualMerchant'
39
- self.supported_countries = %w(US CA PR DE IE NO PL LU BE NL)
40
- self.supported_cardtypes = [:visa, :master, :american_express, :discover]
15
+ self.supported_countries = %w(US CA PR DE IE NO PL LU BE NL MX)
16
+ self.supported_cardtypes = %i[visa master american_express discover]
41
17
  self.homepage_url = 'http://www.elavon.com/'
18
+ self.money_format = :dollars
19
+ self.default_currency = 'USD'
42
20
 
43
21
  self.delimiter = "\n"
44
22
  self.actions = {
45
- :purchase => 'CCSALE',
46
- :credit => 'CCCREDIT',
47
- :refund => 'CCRETURN',
48
- :authorize => 'CCAUTHONLY',
49
- :capture => 'CCFORCE',
50
- :void => 'CCDELETE',
51
- :store => 'CCGETTOKEN',
52
- :update => 'CCUPDATETOKEN',
23
+ purchase: 'CCSALE',
24
+ credit: 'CCCREDIT',
25
+ refund: 'CCRETURN',
26
+ authorize: 'CCAUTHONLY',
27
+ capture: 'CCFORCE',
28
+ capture_complete: 'CCCOMPLETE',
29
+ void: 'CCDELETE',
30
+ store: 'CCGETTOKEN',
31
+ update: 'CCUPDATETOKEN',
32
+ verify: 'CCVERIFY'
53
33
  }
54
34
 
55
- # Initialize the Gateway
56
- #
57
- # The gateway requires that a valid login and password be passed
58
- # in the +options+ hash.
59
- #
60
- # ==== Options
61
- #
62
- # * <tt>:login</tt> -- Merchant ID
63
- # * <tt>:password</tt> -- PIN
64
- # * <tt>:user</tt> -- Specify a subuser of the account (optional)
65
- # * <tt>:test => +true+ or +false+</tt> -- Force test transactions
66
35
  def initialize(options = {})
67
36
  requires!(options, :login, :password)
68
37
  super
69
38
  end
70
39
 
71
- # Make a purchase
72
40
  def purchase(money, payment_method, options = {})
73
- form = {}
74
- add_salestax(form, options)
75
- add_invoice(form, options)
76
- if payment_method.is_a?(String)
77
- add_token(form, payment_method)
78
- else
79
- add_creditcard(form, payment_method)
41
+ request = build_xml_request do |xml|
42
+ xml.ssl_vendor_id @options[:ssl_vendor_id] || options[:ssl_vendor_id]
43
+ xml.ssl_transaction_type self.actions[:purchase]
44
+ xml.ssl_amount amount(money)
45
+
46
+ if payment_method.is_a?(String)
47
+ add_token(xml, payment_method)
48
+ else
49
+ add_creditcard(xml, payment_method)
50
+ end
51
+
52
+ add_invoice(xml, options)
53
+ add_salestax(xml, options)
54
+ add_currency(xml, money, options)
55
+ add_address(xml, options)
56
+ add_customer_email(xml, options)
57
+ add_test_mode(xml, options)
58
+ add_ip(xml, options)
59
+ add_auth_purchase_params(xml, options)
60
+ add_level_3_fields(xml, options) if options[:level_3_data]
80
61
  end
81
- add_address(form, options)
82
- add_customer_data(form, options)
83
- add_test_mode(form, options)
84
- commit(:purchase, money, form)
85
- end
86
-
87
- # Authorize a credit card for a given amount.
88
- #
89
- # ==== Parameters
90
- # * <tt>money</tt> - The amount to be authorized as an Integer value in cents.
91
- # * <tt>credit_card</tt> - The CreditCard details for the transaction.
92
- # * <tt>options</tt>
93
- # * <tt>:billing_address</tt> - The billing address for the cardholder.
62
+ commit(request)
63
+ end
64
+
94
65
  def authorize(money, creditcard, options = {})
95
- form = {}
96
- add_salestax(form, options)
97
- add_invoice(form, options)
98
- add_creditcard(form, creditcard)
99
- add_address(form, options)
100
- add_customer_data(form, options)
101
- add_test_mode(form, options)
102
- commit(:authorize, money, form)
103
- end
104
-
105
- # Capture authorized funds from a credit card.
106
- #
107
- # ==== Parameters
108
- # * <tt>money</tt> - The amount to be captured as an Integer value in cents.
109
- # * <tt>authorization</tt> - The approval code returned from the initial authorization.
110
- # * <tt>options</tt>
111
- # * <tt>:credit_card</tt> - The CreditCard details from the initial transaction (required).
66
+ request = build_xml_request do |xml|
67
+ xml.ssl_vendor_id @options[:ssl_vendor_id] || options[:ssl_vendor_id]
68
+ xml.ssl_transaction_type self.actions[:authorize]
69
+ xml.ssl_amount amount(money)
70
+
71
+ add_salestax(xml, options)
72
+ add_invoice(xml, options)
73
+ add_creditcard(xml, creditcard)
74
+ add_currency(xml, money, options)
75
+ add_address(xml, options)
76
+ add_customer_email(xml, options)
77
+ add_test_mode(xml, options)
78
+ add_ip(xml, options)
79
+ add_auth_purchase_params(xml, options)
80
+ add_level_3_fields(xml, options) if options[:level_3_data]
81
+ end
82
+ commit(request)
83
+ end
84
+
112
85
  def capture(money, authorization, options = {})
113
- requires!(options, :credit_card)
114
-
115
- form = {}
116
- add_salestax(form, options)
117
- add_approval_code(form, authorization)
118
- add_invoice(form, options)
119
- add_creditcard(form, options[:credit_card])
120
- add_customer_data(form, options)
121
- add_test_mode(form, options)
122
- commit(:capture, money, form)
123
- end
124
-
125
- # Refund a transaction.
126
- #
127
- # This transaction indicates to the gateway that
128
- # money should flow from the merchant to the customer.
129
- #
130
- # ==== Parameters
131
- #
132
- # * <tt>money</tt> -- The amount to be credited to the customer as an Integer value in cents.
133
- # * <tt>identification</tt> -- The ID of the original transaction against which the refund is being issued.
134
- # * <tt>options</tt> -- A hash of parameters.
86
+ request = build_xml_request do |xml|
87
+ xml.ssl_vendor_id @options[:ssl_vendor_id] || options[:ssl_vendor_id]
88
+
89
+ if options[:credit_card]
90
+ xml.ssl_transaction_type self.actions[:capture]
91
+ xml.ssl_amount amount(money)
92
+ add_salestax(xml, options)
93
+ add_approval_code(xml, authorization)
94
+ add_invoice(xml, options)
95
+ add_creditcard(xml, options[:credit_card])
96
+ add_currency(xml, money, options)
97
+ add_address(xml, options)
98
+ add_customer_email(xml, options)
99
+ add_test_mode(xml, options)
100
+ else
101
+ xml.ssl_transaction_type self.actions[:capture_complete]
102
+ xml.ssl_amount amount(money)
103
+ add_currency(xml, money, options)
104
+ add_txn_id(xml, authorization)
105
+ add_partial_shipment_flag(xml, options)
106
+ add_test_mode(xml, options)
107
+ end
108
+ end
109
+ commit(request)
110
+ end
111
+
135
112
  def refund(money, identification, options = {})
136
- form = {}
137
- add_txn_id(form, identification)
138
- add_test_mode(form, options)
139
- commit(:refund, money, form)
113
+ request = build_xml_request do |xml|
114
+ xml.ssl_vendor_id @options[:ssl_vendor_id] || options[:ssl_vendor_id]
115
+ xml.ssl_transaction_type self.actions[:refund]
116
+ xml.ssl_amount amount(money)
117
+ add_txn_id(xml, identification)
118
+ add_test_mode(xml, options)
119
+ end
120
+ commit(request)
140
121
  end
141
122
 
142
- # Void a previous transaction
143
- #
144
- # ==== Parameters
145
- #
146
- # * <tt>authorization</tt> - The authorization returned from the previous request.
147
123
  def void(identification, options = {})
148
- form = {}
149
- add_txn_id(form, identification)
150
- add_test_mode(form, options)
151
- commit(:void, nil, form)
152
- end
153
-
154
- # Make a credit to a card. Use the refund method if you'd like to credit using
155
- # previous transaction
156
- #
157
- # ==== Parameters
158
- # * <tt>money</tt> - The amount to be credited as an Integer value in cents.
159
- # * <tt>creditcard</tt> - The credit card to be credited.
160
- # * <tt>options</tt>
161
- def credit(money, creditcard, options = {})
162
- if creditcard.is_a?(String)
163
- raise ArgumentError, "Reference credits are not supported. Please supply the original credit card or use the #refund method."
124
+ request = build_xml_request do |xml|
125
+ xml.ssl_vendor_id @options[:ssl_vendor_id] || options[:ssl_vendor_id]
126
+ xml.ssl_transaction_type self.actions[:void]
127
+
128
+ add_txn_id(xml, identification)
129
+ add_test_mode(xml, options)
164
130
  end
131
+ commit(request)
132
+ end
165
133
 
166
- form = {}
167
- add_invoice(form, options)
168
- add_creditcard(form, creditcard)
169
- add_address(form, options)
170
- add_customer_data(form, options)
171
- add_test_mode(form, options)
172
- commit(:credit, money, form)
134
+ def credit(money, creditcard, options = {})
135
+ raise ArgumentError, 'Reference credits are not supported. Please supply the original credit card or use the #refund method.' if creditcard.is_a?(String)
136
+
137
+ request = build_xml_request do |xml|
138
+ xml.ssl_vendor_id @options[:ssl_vendor_id] || options[:ssl_vendor_id]
139
+ xml.ssl_transaction_type self.actions[:credit]
140
+ xml.ssl_amount amount(money)
141
+ add_invoice(xml, options)
142
+ add_creditcard(xml, creditcard)
143
+ add_currency(xml, money, options)
144
+ add_address(xml, options)
145
+ add_customer_email(xml, options)
146
+ add_test_mode(xml, options)
147
+ end
148
+ commit(request)
173
149
  end
174
150
 
175
151
  def verify(credit_card, options = {})
176
- MultiResponse.run(:use_first_response) do |r|
177
- r.process { authorize(100, credit_card, options) }
178
- r.process(:ignore_result) { void(r.authorization, options) }
152
+ request = build_xml_request do |xml|
153
+ xml.ssl_vendor_id @options[:ssl_vendor_id] || options[:ssl_vendor_id]
154
+ xml.ssl_transaction_type self.actions[:verify]
155
+ add_creditcard(xml, credit_card)
156
+ add_address(xml, options)
157
+ add_test_mode(xml, options)
158
+ add_ip(xml, options)
179
159
  end
160
+ commit(request)
180
161
  end
181
162
 
182
163
  def store(creditcard, options = {})
183
- form = {}
184
- add_creditcard(form, creditcard)
185
- add_address(form, options)
186
- add_customer_data(form, options)
187
- add_test_mode(form, options)
188
- add_verification(form, options)
189
- form[:add_token] = 'Y'
190
- commit(:store, nil, form)
164
+ request = build_xml_request do |xml|
165
+ xml.ssl_vendor_id @options[:ssl_vendor_id] || options[:ssl_vendor_id]
166
+ xml.ssl_transaction_type self.actions[:store]
167
+ xml.ssl_add_token 'Y'
168
+ add_creditcard(xml, creditcard)
169
+ add_address(xml, options)
170
+ add_customer_email(xml, options)
171
+ add_test_mode(xml, options)
172
+ add_verification(xml, options)
173
+ end
174
+ commit(request)
191
175
  end
192
176
 
193
177
  def update(token, creditcard, options = {})
194
- form = {}
195
- add_token(form, token)
196
- add_creditcard(form, creditcard)
197
- add_address(form, options)
198
- add_customer_data(form, options)
199
- add_test_mode(form, options)
200
- commit(:update, nil, form)
178
+ request = build_xml_request do |xml|
179
+ xml.ssl_vendor_id @options[:ssl_vendor_id] || options[:ssl_vendor_id]
180
+ xml.ssl_transaction_type self.actions[:update]
181
+ add_token(xml, token)
182
+ add_creditcard(xml, creditcard)
183
+ add_address(xml, options)
184
+ add_customer_email(xml, options)
185
+ add_test_mode(xml, options)
186
+ end
187
+ commit(request)
201
188
  end
202
189
 
203
- private
190
+ def supports_scrubbing?
191
+ true
192
+ end
204
193
 
205
- def add_invoice(form,options)
206
- form[:invoice_number] = (options[:order_id] || options[:invoice]).to_s.slice(0, 10)
207
- form[:description] = options[:description].to_s.slice(0, 255)
194
+ def scrub(transcript)
195
+ transcript.
196
+ gsub(%r((<ssl_pin>)(.*)(</ssl_pin>)), '\1[FILTERED]\3').
197
+ gsub(%r((<ssl_card_number>)(.*)(</ssl_card_number>)), '\1[FILTERED]\3').
198
+ gsub(%r((<ssl_cvv2cvc2>)(.*)(</ssl_cvv2cvc2>)), '\1[FILTERED]\3')
208
199
  end
209
200
 
210
- def add_approval_code(form, authorization)
211
- form[:approval_code] = authorization.split(';').first
201
+ private
202
+
203
+ def add_invoice(xml, options)
204
+ xml.ssl_invoice_number url_encode_truncate((options[:order_id] || options[:invoice]), 25)
205
+ xml.ssl_description url_encode_truncate(options[:description], 255)
212
206
  end
213
207
 
214
- def add_txn_id(form, authorization)
215
- form[:txn_id] = authorization.split(';').last
208
+ def add_approval_code(xml, authorization)
209
+ xml.ssl_approval_code authorization.split(';').first
216
210
  end
217
211
 
218
- def authorization_from(response)
219
- [response['approval_code'], response['txn_id']].join(';')
212
+ def add_txn_id(xml, authorization)
213
+ xml.ssl_txn_id authorization.split(';').last
220
214
  end
221
215
 
222
- def add_creditcard(form, creditcard)
223
- form[:card_number] = creditcard.number
224
- form[:exp_date] = expdate(creditcard)
216
+ def add_creditcard(xml, creditcard)
217
+ xml.ssl_card_number creditcard.number
218
+ xml.ssl_exp_date expdate(creditcard)
225
219
 
226
- if creditcard.verification_value?
227
- add_verification_value(form, creditcard)
228
- end
220
+ add_verification_value(xml, creditcard) if creditcard.verification_value?
229
221
 
230
- form[:first_name] = creditcard.first_name.to_s.slice(0, 20)
231
- form[:last_name] = creditcard.last_name.to_s.slice(0, 30)
222
+ xml.ssl_first_name url_encode_truncate(creditcard.first_name, 20)
223
+ xml.ssl_last_name url_encode_truncate(creditcard.last_name, 30)
232
224
  end
233
225
 
234
- def add_token(form, token)
235
- form[:token] = token
226
+ def add_currency(xml, money, options)
227
+ currency = options[:currency] || currency(money)
228
+ return unless currency && (@options[:multi_currency] || options[:multi_currency])
229
+
230
+ xml.ssl_transaction_currency currency
231
+ end
232
+
233
+ def add_token(xml, token)
234
+ xml.ssl_token token
236
235
  end
237
236
 
238
- def add_verification_value(form, creditcard)
239
- form[:cvv2cvc2] = creditcard.verification_value
240
- form[:cvv2cvc2_indicator] = '1'
237
+ def add_verification_value(xml, creditcard)
238
+ xml.ssl_cvv2cvc2 creditcard.verification_value
239
+ xml.ssl_cvv2cvc2_indicator 1
241
240
  end
242
241
 
243
- def add_customer_data(form, options)
244
- form[:email] = options[:email].to_s.slice(0, 100) unless options[:email].blank?
245
- form[:customer_code] = options[:customer].to_s.slice(0, 10) unless options[:customer].blank?
242
+ def add_customer_email(xml, options)
243
+ xml.ssl_email url_encode_truncate(options[:email], 100) unless empty?(options[:email])
246
244
  end
247
245
 
248
- def add_salestax(form, options)
249
- form[:salestax] = options[:tax] if options[:tax].present?
246
+ def add_salestax(xml, options)
247
+ return unless options[:tax].present?
248
+
249
+ xml.ssl_salestax options[:tax]
250
250
  end
251
251
 
252
- def add_address(form, options)
252
+ def add_address(xml, options)
253
253
  billing_address = options[:billing_address] || options[:address]
254
254
 
255
255
  if billing_address
256
- form[:avs_address] = billing_address[:address1].to_s.slice(0, 30)
257
- form[:address2] = billing_address[:address2].to_s.slice(0, 30)
258
- form[:avs_zip] = billing_address[:zip].to_s.gsub(/[^a-zA-Z0-9]/, '').slice(0, 9)
259
- form[:city] = billing_address[:city].to_s.slice(0, 30)
260
- form[:state] = billing_address[:state].to_s.slice(0, 10)
261
- form[:company] = billing_address[:company].to_s.slice(0, 50)
262
- form[:phone] = billing_address[:phone].to_s.slice(0, 20)
263
- form[:country] = billing_address[:country].to_s.slice(0, 50)
256
+ xml.ssl_avs_address url_encode_truncate(billing_address[:address1], 30)
257
+ xml.ssl_address2 url_encode_truncate(billing_address[:address2], 30)
258
+ xml.ssl_avs_zip url_encode_truncate(billing_address[:zip].to_s.gsub(/[^a-zA-Z0-9]/, ''), 9)
259
+ xml.ssl_city url_encode_truncate(billing_address[:city], 30)
260
+ xml.ssl_state url_encode_truncate(billing_address[:state], 10)
261
+ xml.ssl_company url_encode_truncate(billing_address[:company], 50)
262
+ xml.ssl_phone url_encode_truncate(billing_address[:phone], 20)
263
+ xml.ssl_country url_encode_truncate(billing_address[:country], 50)
264
264
  end
265
265
 
266
266
  if shipping_address = options[:shipping_address]
267
- first_name, last_name = parse_first_and_last_name(shipping_address[:name])
268
- form[:ship_to_first_name] = first_name.to_s.slice(0, 20)
269
- form[:ship_to_last_name] = last_name.to_s.slice(0, 30)
270
- form[:ship_to_address1] = shipping_address[:address1].to_s.slice(0, 30)
271
- form[:ship_to_address2] = shipping_address[:address2].to_s.slice(0, 30)
272
- form[:ship_to_city] = shipping_address[:city].to_s.slice(0, 30)
273
- form[:ship_to_state] = shipping_address[:state].to_s.slice(0, 10)
274
- form[:ship_to_company] = shipping_address[:company].to_s.slice(0, 50)
275
- form[:ship_to_country] = shipping_address[:country].to_s.slice(0, 50)
276
- form[:ship_to_zip] = shipping_address[:zip].to_s.slice(0, 10)
267
+ xml.ssl_ship_to_address1 url_encode_truncate(shipping_address[:address1], 30)
268
+ xml.ssl_ship_to_address2 url_encode_truncate(shipping_address[:address2], 30)
269
+ xml.ssl_ship_to_city url_encode_truncate(shipping_address[:city], 30)
270
+ xml.ssl_ship_to_company url_encode_truncate(shipping_address[:company], 50)
271
+ xml.ssl_ship_to_country url_encode_truncate(shipping_address[:country], 50)
272
+ xml.ssl_ship_to_first_name url_encode_truncate(shipping_address[:first_name], 20)
273
+ xml.ssl_ship_to_last_name url_encode_truncate(shipping_address[:last_name], 30)
274
+ xml.ssl_ship_to_phone url_encode_truncate(shipping_address[:phone], 10)
275
+ xml.ssl_ship_to_state url_encode_truncate(shipping_address[:state], 2)
276
+ xml.ssl_ship_to_zip url_encode_truncate(shipping_address[:zip], 10)
277
277
  end
278
278
  end
279
279
 
280
- def add_verification(form, options)
281
- form[:verify] = 'Y' if options[:verify]
280
+ def add_verification(xml, options)
281
+ xml.ssl_verify 'Y' if options[:verify]
282
282
  end
283
283
 
284
- def parse_first_and_last_name(value)
285
- name = value.to_s.split(' ')
284
+ def add_test_mode(xml, options)
285
+ xml.ssl_test_mode 'TRUE' if options[:test_mode]
286
+ end
286
287
 
287
- last_name = name.pop || ''
288
- first_name = name.join(' ')
289
- [ first_name, last_name ]
288
+ def add_partial_shipment_flag(xml, options)
289
+ xml.ssl_partial_shipment_flag 'Y' if options[:partial_shipment_flag]
290
290
  end
291
291
 
292
- def add_test_mode(form, options)
293
- form[:test_mode] = 'TRUE' if options[:test_mode]
292
+ def add_ip(xml, options)
293
+ xml.ssl_cardholder_ip options[:ip] if options.has_key?(:ip)
294
294
  end
295
295
 
296
- def message_from(response)
297
- success?(response) ? response['result_message'] : response['errorMessage']
296
+ # add_recurring_token is a field that can be sent in to obtain a token from Elavon for use with their tokenization program
297
+ def add_auth_purchase_params(xml, options)
298
+ xml.ssl_dynamic_dba options[:dba] if options.has_key?(:dba)
299
+ xml.ssl_merchant_initiated_unscheduled merchant_initiated_unscheduled(options) if merchant_initiated_unscheduled(options)
300
+ xml.ssl_add_token options[:add_recurring_token] if options.has_key?(:add_recurring_token)
301
+ xml.ssl_token options[:ssl_token] if options[:ssl_token]
302
+ xml.ssl_customer_code options[:customer] if options.has_key?(:customer)
303
+ xml.ssl_customer_number options[:customer_number] if options.has_key?(:customer_number)
304
+ xml.ssl_entry_mode entry_mode(options) if entry_mode(options)
305
+ add_custom_fields(xml, options) if options[:custom_fields]
306
+ add_stored_credential(xml, options) if options[:stored_credential]
298
307
  end
299
308
 
300
- def success?(response)
301
- !response.has_key?('errorMessage')
309
+ def add_custom_fields(xml, options)
310
+ options[:custom_fields]&.each do |key, value|
311
+ xml.send(key.to_sym, value)
312
+ end
302
313
  end
303
314
 
304
- def commit(action, money, parameters)
305
- parameters[:amount] = amount(money)
306
- parameters[:transaction_type] = self.actions[action]
315
+ def add_level_3_fields(xml, options)
316
+ level_3_data = options[:level_3_data]
317
+ xml.ssl_customer_code level_3_data[:customer_code] if level_3_data[:customer_code]
318
+ xml.ssl_salestax level_3_data[:salestax] if level_3_data[:salestax]
319
+ xml.ssl_salestax_indicator level_3_data[:salestax_indicator] if level_3_data[:salestax_indicator]
320
+ xml.ssl_level3_indicator level_3_data[:level3_indicator] if level_3_data[:level3_indicator]
321
+ xml.ssl_ship_to_zip level_3_data[:ship_to_zip] if level_3_data[:ship_to_zip]
322
+ xml.ssl_ship_to_country level_3_data[:ship_to_country] if level_3_data[:ship_to_country]
323
+ xml.ssl_shipping_amount level_3_data[:shipping_amount] if level_3_data[:shipping_amount]
324
+ xml.ssl_ship_from_postal_code level_3_data[:ship_from_postal_code] if level_3_data[:ship_from_postal_code]
325
+ xml.ssl_discount_amount level_3_data[:discount_amount] if level_3_data[:discount_amount]
326
+ xml.ssl_duty_amount level_3_data[:duty_amount] if level_3_data[:duty_amount]
327
+ xml.ssl_national_tax_indicator level_3_data[:national_tax_indicator] if level_3_data[:national_tax_indicator]
328
+ xml.ssl_national_tax_amount level_3_data[:national_tax_amount] if level_3_data[:national_tax_amount]
329
+ xml.ssl_order_date level_3_data[:order_date] if level_3_data[:order_date]
330
+ xml.ssl_other_tax level_3_data[:other_tax] if level_3_data[:other_tax]
331
+ xml.ssl_summary_commodity_code level_3_data[:summary_commodity_code] if level_3_data[:summary_commodity_code]
332
+ xml.ssl_merchant_vat_number level_3_data[:merchant_vat_number] if level_3_data[:merchant_vat_number]
333
+ xml.ssl_customer_vat_number level_3_data[:customer_vat_number] if level_3_data[:customer_vat_number]
334
+ xml.ssl_freight_tax_amount level_3_data[:freight_tax_amount] if level_3_data[:freight_tax_amount]
335
+ xml.ssl_vat_invoice_number level_3_data[:vat_invoice_number] if level_3_data[:vat_invoice_number]
336
+ xml.ssl_tracking_number level_3_data[:tracking_number] if level_3_data[:tracking_number]
337
+ xml.ssl_shipping_company level_3_data[:shipping_company] if level_3_data[:shipping_company]
338
+ xml.ssl_other_fees level_3_data[:other_fees] if level_3_data[:other_fees]
339
+ add_line_items(xml, level_3_data) if level_3_data[:line_items]
340
+ end
307
341
 
308
- response = parse( ssl_post(test? ? self.test_url : self.live_url, post_data(parameters)) )
342
+ def add_line_items(xml, level_3_data)
343
+ xml.LineItemProducts {
344
+ level_3_data[:line_items].each do |line_item|
345
+ xml.product {
346
+ line_item.each do |key, value|
347
+ prefixed_key = "ssl_line_Item_#{key}"
348
+ xml.send(prefixed_key, value)
349
+ end
350
+ }
351
+ end
352
+ }
353
+ end
354
+
355
+ def add_stored_credential(xml, options)
356
+ network_transaction_id = options.dig(:stored_credential, :network_transaction_id)
357
+ case
358
+ when network_transaction_id.nil?
359
+ return
360
+ when network_transaction_id.to_s.include?('|')
361
+ oar_data, ps2000_data = options[:stored_credential][:network_transaction_id].split('|')
362
+ xml.ssl_oar_data oar_data unless oar_data.nil? || oar_data.empty?
363
+ xml.ssl_ps2000_data ps2000_data unless ps2000_data.nil? || ps2000_data.empty?
364
+ when network_transaction_id.to_s.length > 22
365
+ xml.ssl_oar_data options.dig(:stored_credential, :network_transaction_id)
366
+ else
367
+ xml.ssl_ps2000_data options.dig(:stored_credential, :network_transaction_id)
368
+ end
369
+ end
370
+
371
+ def merchant_initiated_unscheduled(options)
372
+ return options[:merchant_initiated_unscheduled] if options[:merchant_initiated_unscheduled]
373
+ return 'Y' if options.dig(:stored_credential, :initiator) == 'merchant' && options.dig(:stored_credential, :reason_type) == 'unscheduled' || options.dig(:stored_credential, :reason_type) == 'recurring'
374
+ end
309
375
 
310
- Response.new(response['result'] == '0', message_from(response), response,
311
- :test => @options[:test] || test?,
312
- :authorization => authorization_from(response),
313
- :avs_result => { :code => response['avs_response'] },
314
- :cvv_result => response['cvv2_response']
376
+ def entry_mode(options)
377
+ return options[:entry_mode] if options[:entry_mode]
378
+ return 12 if options[:stored_credential]
379
+ end
380
+
381
+ def build_xml_request
382
+ builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
383
+ xml.txn do
384
+ xml.ssl_merchant_id @options[:login]
385
+ xml.ssl_user_id @options[:user]
386
+ xml.ssl_pin @options[:password]
387
+ yield(xml)
388
+ end
389
+ end
390
+
391
+ builder.to_xml.gsub("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", '')
392
+ end
393
+
394
+ def commit(request)
395
+ request = "xmldata=#{request}".delete('&')
396
+ store_action = request.match?('CCGETTOKEN')
397
+
398
+ response = parse(ssl_post(test? ? self.test_url : self.live_url, request, headers))
399
+ response = hash_html_decode(response)
400
+
401
+ Response.new(
402
+ response[:result] == '0',
403
+ response[:result_message] || response[:errorMessage],
404
+ response,
405
+ test: @options[:test] || test?,
406
+ authorization: authorization_from(response, store_action),
407
+ error_code: response[:errorCode],
408
+ avs_result: { code: response[:avs_response] },
409
+ cvv_result: response[:cvv2_response],
410
+ network_transaction_id: build_network_transaction_id(response)
315
411
  )
316
412
  end
317
413
 
318
- def post_data(parameters)
319
- result = preamble
320
- result.merge!(parameters)
321
- result.collect { |key, value| "ssl_#{key}=#{CGI.escape(value.to_s)}" }.join("&")
414
+ def build_network_transaction_id(response)
415
+ "#{response[:oar_data]}|#{response[:ps2000_data]}"
322
416
  end
323
417
 
324
- def preamble
325
- result = {
326
- 'merchant_id' => @options[:login],
327
- 'pin' => @options[:password],
328
- 'show_form' => 'false',
329
- 'result_format' => 'ASCII'
418
+ def headers
419
+ {
420
+ 'Accept' => 'application/xml',
421
+ 'Content-type' => 'application/x-www-form-urlencoded;charset=utf8'
330
422
  }
423
+ end
331
424
 
332
- result['user_id'] = @options[:user] unless @options[:user].blank?
333
- result
425
+ def parse(body)
426
+ xml = Nokogiri::XML(body)
427
+ response = Hash.from_xml(xml.to_s)['txn']
428
+
429
+ response.deep_transform_keys { |key| key.gsub('ssl_', '').to_sym }
430
+ end
431
+
432
+ def authorization_from(response, store_action)
433
+ return response[:token] if store_action
434
+
435
+ [response[:approval_code], response[:txn_id]].join(';')
436
+ end
437
+
438
+ def url_encode_truncate(value, size)
439
+ return nil unless value
440
+
441
+ encoded = url_encode(value)
442
+
443
+ while encoded.length > size
444
+ value.chop!
445
+ encoded = url_encode(value)
446
+ end
447
+ encoded
334
448
  end
335
449
 
336
- def parse(msg)
337
- resp = {}
338
- msg.split(self.delimiter).collect{|li|
339
- key, value = li.split("=")
340
- resp[key.to_s.strip.gsub(/^ssl_/, '')] = value.to_s.strip
341
- }
342
- resp
450
+ def url_encode(value)
451
+ if value.is_a?(String)
452
+ encoded = CGI.escape(value)
453
+ encoded = encoded.tr('+', ' ') # don't encode spaces
454
+ encoded = encoded.gsub('%26', '%26amp;') # account for Elavon's weird '&' handling
455
+ encoded
456
+ else
457
+ value.to_s
458
+ end
343
459
  end
344
460
 
461
+ def hash_html_decode(hash)
462
+ hash.each do |k, v|
463
+ if v.is_a?(String)
464
+ # decode all string params
465
+ v = v.gsub('&amp;amp;', '&amp;') # account for Elavon's weird '&' handling
466
+ hash[k] = CGI.unescape_html(v)
467
+ elsif v.is_a?(Hash)
468
+ hash_html_decode(v)
469
+ end
470
+ end
471
+ hash
472
+ end
345
473
  end
346
474
  end
347
475
  end
348
-