archetype2142_activemerchant 1.124.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (271) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +3640 -0
  3. data/CONTRIBUTORS +568 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +249 -0
  6. data/lib/active_merchant/billing/apple_pay_payment_token.rb +22 -0
  7. data/lib/active_merchant/billing/avs_result.rb +95 -0
  8. data/lib/active_merchant/billing/base.rb +48 -0
  9. data/lib/active_merchant/billing/check.rb +80 -0
  10. data/lib/active_merchant/billing/compatibility.rb +118 -0
  11. data/lib/active_merchant/billing/credit_card.rb +414 -0
  12. data/lib/active_merchant/billing/credit_card_formatting.rb +24 -0
  13. data/lib/active_merchant/billing/credit_card_methods.rb +444 -0
  14. data/lib/active_merchant/billing/cvv_result.rb +37 -0
  15. data/lib/active_merchant/billing/gateway.rb +331 -0
  16. data/lib/active_merchant/billing/gateways/adyen.rb +712 -0
  17. data/lib/active_merchant/billing/gateways/allied_wallet.rb +205 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net.rb +1107 -0
  19. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +424 -0
  20. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +977 -0
  21. data/lib/active_merchant/billing/gateways/axcessms.rb +179 -0
  22. data/lib/active_merchant/billing/gateways/balanced.rb +263 -0
  23. data/lib/active_merchant/billing/gateways/bambora_apac.rb +222 -0
  24. data/lib/active_merchant/billing/gateways/bank_frick.rb +225 -0
  25. data/lib/active_merchant/billing/gateways/banwire.rb +116 -0
  26. data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +396 -0
  27. data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +15 -0
  28. data/lib/active_merchant/billing/gateways/be2bill.rb +131 -0
  29. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +474 -0
  30. data/lib/active_merchant/billing/gateways/beanstream.rb +220 -0
  31. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +57 -0
  32. data/lib/active_merchant/billing/gateways/blue_pay.rb +549 -0
  33. data/lib/active_merchant/billing/gateways/blue_snap.rb +613 -0
  34. data/lib/active_merchant/billing/gateways/bogus.rb +186 -0
  35. data/lib/active_merchant/billing/gateways/borgun.rb +231 -0
  36. data/lib/active_merchant/billing/gateways/bpoint.rb +277 -0
  37. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +23 -0
  38. data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
  39. data/lib/active_merchant/billing/gateways/braintree_blue.rb +832 -0
  40. data/lib/active_merchant/billing/gateways/braintree_orange.rb +19 -0
  41. data/lib/active_merchant/billing/gateways/bridge_pay.rb +244 -0
  42. data/lib/active_merchant/billing/gateways/cams.rb +230 -0
  43. data/lib/active_merchant/billing/gateways/card_connect.rb +320 -0
  44. data/lib/active_merchant/billing/gateways/card_save.rb +21 -0
  45. data/lib/active_merchant/billing/gateways/card_stream.rb +371 -0
  46. data/lib/active_merchant/billing/gateways/cardknox.rb +327 -0
  47. data/lib/active_merchant/billing/gateways/cardprocess.rb +256 -0
  48. data/lib/active_merchant/billing/gateways/cashnet.rb +225 -0
  49. data/lib/active_merchant/billing/gateways/cc5.rb +198 -0
  50. data/lib/active_merchant/billing/gateways/cecabank.rb +249 -0
  51. data/lib/active_merchant/billing/gateways/cenpos.rb +328 -0
  52. data/lib/active_merchant/billing/gateways/checkout.rb +212 -0
  53. data/lib/active_merchant/billing/gateways/checkout_v2.rb +311 -0
  54. data/lib/active_merchant/billing/gateways/citrus_pay.rb +21 -0
  55. data/lib/active_merchant/billing/gateways/clearhaus.rb +219 -0
  56. data/lib/active_merchant/billing/gateways/commercegate.rb +142 -0
  57. data/lib/active_merchant/billing/gateways/conekta.rb +230 -0
  58. data/lib/active_merchant/billing/gateways/creditcall.rb +272 -0
  59. data/lib/active_merchant/billing/gateways/credorax.rb +496 -0
  60. data/lib/active_merchant/billing/gateways/ct_payment.rb +269 -0
  61. data/lib/active_merchant/billing/gateways/culqi.rb +279 -0
  62. data/lib/active_merchant/billing/gateways/cyber_source.rb +1074 -0
  63. data/lib/active_merchant/billing/gateways/d_local.rb +253 -0
  64. data/lib/active_merchant/billing/gateways/data_cash.rb +302 -0
  65. data/lib/active_merchant/billing/gateways/decidir.rb +331 -0
  66. data/lib/active_merchant/billing/gateways/dibs.rb +199 -0
  67. data/lib/active_merchant/billing/gateways/digitzs.rb +295 -0
  68. data/lib/active_merchant/billing/gateways/ebanx.rb +333 -0
  69. data/lib/active_merchant/billing/gateways/efsnet.rb +215 -0
  70. data/lib/active_merchant/billing/gateways/elavon.rb +472 -0
  71. data/lib/active_merchant/billing/gateways/element.rb +386 -0
  72. data/lib/active_merchant/billing/gateways/epay.rb +296 -0
  73. data/lib/active_merchant/billing/gateways/evo_ca.rb +307 -0
  74. data/lib/active_merchant/billing/gateways/eway.rb +226 -0
  75. data/lib/active_merchant/billing/gateways/eway_managed.rb +289 -0
  76. data/lib/active_merchant/billing/gateways/eway_rapid.rb +578 -0
  77. data/lib/active_merchant/billing/gateways/exact.rb +219 -0
  78. data/lib/active_merchant/billing/gateways/ezic.rb +195 -0
  79. data/lib/active_merchant/billing/gateways/fat_zebra.rb +223 -0
  80. data/lib/active_merchant/billing/gateways/federated_canada.rb +158 -0
  81. data/lib/active_merchant/billing/gateways/finansbank.rb +22 -0
  82. data/lib/active_merchant/billing/gateways/first_giving.rb +143 -0
  83. data/lib/active_merchant/billing/gateways/first_pay.rb +182 -0
  84. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +452 -0
  85. data/lib/active_merchant/billing/gateways/firstdata_e4_v27.rb +505 -0
  86. data/lib/active_merchant/billing/gateways/flo2cash.rb +215 -0
  87. data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +20 -0
  88. data/lib/active_merchant/billing/gateways/forte.rb +286 -0
  89. data/lib/active_merchant/billing/gateways/garanti.rb +256 -0
  90. data/lib/active_merchant/billing/gateways/global_collect.rb +463 -0
  91. data/lib/active_merchant/billing/gateways/global_transport.rb +193 -0
  92. data/lib/active_merchant/billing/gateways/hdfc.rb +205 -0
  93. data/lib/active_merchant/billing/gateways/hps.rb +472 -0
  94. data/lib/active_merchant/billing/gateways/iats_payments.rb +312 -0
  95. data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +15 -0
  96. data/lib/active_merchant/billing/gateways/inspire.rb +213 -0
  97. data/lib/active_merchant/billing/gateways/instapay.rb +159 -0
  98. data/lib/active_merchant/billing/gateways/ipg.rb +390 -0
  99. data/lib/active_merchant/billing/gateways/ipp.rb +176 -0
  100. data/lib/active_merchant/billing/gateways/iridium.rb +467 -0
  101. data/lib/active_merchant/billing/gateways/itransact.rb +448 -0
  102. data/lib/active_merchant/billing/gateways/iveri.rb +254 -0
  103. data/lib/active_merchant/billing/gateways/ixopay.rb +320 -0
  104. data/lib/active_merchant/billing/gateways/jetpay.rb +395 -0
  105. data/lib/active_merchant/billing/gateways/jetpay_v2.rb +432 -0
  106. data/lib/active_merchant/billing/gateways/komoju.rb +115 -0
  107. data/lib/active_merchant/billing/gateways/kushki.rb +270 -0
  108. data/lib/active_merchant/billing/gateways/latitude19.rb +412 -0
  109. data/lib/active_merchant/billing/gateways/linkpoint.rb +448 -0
  110. data/lib/active_merchant/billing/gateways/litle.rb +531 -0
  111. data/lib/active_merchant/billing/gateways/mastercard.rb +293 -0
  112. data/lib/active_merchant/billing/gateways/maxipago.rb +220 -0
  113. data/lib/active_merchant/billing/gateways/mercado_pago.rb +329 -0
  114. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +194 -0
  115. data/lib/active_merchant/billing/gateways/merchant_one.rb +110 -0
  116. data/lib/active_merchant/billing/gateways/merchant_partners.rb +245 -0
  117. data/lib/active_merchant/billing/gateways/merchant_ware.rb +313 -0
  118. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +284 -0
  119. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +248 -0
  120. data/lib/active_merchant/billing/gateways/mercury.rb +352 -0
  121. data/lib/active_merchant/billing/gateways/metrics_global.rb +293 -0
  122. data/lib/active_merchant/billing/gateways/micropayment.rb +182 -0
  123. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  124. data/lib/active_merchant/billing/gateways/migs.rb +329 -0
  125. data/lib/active_merchant/billing/gateways/mit.rb +260 -0
  126. data/lib/active_merchant/billing/gateways/modern_payments.rb +37 -0
  127. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +215 -0
  128. data/lib/active_merchant/billing/gateways/moka.rb +290 -0
  129. data/lib/active_merchant/billing/gateways/monei.rb +422 -0
  130. data/lib/active_merchant/billing/gateways/moneris.rb +446 -0
  131. data/lib/active_merchant/billing/gateways/money_movers.rb +150 -0
  132. data/lib/active_merchant/billing/gateways/mundipagg.rb +363 -0
  133. data/lib/active_merchant/billing/gateways/nab_transact.rb +299 -0
  134. data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +163 -0
  135. data/lib/active_merchant/billing/gateways/net_registry.rb +198 -0
  136. data/lib/active_merchant/billing/gateways/netaxept.rb +180 -0
  137. data/lib/active_merchant/billing/gateways/netbanx.rb +376 -0
  138. data/lib/active_merchant/billing/gateways/netbilling.rb +229 -0
  139. data/lib/active_merchant/billing/gateways/netpay.rb +223 -0
  140. data/lib/active_merchant/billing/gateways/network_merchants.rb +238 -0
  141. data/lib/active_merchant/billing/gateways/nmi.rb +356 -0
  142. data/lib/active_merchant/billing/gateways/ogone.rb +481 -0
  143. data/lib/active_merchant/billing/gateways/omise.rb +323 -0
  144. data/lib/active_merchant/billing/gateways/openpay.rb +229 -0
  145. data/lib/active_merchant/billing/gateways/opp.rb +394 -0
  146. data/lib/active_merchant/billing/gateways/optimal_payment.rb +331 -0
  147. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +45 -0
  148. data/lib/active_merchant/billing/gateways/orbital.rb +1209 -0
  149. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +206 -0
  150. data/lib/active_merchant/billing/gateways/pagarme.rb +239 -0
  151. data/lib/active_merchant/billing/gateways/pago_facil.rb +120 -0
  152. data/lib/active_merchant/billing/gateways/pay_arc.rb +392 -0
  153. data/lib/active_merchant/billing/gateways/pay_conex.rb +245 -0
  154. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +277 -0
  155. data/lib/active_merchant/billing/gateways/pay_hub.rb +213 -0
  156. data/lib/active_merchant/billing/gateways/pay_junction.rb +390 -0
  157. data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +206 -0
  158. data/lib/active_merchant/billing/gateways/pay_secure.rb +110 -0
  159. data/lib/active_merchant/billing/gateways/pay_trace.rb +404 -0
  160. data/lib/active_merchant/billing/gateways/paybox_direct.rb +224 -0
  161. data/lib/active_merchant/billing/gateways/payeezy.rb +458 -0
  162. data/lib/active_merchant/billing/gateways/payex.rb +409 -0
  163. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +235 -0
  164. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +42 -0
  165. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  166. data/lib/active_merchant/billing/gateways/payflow.rb +411 -0
  167. data/lib/active_merchant/billing/gateways/payflow_express.rb +220 -0
  168. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +14 -0
  169. data/lib/active_merchant/billing/gateways/payflow_uk.rb +20 -0
  170. data/lib/active_merchant/billing/gateways/payment_express.rb +373 -0
  171. data/lib/active_merchant/billing/gateways/paymentez.rb +327 -0
  172. data/lib/active_merchant/billing/gateways/paymill.rb +369 -0
  173. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +718 -0
  174. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +65 -0
  175. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +262 -0
  176. data/lib/active_merchant/billing/gateways/paypal.rb +136 -0
  177. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  178. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +44 -0
  179. data/lib/active_merchant/billing/gateways/paypal_express.rb +270 -0
  180. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  181. data/lib/active_merchant/billing/gateways/paysafe.rb +412 -0
  182. data/lib/active_merchant/billing/gateways/payscout.rb +159 -0
  183. data/lib/active_merchant/billing/gateways/paystation.rb +204 -0
  184. data/lib/active_merchant/billing/gateways/payu_in.rb +249 -0
  185. data/lib/active_merchant/billing/gateways/payu_latam.rb +469 -0
  186. data/lib/active_merchant/billing/gateways/payu_polska.rb +178 -0
  187. data/lib/active_merchant/billing/gateways/payway.rb +207 -0
  188. data/lib/active_merchant/billing/gateways/payway_dot_com.rb +253 -0
  189. data/lib/active_merchant/billing/gateways/pin.rb +246 -0
  190. data/lib/active_merchant/billing/gateways/plugnpay.rb +283 -0
  191. data/lib/active_merchant/billing/gateways/priority.rb +390 -0
  192. data/lib/active_merchant/billing/gateways/pro_pay.rb +325 -0
  193. data/lib/active_merchant/billing/gateways/psigate.rb +227 -0
  194. data/lib/active_merchant/billing/gateways/psl_card.rb +295 -0
  195. data/lib/active_merchant/billing/gateways/qbms.rb +302 -0
  196. data/lib/active_merchant/billing/gateways/quantum.rb +274 -0
  197. data/lib/active_merchant/billing/gateways/quickbooks.rb +377 -0
  198. data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +184 -0
  199. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +297 -0
  200. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +226 -0
  201. data/lib/active_merchant/billing/gateways/quickpay.rb +24 -0
  202. data/lib/active_merchant/billing/gateways/qvalent.rb +305 -0
  203. data/lib/active_merchant/billing/gateways/realex.rb +400 -0
  204. data/lib/active_merchant/billing/gateways/redsys.rb +718 -0
  205. data/lib/active_merchant/billing/gateways/s5.rb +247 -0
  206. data/lib/active_merchant/billing/gateways/safe_charge.rb +301 -0
  207. data/lib/active_merchant/billing/gateways/sage.rb +446 -0
  208. data/lib/active_merchant/billing/gateways/sage_pay.rb +434 -0
  209. data/lib/active_merchant/billing/gateways/sallie_mae.rb +141 -0
  210. data/lib/active_merchant/billing/gateways/secure_net.rb +260 -0
  211. data/lib/active_merchant/billing/gateways/secure_pay.rb +191 -0
  212. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +290 -0
  213. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +103 -0
  214. data/lib/active_merchant/billing/gateways/securion_pay.rb +265 -0
  215. data/lib/active_merchant/billing/gateways/skip_jack.rb +450 -0
  216. data/lib/active_merchant/billing/gateways/smart_ps.rb +274 -0
  217. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
  218. data/lib/active_merchant/billing/gateways/spreedly_core.rb +312 -0
  219. data/lib/active_merchant/billing/gateways/stripe.rb +813 -0
  220. data/lib/active_merchant/billing/gateways/stripe_payment_intents.rb +463 -0
  221. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +151 -0
  222. data/lib/active_merchant/billing/gateways/telr.rb +273 -0
  223. data/lib/active_merchant/billing/gateways/tns.rb +26 -0
  224. data/lib/active_merchant/billing/gateways/trans_first.rb +240 -0
  225. data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +612 -0
  226. data/lib/active_merchant/billing/gateways/transact_pro.rb +222 -0
  227. data/lib/active_merchant/billing/gateways/transax.rb +21 -0
  228. data/lib/active_merchant/billing/gateways/transnational.rb +9 -0
  229. data/lib/active_merchant/billing/gateways/trexle.rb +221 -0
  230. data/lib/active_merchant/billing/gateways/trust_commerce.rb +489 -0
  231. data/lib/active_merchant/billing/gateways/usa_epay.rb +24 -0
  232. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1612 -0
  233. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +353 -0
  234. data/lib/active_merchant/billing/gateways/vanco.rb +294 -0
  235. data/lib/active_merchant/billing/gateways/verifi.rb +224 -0
  236. data/lib/active_merchant/billing/gateways/viaklix.rb +171 -0
  237. data/lib/active_merchant/billing/gateways/visanet_peru.rb +246 -0
  238. data/lib/active_merchant/billing/gateways/vpos.rb +220 -0
  239. data/lib/active_merchant/billing/gateways/webpay.rb +97 -0
  240. data/lib/active_merchant/billing/gateways/wepay.rb +235 -0
  241. data/lib/active_merchant/billing/gateways/wirecard.rb +430 -0
  242. data/lib/active_merchant/billing/gateways/wompi.rb +153 -0
  243. data/lib/active_merchant/billing/gateways/world_net.rb +345 -0
  244. data/lib/active_merchant/billing/gateways/worldpay.rb +923 -0
  245. data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +208 -0
  246. data/lib/active_merchant/billing/gateways/worldpay_us.rb +221 -0
  247. data/lib/active_merchant/billing/gateways.rb +14 -0
  248. data/lib/active_merchant/billing/model.rb +30 -0
  249. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +39 -0
  250. data/lib/active_merchant/billing/payment_token.rb +21 -0
  251. data/lib/active_merchant/billing/rails.rb +3 -0
  252. data/lib/active_merchant/billing/response.rb +97 -0
  253. data/lib/active_merchant/billing/three_d_secure_eci_mapper.rb +27 -0
  254. data/lib/active_merchant/billing.rb +16 -0
  255. data/lib/active_merchant/connection.rb +196 -0
  256. data/lib/active_merchant/country.rb +337 -0
  257. data/lib/active_merchant/empty.rb +20 -0
  258. data/lib/active_merchant/errors.rb +35 -0
  259. data/lib/active_merchant/net_http_ssl_connection.rb +11 -0
  260. data/lib/active_merchant/network_connection_retries.rb +78 -0
  261. data/lib/active_merchant/post_data.rb +26 -0
  262. data/lib/active_merchant/posts_data.rb +92 -0
  263. data/lib/active_merchant/version.rb +3 -0
  264. data/lib/active_merchant.rb +63 -0
  265. data/lib/activemerchant.rb +1 -0
  266. data/lib/certs/cacert.pem +3214 -0
  267. data/lib/support/gateway_support.rb +69 -0
  268. data/lib/support/outbound_hosts.rb +28 -0
  269. data/lib/support/ssl_verify.rb +88 -0
  270. data/lib/support/ssl_version.rb +86 -0
  271. metadata +463 -0
@@ -0,0 +1,446 @@
1
+ require 'rexml/document'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ # To learn more about the Moneris gateway, please contact
6
+ # eselectplus@moneris.com for a copy of their integration guide. For
7
+ # information on remote testing, please see "Test Environment Penny Value
8
+ # Response Table", and "Test Environment eFraud (AVS and CVD) Penny
9
+ # Response Values", available at Moneris' {eSelect Plus Documentation
10
+ # Centre}[https://www3.moneris.com/connect/en/documents/index.html].
11
+ class MonerisGateway < Gateway
12
+ self.test_url = 'https://esqa.moneris.com/gateway2/servlet/MpgRequest'
13
+ self.live_url = 'https://www3.moneris.com/gateway2/servlet/MpgRequest'
14
+
15
+ self.supported_countries = ['CA']
16
+ self.supported_cardtypes = %i[visa master american_express diners_club discover]
17
+ self.homepage_url = 'http://www.moneris.com/'
18
+ self.display_name = 'Moneris'
19
+
20
+ # Initialize the Gateway
21
+ #
22
+ # The gateway requires that a valid login and password be passed
23
+ # in the +options+ hash.
24
+ #
25
+ # ==== Options
26
+ #
27
+ # * <tt>:login</tt> -- Your Store ID
28
+ # * <tt>:password</tt> -- Your API Token
29
+ # * <tt>:cvv_enabled</tt> -- Specify that you would like the CVV passed to the gateway.
30
+ # Only particular account types at Moneris will allow this.
31
+ # Defaults to false. (optional)
32
+ def initialize(options = {})
33
+ requires!(options, :login, :password)
34
+ @cvv_enabled = options[:cvv_enabled]
35
+ @avs_enabled = options[:avs_enabled]
36
+ options[:crypt_type] = 7 unless options.has_key?(:crypt_type)
37
+ super
38
+ end
39
+
40
+ # Referred to as "PreAuth" in the Moneris integration guide, this action
41
+ # verifies and locks funds on a customer's card, which then must be
42
+ # captured at a later date.
43
+ #
44
+ # Pass in +order_id+ and optionally a +customer+ parameter.
45
+ def authorize(money, creditcard_or_datakey, options = {})
46
+ requires!(options, :order_id)
47
+ post = {}
48
+ add_payment_source(post, creditcard_or_datakey, options)
49
+ post[:amount] = amount(money)
50
+ post[:order_id] = options[:order_id]
51
+ post[:address] = options[:billing_address] || options[:address]
52
+ post[:crypt_type] = options[:crypt_type] || @options[:crypt_type]
53
+ add_stored_credential(post, options)
54
+ action = if post[:cavv]
55
+ 'cavv_preauth'
56
+ elsif post[:data_key].blank?
57
+ 'preauth'
58
+ else
59
+ 'res_preauth_cc'
60
+ end
61
+ commit(action, post)
62
+ end
63
+
64
+ # This action verifies funding on a customer's card and readies them for
65
+ # deposit in a merchant's account.
66
+ #
67
+ # Pass in <tt>order_id</tt> and optionally a <tt>customer</tt> parameter
68
+ def purchase(money, creditcard_or_datakey, options = {})
69
+ requires!(options, :order_id)
70
+ post = {}
71
+ add_payment_source(post, creditcard_or_datakey, options)
72
+ post[:amount] = amount(money)
73
+ post[:order_id] = options[:order_id]
74
+ post[:address] = options[:billing_address] || options[:address]
75
+ post[:crypt_type] = options[:crypt_type] || @options[:crypt_type]
76
+ add_stored_credential(post, options)
77
+ action = if post[:cavv]
78
+ 'cavv_purchase'
79
+ elsif post[:data_key].blank?
80
+ 'purchase'
81
+ else
82
+ 'res_purchase_cc'
83
+ end
84
+ commit(action, post)
85
+ end
86
+
87
+ # This method retrieves locked funds from a customer's account (from a
88
+ # PreAuth) and prepares them for deposit in a merchant's account.
89
+ #
90
+ # Note: Moneris requires both the order_id and the transaction number of
91
+ # the original authorization. To maintain the same interface as the other
92
+ # gateways the two numbers are concatenated together with a ; separator as
93
+ # the authorization number returned by authorization
94
+ def capture(money, authorization, options = {})
95
+ commit 'completion', crediting_params(authorization, comp_amount: amount(money))
96
+ end
97
+
98
+ # Voiding requires the original transaction ID and order ID of some open
99
+ # transaction. Closed transactions must be refunded.
100
+ #
101
+ # Moneris supports the voiding of an unsettled capture or purchase via
102
+ # its <tt>purchasecorrection</tt> command. This action can only occur
103
+ # on the same day as the capture/purchase prior to 22:00-23:00 EST. If
104
+ # you want to do this, pass <tt>:purchasecorrection => true</tt> as
105
+ # an option.
106
+ #
107
+ # Fun, Historical Trivia:
108
+ # Voiding an authorization in Moneris is a relatively new feature
109
+ # (September, 2011). It is actually done by doing a $0 capture.
110
+ #
111
+ # Concatenate your transaction number and order_id by using a semicolon
112
+ # (';'). This is to keep the Moneris interface consistent with other
113
+ # gateways. (See +capture+ for details.)
114
+ def void(authorization, options = {})
115
+ if options[:purchasecorrection]
116
+ commit 'purchasecorrection', crediting_params(authorization)
117
+ else
118
+ capture(0, authorization, options)
119
+ end
120
+ end
121
+
122
+ # Performs a refund. This method requires that the original transaction
123
+ # number and order number be included. Concatenate your transaction
124
+ # number and order_id by using a semicolon (';'). This is to keep the
125
+ # Moneris interface consistent with other gateways. (See +capture+ for
126
+ # details.)
127
+ def credit(money, authorization, options = {})
128
+ ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
129
+ refund(money, authorization, options)
130
+ end
131
+
132
+ def refund(money, authorization, options = {})
133
+ commit 'refund', crediting_params(authorization, amount: amount(money))
134
+ end
135
+
136
+ def verify(credit_card, options = {})
137
+ requires!(options, :order_id)
138
+ post = {}
139
+ add_payment_source(post, credit_card, options)
140
+ post[:order_id] = options[:order_id]
141
+ post[:address] = options[:billing_address] || options[:address]
142
+ post[:crypt_type] = options[:crypt_type] || @options[:crypt_type]
143
+ add_stored_credential(post, options)
144
+ action = if post[:data_key].blank?
145
+ 'card_verification'
146
+ else
147
+ 'res_card_verification_cc'
148
+ end
149
+ commit(action, post)
150
+ end
151
+
152
+ # When passing a :duration option (time in seconds) you can create a
153
+ # temporary vault record to avoid incurring Moneris vault storage fees
154
+ #
155
+ # https://developer.moneris.com/Documentation/NA/E-Commerce%20Solutions/API/Vault#vaulttokenadd
156
+ def store(credit_card, options = {})
157
+ post = {}
158
+ post[:pan] = credit_card.number
159
+ post[:expdate] = expdate(credit_card)
160
+ post[:address] = options[:billing_address] || options[:address]
161
+ post[:crypt_type] = options[:crypt_type] || @options[:crypt_type]
162
+ add_stored_credential(post, options)
163
+
164
+ if options[:duration]
165
+ post[:duration] = options[:duration]
166
+ commit('res_temp_add', post)
167
+ else
168
+ commit('res_add_cc', post)
169
+ end
170
+ end
171
+
172
+ def unstore(data_key, options = {})
173
+ post = {}
174
+ post[:data_key] = data_key
175
+ commit('res_delete', post)
176
+ end
177
+
178
+ def update(data_key, credit_card, options = {})
179
+ post = {}
180
+ post[:pan] = credit_card.number
181
+ post[:expdate] = expdate(credit_card)
182
+ post[:data_key] = data_key
183
+ post[:crypt_type] = options[:crypt_type] || @options[:crypt_type]
184
+ commit('res_update_cc', post)
185
+ end
186
+
187
+ def supports_scrubbing?
188
+ true
189
+ end
190
+
191
+ def scrub(transcript)
192
+ transcript.
193
+ gsub(%r((<store_id>).+(</store_id>)), '\1[FILTERED]\2').
194
+ gsub(%r((<api_token>).+(</api_token>)), '\1[FILTERED]\2').
195
+ gsub(%r((<pan>).+(</pan>)), '\1[FILTERED]\2').
196
+ gsub(%r((<cvd_value>).+(</cvd_value>)), '\1[FILTERED]\2').
197
+ gsub(%r((<cavv>).+(</cavv>)), '\1[FILTERED]\2')
198
+ end
199
+
200
+ private # :nodoc: all
201
+
202
+ def expdate(creditcard)
203
+ sprintf('%.4i', creditcard.year)[-2..-1] + sprintf('%.2i', creditcard.month)
204
+ end
205
+
206
+ def add_payment_source(post, payment_method, options)
207
+ if payment_method.is_a?(String)
208
+ post[:data_key] = payment_method
209
+ post[:cust_id] = options[:customer]
210
+ else
211
+ if payment_method.respond_to?(:track_data) && payment_method.track_data.present?
212
+ post[:pos_code] = '00'
213
+ post[:track2] = payment_method.track_data
214
+ else
215
+ post[:pan] = payment_method.number
216
+ post[:expdate] = expdate(payment_method)
217
+ post[:cvd_value] = payment_method.verification_value if payment_method.verification_value?
218
+ post[:cavv] = payment_method.payment_cryptogram if payment_method.is_a?(NetworkTokenizationCreditCard)
219
+ post[:wallet_indicator] = wallet_indicator(payment_method.source.to_s) if payment_method.is_a?(NetworkTokenizationCreditCard)
220
+ post[:crypt_type] = (payment_method.eci || 7) if payment_method.is_a?(NetworkTokenizationCreditCard)
221
+ end
222
+ post[:cust_id] = options[:customer] || payment_method.name
223
+ end
224
+ end
225
+
226
+ def add_cof(post, options)
227
+ post[:issuer_id] = options[:issuer_id] if options[:issuer_id]
228
+ post[:payment_indicator] = options[:payment_indicator] if options[:payment_indicator]
229
+ post[:payment_information] = options[:payment_information] if options[:payment_information]
230
+ end
231
+
232
+ def add_stored_credential(post, options)
233
+ add_cof(post, options)
234
+ # if any of :issuer_id, :payment_information, or :payment_indicator is not passed,
235
+ # then check for :stored credential options
236
+ return unless (stored_credential = options[:stored_credential]) && !cof_details_present?(options)
237
+
238
+ if stored_credential[:initial_transaction]
239
+ add_stored_credential_initial(post, options)
240
+ else
241
+ add_stored_credential_used(post, options)
242
+ end
243
+ end
244
+
245
+ def add_stored_credential_initial(post, options)
246
+ post[:payment_information] ||= '0'
247
+ post[:issuer_id] ||= ''
248
+ if options[:stored_credential][:initiator] == 'merchant'
249
+ case options[:stored_credential][:reason_type]
250
+ when 'recurring', 'installment'
251
+ post[:payment_indicator] ||= 'R'
252
+ when 'unscheduled'
253
+ post[:payment_indicator] ||= 'C'
254
+ end
255
+ else
256
+ post[:payment_indicator] ||= 'C'
257
+ end
258
+ end
259
+
260
+ def add_stored_credential_used(post, options)
261
+ post[:payment_information] ||= '2'
262
+ post[:issuer_id] = options[:stored_credential][:network_transaction_id] if options[:issuer_id].blank?
263
+ if options[:stored_credential][:initiator] == 'merchant'
264
+ case options[:stored_credential][:reason_type]
265
+ when 'recurring', 'installment'
266
+ post[:payment_indicator] ||= 'R'
267
+ when '', 'unscheduled'
268
+ post[:payment_indicator] ||= 'U'
269
+ end
270
+ else
271
+ post[:payment_indicator] ||= 'Z'
272
+ end
273
+ end
274
+
275
+ # Common params used amongst the +credit+, +void+ and +capture+ methods
276
+ def crediting_params(authorization, options = {})
277
+ {
278
+ txn_number: split_authorization(authorization).first,
279
+ order_id: split_authorization(authorization).last,
280
+ crypt_type: options[:crypt_type] || @options[:crypt_type]
281
+ }.merge(options)
282
+ end
283
+
284
+ # Splits an +authorization+ param and retrieves the order id and
285
+ # transaction number in that order.
286
+ def split_authorization(authorization)
287
+ if authorization.nil? || authorization.empty? || authorization !~ /;/
288
+ raise ArgumentError, 'You must include a valid authorization code (e.g. "1234;567")'
289
+ else
290
+ authorization.split(';')
291
+ end
292
+ end
293
+
294
+ def commit(action, parameters = {})
295
+ data = post_data(action, parameters)
296
+ url = test? ? self.test_url : self.live_url
297
+ raw = ssl_post(url, data)
298
+ response = parse(raw)
299
+
300
+ Response.new(
301
+ successful?(response),
302
+ message_from(response[:message]),
303
+ response,
304
+ test: test?,
305
+ avs_result: { code: response[:avs_result_code] },
306
+ cvv_result: response[:cvd_result_code] && response[:cvd_result_code][-1, 1],
307
+ authorization: authorization_from(response)
308
+ )
309
+ end
310
+
311
+ # Generates a Moneris authorization string of the form 'trans_id;receipt_id'.
312
+ def authorization_from(response = {})
313
+ "#{response[:trans_id]};#{response[:receipt_id]}" if response[:trans_id] && response[:receipt_id]
314
+ end
315
+
316
+ # Tests for a successful response from Moneris' servers
317
+ def successful?(response)
318
+ response[:response_code] &&
319
+ response[:complete] &&
320
+ (0..49).cover?(response[:response_code].to_i)
321
+ end
322
+
323
+ def parse(xml)
324
+ response = { message: 'Global Error Receipt', complete: false }
325
+ hashify_xml!(xml, response)
326
+ response
327
+ end
328
+
329
+ def hashify_xml!(xml, response)
330
+ xml = REXML::Document.new(xml)
331
+ return if xml.root.nil?
332
+
333
+ xml.elements.each('//receipt/*') do |node|
334
+ response[node.name.underscore.to_sym] = normalize(node.text)
335
+ end
336
+ end
337
+
338
+ def post_data(action, parameters = {})
339
+ xml = REXML::Document.new
340
+ root = xml.add_element('request')
341
+ root.add_element('store_id').text = options[:login]
342
+ root.add_element('api_token').text = options[:password]
343
+ root.add_element(transaction_element(action, parameters))
344
+
345
+ xml.to_s
346
+ end
347
+
348
+ def transaction_element(action, parameters)
349
+ transaction = REXML::Element.new(action)
350
+
351
+ # Must add the elements in the correct order
352
+ actions[action].each do |key|
353
+ case key
354
+ when :avs_info
355
+ transaction.add_element(avs_element(parameters[:address])) if @avs_enabled && parameters[:address]
356
+ when :cvd_info
357
+ transaction.add_element(cvd_element(parameters[:cvd_value])) if @cvv_enabled
358
+ when :cof_info
359
+ transaction.add_element(credential_on_file(parameters)) if cof_details_present?(parameters)
360
+ else
361
+ transaction.add_element(key.to_s).text = parameters[key] unless parameters[key].blank?
362
+ end
363
+ end
364
+
365
+ transaction
366
+ end
367
+
368
+ def avs_element(address)
369
+ full_address = "#{address[:address1]} #{address[:address2]}"
370
+ tokens = full_address.split(/\s+/)
371
+
372
+ element = REXML::Element.new('avs_info')
373
+ element.add_element('avs_street_number').text = tokens.select { |x| x =~ /\d/ }.join(' ')
374
+ element.add_element('avs_street_name').text = tokens.reject { |x| x =~ /\d/ }.join(' ')
375
+ element.add_element('avs_zipcode').text = address[:zip]
376
+ element
377
+ end
378
+
379
+ def cvd_element(cvd_value)
380
+ element = REXML::Element.new('cvd_info')
381
+ if cvd_value
382
+ element.add_element('cvd_indicator').text = '1'
383
+ element.add_element('cvd_value').text = cvd_value
384
+ else
385
+ element.add_element('cvd_indicator').text = '0'
386
+ end
387
+ element
388
+ end
389
+
390
+ def cof_details_present?(parameters)
391
+ parameters[:issuer_id] && parameters[:payment_indicator] && parameters[:payment_information]
392
+ end
393
+
394
+ def credential_on_file(parameters)
395
+ issuer_id = parameters[:issuer_id]
396
+ payment_indicator = parameters[:payment_indicator]
397
+ payment_information = parameters[:payment_information]
398
+
399
+ cof_info = REXML::Element.new('cof_info')
400
+ cof_info.add_element('issuer_id').text = issuer_id
401
+ cof_info.add_element('payment_indicator').text = payment_indicator
402
+ cof_info.add_element('payment_information').text = payment_information
403
+ cof_info
404
+ end
405
+
406
+ def wallet_indicator(token_source)
407
+ return 'APP' if token_source == 'apple_pay'
408
+ return 'ANP' if token_source == 'android_pay'
409
+
410
+ nil
411
+ end
412
+
413
+ def message_from(message)
414
+ return 'Unspecified error' if message.blank?
415
+
416
+ message.gsub(/[^\w]/, ' ').split.join(' ').capitalize
417
+ end
418
+
419
+ def actions
420
+ {
421
+ 'purchase' => %i[order_id cust_id amount pan expdate crypt_type avs_info cvd_info track2 pos_code cof_info],
422
+ 'preauth' => %i[order_id cust_id amount pan expdate crypt_type avs_info cvd_info track2 pos_code cof_info],
423
+ 'command' => [:order_id],
424
+ 'refund' => %i[order_id amount txn_number crypt_type],
425
+ 'indrefund' => %i[order_id cust_id amount pan expdate crypt_type],
426
+ 'completion' => %i[order_id comp_amount txn_number crypt_type],
427
+ 'purchasecorrection' => %i[order_id txn_number crypt_type],
428
+ 'cavv_preauth' => %i[order_id cust_id amount pan expdate cavv crypt_type wallet_indicator],
429
+ 'cavv_purchase' => %i[order_id cust_id amount pan expdate cavv crypt_type wallet_indicator],
430
+ 'card_verification' => %i[order_id cust_id pan expdate crypt_type avs_info cvd_info cof_info],
431
+ 'transact' => %i[order_id cust_id amount pan expdate crypt_type],
432
+ 'Batchcloseall' => [],
433
+ 'opentotals' => [:ecr_number],
434
+ 'batchclose' => [:ecr_number],
435
+ 'res_add_cc' => %i[pan expdate crypt_type avs_info cof_info],
436
+ 'res_temp_add' => %i[pan expdate crypt_type duration],
437
+ 'res_delete' => [:data_key],
438
+ 'res_update_cc' => %i[data_key pan expdate crypt_type avs_info cof_info],
439
+ 'res_purchase_cc' => %i[data_key order_id cust_id amount crypt_type cof_info],
440
+ 'res_preauth_cc' => %i[data_key order_id cust_id amount crypt_type cof_info],
441
+ 'res_card_verification_cc' => %i[order_id data_key expdate crypt_type cof_info]
442
+ }
443
+ end
444
+ end
445
+ end
446
+ end
@@ -0,0 +1,150 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class MoneyMoversGateway < Gateway
4
+ self.live_url = self.test_url = 'https://secure.mmoagateway.com/api/transact.php'
5
+
6
+ APPROVED, DECLINED, ERROR = 1, 2, 3
7
+
8
+ self.homepage_url = 'http://mmoa.us/'
9
+ self.display_name = 'MoneyMovers'
10
+ self.supported_countries = ['US']
11
+ self.supported_cardtypes = %i[visa master american_express discover]
12
+
13
+ def initialize(options = {})
14
+ requires!(options, :login, :password)
15
+ @options = options
16
+ super
17
+ end
18
+
19
+ def purchase(money, creditcard, options = {})
20
+ post = {}
21
+ add_invoice(post, options)
22
+ add_creditcard(post, creditcard)
23
+ add_address(post, options)
24
+ add_customer_data(post, options)
25
+ commit('sale', money, post)
26
+ end
27
+
28
+ def authorize(money, creditcard, options = {})
29
+ post = {}
30
+ add_invoice(post, options)
31
+ add_creditcard(post, creditcard)
32
+ add_address(post, options)
33
+ add_customer_data(post, options)
34
+ commit('auth', money, post)
35
+ end
36
+
37
+ def capture(money, authorization, options = {})
38
+ options[:transactionid] = authorization
39
+ commit('capture', money, options)
40
+ end
41
+
42
+ def void(authorization, options = {})
43
+ options[:transactionid] = authorization
44
+ commit('void', nil, options)
45
+ end
46
+
47
+ def refund(money, authorization, options = {})
48
+ commit('refund', money, options.merge(transactionid: authorization))
49
+ end
50
+
51
+ def credit(money, authorization, options = {})
52
+ ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
53
+ refund(money, authorization, options)
54
+ end
55
+
56
+ private
57
+
58
+ def add_customer_data(post, options)
59
+ post[:firstname] = options[:first_name]
60
+ post[:lastname] = options[:last_name]
61
+
62
+ post[:email] = options[:email]
63
+ end
64
+
65
+ def add_address(post, options)
66
+ if address = (options[:billing_address] || options[:address])
67
+ post[:company] = address[:company]
68
+ post[:address1] = address[:address1]
69
+ post[:address2] = address[:address2]
70
+ post[:city] = address[:city]
71
+ post[:state] = address[:state]
72
+ post[:zip] = address[:zip]
73
+ post[:country] = address[:country]
74
+ post[:phone] = address[:phone]
75
+ end
76
+ if address = options[:shipping_address]
77
+ post[:shipping_firstname] = address[:first_name]
78
+ post[:shipping_lastname] = address[:last_name]
79
+ post[:shipping_company] = address[:company]
80
+ post[:shipping_address1] = address[:address1]
81
+ post[:shipping_address2] = address[:address2]
82
+ post[:shipping_city] = address[:city]
83
+ post[:shipping_state] = address[:state]
84
+ post[:shipping_zip] = address[:zip]
85
+ post[:shipping_country] = address[:country]
86
+ post[:shipping_email] = address[:email]
87
+ end
88
+ end
89
+
90
+ def add_invoice(post, options)
91
+ post[:orderid] = options[:order_id]
92
+ post[:orderdescription] = options[:description]
93
+ end
94
+
95
+ def add_creditcard(post, creditcard)
96
+ post[:ccnumber] = creditcard.number
97
+ post[:ccexp] = expdate(creditcard)
98
+ post[:cvv] = creditcard.verification_value
99
+ end
100
+
101
+ def parse(body)
102
+ body.split('&').inject({}) do |memo, x|
103
+ k, v = x.split('=')
104
+ memo[k] = v
105
+ memo
106
+ end
107
+ end
108
+
109
+ def commit(action, money, parameters)
110
+ parameters[:amount] = amount(money)
111
+
112
+ data = ssl_post(self.live_url, post_data(action, parameters))
113
+ response = parse(data)
114
+ message = message_from(response)
115
+
116
+ Response.new(success?(response), message, response,
117
+ test: test?,
118
+ authorization: response['transactionid'],
119
+ avs_result: { code: response['avsresponse'] },
120
+ cvv_result: response['cvvresponse'])
121
+ end
122
+
123
+ def success?(response)
124
+ response['response'] == '1'
125
+ end
126
+
127
+ def test?
128
+ @options[:login].eql?('demo') && @options[:password].eql?('password')
129
+ end
130
+
131
+ def message_from(response)
132
+ case response['response'].to_i
133
+ when APPROVED
134
+ 'Transaction Approved'
135
+ when DECLINED
136
+ 'Transaction Declined'
137
+ else
138
+ 'Error in transaction data or system error'
139
+ end
140
+ end
141
+
142
+ def post_data(action, parameters = {})
143
+ parameters[:type] = action
144
+ parameters[:username] = @options[:login]
145
+ parameters[:password] = @options[:password]
146
+ parameters.map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&')
147
+ end
148
+ end
149
+ end
150
+ end