jelaniharris-activemerchant 1.24.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. data/CHANGELOG +893 -0
  2. data/CONTRIBUTORS +307 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +196 -0
  5. data/gem-public_cert.pem +20 -0
  6. data/lib/active_merchant.rb +63 -0
  7. data/lib/active_merchant/billing.rb +9 -0
  8. data/lib/active_merchant/billing/avs_result.rb +98 -0
  9. data/lib/active_merchant/billing/base.rb +57 -0
  10. data/lib/active_merchant/billing/check.rb +68 -0
  11. data/lib/active_merchant/billing/credit_card.rb +274 -0
  12. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  13. data/lib/active_merchant/billing/credit_card_methods.rb +143 -0
  14. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  15. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  16. data/lib/active_merchant/billing/gateway.rb +170 -0
  17. data/lib/active_merchant/billing/gateways.rb +18 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net.rb +694 -0
  19. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +946 -0
  20. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +308 -0
  21. data/lib/active_merchant/billing/gateways/beanstream.rb +167 -0
  22. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +388 -0
  23. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  24. data/lib/active_merchant/billing/gateways/blue_pay.rb +492 -0
  25. data/lib/active_merchant/billing/gateways/bogus.rb +142 -0
  26. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  27. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  28. data/lib/active_merchant/billing/gateways/braintree_blue.rb +335 -0
  29. data/lib/active_merchant/billing/gateways/braintree_orange.rb +21 -0
  30. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  31. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  32. data/lib/active_merchant/billing/gateways/certo_direct.rb +279 -0
  33. data/lib/active_merchant/billing/gateways/cyber_source.rb +430 -0
  34. data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
  35. data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
  36. data/lib/active_merchant/billing/gateways/elavon.rb +137 -0
  37. data/lib/active_merchant/billing/gateways/epay.rb +276 -0
  38. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  39. data/lib/active_merchant/billing/gateways/eway_managed.rb +265 -0
  40. data/lib/active_merchant/billing/gateways/exact.rb +227 -0
  41. data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
  42. data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
  43. data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
  44. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +250 -0
  45. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  46. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  47. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
  48. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  49. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  50. data/lib/active_merchant/billing/gateways/iridium.rb +258 -0
  51. data/lib/active_merchant/billing/gateways/itransact.rb +450 -0
  52. data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
  53. data/lib/active_merchant/billing/gateways/linkpoint.rb +454 -0
  54. data/lib/active_merchant/billing/gateways/litle.rb +275 -0
  55. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +157 -0
  56. data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
  57. data/lib/active_merchant/billing/gateways/migs.rb +259 -0
  58. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  59. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  60. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  61. data/lib/active_merchant/billing/gateways/moneris.rb +250 -0
  62. data/lib/active_merchant/billing/gateways/moneris_us.rb +211 -0
  63. data/lib/active_merchant/billing/gateways/nab_transact.rb +255 -0
  64. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  65. data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
  66. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  67. data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
  68. data/lib/active_merchant/billing/gateways/ogone.rb +422 -0
  69. data/lib/active_merchant/billing/gateways/optimal_payment.rb +277 -0
  70. data/lib/active_merchant/billing/gateways/orbital.rb +353 -0
  71. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
  72. data/lib/active_merchant/billing/gateways/pay_junction.rb +397 -0
  73. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  74. data/lib/active_merchant/billing/gateways/paybox_direct.rb +199 -0
  75. data/lib/active_merchant/billing/gateways/payflow.rb +266 -0
  76. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +211 -0
  77. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  78. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  79. data/lib/active_merchant/billing/gateways/payflow_express.rb +224 -0
  80. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  81. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  82. data/lib/active_merchant/billing/gateways/payment_express.rb +282 -0
  83. data/lib/active_merchant/billing/gateways/paypal.rb +106 -0
  84. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +640 -0
  85. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
  86. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +245 -0
  87. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  88. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +43 -0
  89. data/lib/active_merchant/billing/gateways/paypal_express.rb +178 -0
  90. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  91. data/lib/active_merchant/billing/gateways/paystation.rb +201 -0
  92. data/lib/active_merchant/billing/gateways/plugnpay.rb +298 -0
  93. data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
  94. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  95. data/lib/active_merchant/billing/gateways/qbms.rb +297 -0
  96. data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
  97. data/lib/active_merchant/billing/gateways/quickpay.rb +298 -0
  98. data/lib/active_merchant/billing/gateways/realex.rb +313 -0
  99. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  100. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  101. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  102. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  103. data/lib/active_merchant/billing/gateways/sage_pay.rb +320 -0
  104. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  105. data/lib/active_merchant/billing/gateways/samurai.rb +121 -0
  106. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  107. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  108. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +281 -0
  109. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  110. data/lib/active_merchant/billing/gateways/skip_jack.rb +458 -0
  111. data/lib/active_merchant/billing/gateways/smart_ps.rb +271 -0
  112. data/lib/active_merchant/billing/gateways/stripe.rb +236 -0
  113. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  114. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  115. data/lib/active_merchant/billing/gateways/trust_commerce.rb +437 -0
  116. data/lib/active_merchant/billing/gateways/usa_epay.rb +23 -0
  117. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1496 -0
  118. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +202 -0
  119. data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
  120. data/lib/active_merchant/billing/gateways/viaklix.rb +194 -0
  121. data/lib/active_merchant/billing/gateways/vindicia.rb +359 -0
  122. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  123. data/lib/active_merchant/billing/gateways/worldpay.rb +280 -0
  124. data/lib/active_merchant/billing/integrations.rb +17 -0
  125. data/lib/active_merchant/billing/integrations/action_view_helper.rb +72 -0
  126. data/lib/active_merchant/billing/integrations/authorize_net_sim.rb +38 -0
  127. data/lib/active_merchant/billing/integrations/authorize_net_sim/helper.rb +228 -0
  128. data/lib/active_merchant/billing/integrations/authorize_net_sim/notification.rb +340 -0
  129. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  130. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  131. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  132. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  133. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  134. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  135. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  136. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  137. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  138. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
  139. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  140. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  141. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  142. data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
  143. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
  144. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
  145. data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
  146. data/lib/active_merchant/billing/integrations/dotpay.rb +22 -0
  147. data/lib/active_merchant/billing/integrations/dotpay/helper.rb +77 -0
  148. data/lib/active_merchant/billing/integrations/dotpay/notification.rb +86 -0
  149. data/lib/active_merchant/billing/integrations/dotpay/return.rb +11 -0
  150. data/lib/active_merchant/billing/integrations/dwolla.rb +30 -0
  151. data/lib/active_merchant/billing/integrations/dwolla/helper.rb +31 -0
  152. data/lib/active_merchant/billing/integrations/dwolla/notification.rb +55 -0
  153. data/lib/active_merchant/billing/integrations/dwolla/return.rb +38 -0
  154. data/lib/active_merchant/billing/integrations/e_payment_plans.rb +48 -0
  155. data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +34 -0
  156. data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +84 -0
  157. data/lib/active_merchant/billing/integrations/epay.rb +21 -0
  158. data/lib/active_merchant/billing/integrations/epay/helper.rb +55 -0
  159. data/lib/active_merchant/billing/integrations/epay/notification.rb +110 -0
  160. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  161. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  162. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  163. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  164. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  165. data/lib/active_merchant/billing/integrations/helper.rb +113 -0
  166. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  167. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  168. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  169. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  170. data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
  171. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
  172. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
  173. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  174. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  175. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  176. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  177. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  178. data/lib/active_merchant/billing/integrations/payflow_link.rb +21 -0
  179. data/lib/active_merchant/billing/integrations/payflow_link/helper.rb +100 -0
  180. data/lib/active_merchant/billing/integrations/payflow_link/notification.rb +78 -0
  181. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  182. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  183. data/lib/active_merchant/billing/integrations/paypal/notification.rb +155 -0
  184. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  185. data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
  186. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +71 -0
  187. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  188. data/lib/active_merchant/billing/integrations/return.rb +42 -0
  189. data/lib/active_merchant/billing/integrations/robokassa.rb +49 -0
  190. data/lib/active_merchant/billing/integrations/robokassa/common.rb +19 -0
  191. data/lib/active_merchant/billing/integrations/robokassa/helper.rb +50 -0
  192. data/lib/active_merchant/billing/integrations/robokassa/notification.rb +55 -0
  193. data/lib/active_merchant/billing/integrations/robokassa/return.rb +17 -0
  194. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  195. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  196. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +129 -0
  197. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
  198. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
  199. data/lib/active_merchant/billing/integrations/two_checkout.rb +44 -0
  200. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +91 -0
  201. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +139 -0
  202. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  203. data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
  204. data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
  205. data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
  206. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +97 -0
  207. data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
  208. data/lib/active_merchant/billing/integrations/verkkomaksut.rb +20 -0
  209. data/lib/active_merchant/billing/integrations/verkkomaksut/helper.rb +87 -0
  210. data/lib/active_merchant/billing/integrations/verkkomaksut/notification.rb +59 -0
  211. data/lib/active_merchant/billing/integrations/world_pay.rb +27 -0
  212. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
  213. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
  214. data/lib/active_merchant/billing/response.rb +32 -0
  215. data/lib/active_merchant/version.rb +3 -0
  216. data/lib/activemerchant.rb +1 -0
  217. data/lib/support/gateway_support.rb +58 -0
  218. data/lib/support/outbound_hosts.rb +25 -0
  219. metadata +447 -0
@@ -0,0 +1,250 @@
1
+ require 'rexml/document'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+
6
+ # To learn more about the Moneris gateway, please contact
7
+ # eselectplus@moneris.com for a copy of their integration guide. For
8
+ # information on remote testing, please see "Test Environment Penny Value
9
+ # Response Table", and "Test Environment eFraud (AVS and CVD) Penny
10
+ # Response Values", available at Moneris' {eSelect Plus Documentation
11
+ # Centre}[https://www3.moneris.com/connect/en/documents/index.html].
12
+ class MonerisGateway < Gateway
13
+ TEST_URL = 'https://esqa.moneris.com/gateway2/servlet/MpgRequest'
14
+ LIVE_URL = 'https://www3.moneris.com/gateway2/servlet/MpgRequest'
15
+
16
+ self.supported_countries = ['CA']
17
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :discover]
18
+ self.homepage_url = 'http://www.moneris.com/'
19
+ self.display_name = 'Moneris'
20
+
21
+ # login is your Store ID
22
+ # password is your API Token
23
+ def initialize(options = {})
24
+ requires!(options, :login, :password)
25
+ @options = { :crypt_type => 7 }.update(options)
26
+ super
27
+ end
28
+
29
+ # Referred to as "PreAuth" in the Moneris integration guide, this action
30
+ # verifies and locks funds on a customer's card, which then must be
31
+ # captured at a later date.
32
+ #
33
+ # Pass in +order_id+ and optionally a +customer+ parameter.
34
+ def authorize(money, creditcard_or_datakey, options = {})
35
+ requires!(options, :order_id)
36
+ post = {}
37
+ add_payment_source(post, creditcard_or_datakey)
38
+ post[:amount] = amount(money)
39
+ post[:order_id] = options[:order_id]
40
+ post[:cust_id] = options[:customer]
41
+ post[:crypt_type] = options[:crypt_type] || @options[:crypt_type]
42
+ action = (post[:data_key].blank?) ? 'preauth' : 'res_preauth_cc'
43
+ commit(action, post)
44
+ end
45
+
46
+ # This action verifies funding on a customer's card and readies them for
47
+ # deposit in a merchant's account.
48
+ #
49
+ # Pass in <tt>order_id</tt> and optionally a <tt>customer</tt> parameter
50
+ def purchase(money, creditcard_or_datakey, options = {})
51
+ requires!(options, :order_id)
52
+ post = {}
53
+ add_payment_source(post, creditcard_or_datakey)
54
+ post[:amount] = amount(money)
55
+ post[:order_id] = options[:order_id]
56
+ post[:cust_id] = options[:customer]
57
+ post[:crypt_type] = options[:crypt_type] || @options[:crypt_type]
58
+ action = (post[:data_key].blank?) ? 'purchase' : 'res_purchase_cc'
59
+ commit(action, post)
60
+ end
61
+
62
+ # This method retrieves locked funds from a customer's account (from a
63
+ # PreAuth) and prepares them for deposit in a merchant's account.
64
+ #
65
+ # Note: Moneris requires both the order_id and the transaction number of
66
+ # the original authorization. To maintain the same interface as the other
67
+ # gateways the two numbers are concatenated together with a ; separator as
68
+ # the authorization number returned by authorization
69
+ def capture(money, authorization, options = {})
70
+ commit 'completion', crediting_params(authorization, :comp_amount => amount(money))
71
+ end
72
+
73
+ # Voiding requires the original transaction ID and order ID of some open
74
+ # transaction. Closed transactions must be refunded. Note that the only
75
+ # methods which may be voided are +capture+ and +purchase+.
76
+ #
77
+ # Concatenate your transaction number and order_id by using a semicolon
78
+ # (';'). This is to keep the Moneris interface consistent with other
79
+ # gateways. (See +capture+ for details.)
80
+ def void(authorization, options = {})
81
+ commit 'purchasecorrection', crediting_params(authorization)
82
+ end
83
+
84
+ # Performs a refund. This method requires that the original transaction
85
+ # number and order number be included. Concatenate your transaction
86
+ # number and order_id by using a semicolon (';'). This is to keep the
87
+ # Moneris interface consistent with other gateways. (See +capture+ for
88
+ # details.)
89
+ def credit(money, authorization, options = {})
90
+ deprecated CREDIT_DEPRECATION_MESSAGE
91
+ refund(money, authorization, options)
92
+ end
93
+
94
+ def refund(money, authorization, options = {})
95
+ commit 'refund', crediting_params(authorization, :amount => amount(money))
96
+ end
97
+
98
+ def store(credit_card, options = {})
99
+ post = {}
100
+ post[:pan] = credit_card.number
101
+ post[:expdate] = expdate(credit_card)
102
+ post[:crypt_type] = options[:crypt_type] || @options[:crypt_type]
103
+ commit('res_add_cc', post)
104
+ end
105
+
106
+ def unstore(data_key)
107
+ post = {}
108
+ post[:data_key] = data_key
109
+ commit('res_delete', post)
110
+ end
111
+
112
+ def update(data_key, credit_card, options = {})
113
+ post = {}
114
+ post[:pan] = credit_card.number
115
+ post[:expdate] = expdate(credit_card)
116
+ post[:data_key] = data_key
117
+ post[:crypt_type] = options[:crypt_type] || @options[:crypt_type]
118
+ commit('res_update_cc', post)
119
+ end
120
+
121
+ def test?
122
+ @options[:test] || super
123
+ end
124
+
125
+ private # :nodoc: all
126
+
127
+ def expdate(creditcard)
128
+ sprintf("%.4i", creditcard.year)[-2..-1] + sprintf("%.2i", creditcard.month)
129
+ end
130
+
131
+ def add_payment_source(post, source)
132
+ if source.is_a?(String)
133
+ post[:data_key] = source
134
+ else
135
+ post[:pan] = source.number
136
+ post[:expdate] = expdate(source)
137
+ end
138
+ end
139
+
140
+ # Common params used amongst the +credit+, +void+ and +capture+ methods
141
+ def crediting_params(authorization, options = {})
142
+ {
143
+ :txn_number => split_authorization(authorization).first,
144
+ :order_id => split_authorization(authorization).last,
145
+ :crypt_type => options[:crypt_type] || @options[:crypt_type]
146
+ }.merge(options)
147
+ end
148
+
149
+ # Splits an +authorization+ param and retrives the order id and
150
+ # transaction number in that order.
151
+ def split_authorization(authorization)
152
+ if authorization.nil? || authorization.empty? || authorization !~ /;/
153
+ raise ArgumentError, 'You must include a valid authorization code (e.g. "1234;567")'
154
+ else
155
+ authorization.split(';')
156
+ end
157
+ end
158
+
159
+ def commit(action, parameters = {})
160
+ response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, post_data(action, parameters)))
161
+
162
+ Response.new(successful?(response), message_from(response[:message]), response,
163
+ :test => test?,
164
+ :authorization => authorization_from(response)
165
+ )
166
+ end
167
+
168
+ # Generates a Moneris authorization string of the form 'trans_id;receipt_id'.
169
+ def authorization_from(response = {})
170
+ if response[:trans_id] && response[:receipt_id]
171
+ "#{response[:trans_id]};#{response[:receipt_id]}"
172
+ end
173
+ end
174
+
175
+ # Tests for a successful response from Moneris' servers
176
+ def successful?(response)
177
+ response[:response_code] &&
178
+ response[:complete] &&
179
+ (0..49).include?(response[:response_code].to_i)
180
+ end
181
+
182
+ def parse(xml)
183
+ response = { :message => "Global Error Receipt", :complete => false }
184
+ hashify_xml!(xml, response)
185
+ response
186
+ end
187
+
188
+ def hashify_xml!(xml, response)
189
+ xml = REXML::Document.new(xml)
190
+ return if xml.root.nil?
191
+ xml.elements.each('//receipt/*') do |node|
192
+ response[node.name.underscore.to_sym] = normalize(node.text)
193
+ end
194
+ end
195
+
196
+ def post_data(action, parameters = {})
197
+ xml = REXML::Document.new
198
+ root = xml.add_element("request")
199
+ root.add_element("store_id").text = options[:login]
200
+ root.add_element("api_token").text = options[:password]
201
+ transaction = root.add_element(action)
202
+
203
+ # Must add the elements in the correct order
204
+ actions[action].each do |key|
205
+ transaction.add_element(key.to_s).text = parameters[key] unless parameters[key].blank?
206
+ end
207
+
208
+ xml.to_s
209
+ end
210
+
211
+ def message_from(message)
212
+ return 'Unspecified error' if message.blank?
213
+ message.gsub(/[^\w]/, ' ').split.join(" ").capitalize
214
+ end
215
+
216
+ # Make a Ruby type out of the response string
217
+ def normalize(field)
218
+ case field
219
+ when "true" then true
220
+ when "false" then false
221
+ when '', "null" then nil
222
+ else field
223
+ end
224
+ end
225
+
226
+ def actions
227
+ {
228
+ "purchase" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
229
+ "preauth" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
230
+ "command" => [:order_id],
231
+ "refund" => [:order_id, :amount, :txn_number, :crypt_type],
232
+ "indrefund" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
233
+ "completion" => [:order_id, :comp_amount, :txn_number, :crypt_type],
234
+ "purchasecorrection" => [:order_id, :txn_number, :crypt_type],
235
+ "cavvpurcha" => [:order_id, :cust_id, :amount, :pan, :expdate, :cav],
236
+ "cavvpreaut" => [:order_id, :cust_id, :amount, :pan, :expdate, :cavv],
237
+ "transact" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
238
+ "Batchcloseall" => [],
239
+ "opentotals" => [:ecr_number],
240
+ "batchclose" => [:ecr_number],
241
+ "res_add_cc" => [:pan, :expdate, :crypt_type],
242
+ "res_delete" => [:data_key],
243
+ "res_update_cc" => [:data_key, :pan, :expdate, :crypt_type],
244
+ "res_purchase_cc" => [:data_key, :order_id, :cust_id, :amount, :crypt_type],
245
+ "res_preauth_cc" => [:data_key, :order_id, :cust_id, :amount, :crypt_type]
246
+ }
247
+ end
248
+ end
249
+ end
250
+ end
@@ -0,0 +1,211 @@
1
+ require 'rexml/document'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+
6
+ # To learn more about the Moneris (US) gateway, please contact
7
+ # ussales@moneris.com for a copy of their integration guide. For
8
+ # information on remote testing, please see "Test Environment Penny Value
9
+ # Response Table", and "Test Environment eFraud (AVS and CVD) Penny
10
+ # Response Values", available at Moneris' {eSelect Plus Documentation
11
+ # Centre}[https://www3.moneris.com/connect/en/documents/index.html].
12
+ class MonerisUsGateway < Gateway
13
+ TEST_URL = 'https://esplusqa.moneris.com/gateway_us/servlet/MpgRequest'
14
+ LIVE_URL = 'https://esplus.moneris.com/gateway_us/servlet/MpgRequest'
15
+
16
+ self.supported_countries = ['US']
17
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :discover]
18
+ self.homepage_url = 'http://www.monerisusa.com/'
19
+ self.display_name = 'Moneris (US)'
20
+
21
+ # login is your Store ID
22
+ # password is your API Token
23
+ def initialize(options = {})
24
+ requires!(options, :login, :password)
25
+ @options = { :crypt_type => 7 }.update(options)
26
+ super
27
+ end
28
+
29
+ # Referred to as "PreAuth" in the Moneris integration guide, this action
30
+ # verifies and locks funds on a customer's card, which then must be
31
+ # captured at a later date.
32
+ #
33
+ # Pass in +order_id+ and optionally a +customer+ parameter.
34
+ def authorize(money, creditcard, options = {})
35
+ debit_commit 'us_preauth', money, creditcard, options
36
+ end
37
+
38
+ # This action verifies funding on a customer's card, and readies them for
39
+ # deposit in a merchant's account.
40
+ #
41
+ # Pass in <tt>order_id</tt> and optionally a <tt>customer</tt> parameter
42
+ def purchase(money, creditcard, options = {})
43
+ debit_commit 'us_purchase', money, creditcard, options
44
+ end
45
+
46
+ # This method retrieves locked funds from a customer's account (from a
47
+ # PreAuth) and prepares them for deposit in a merchant's account.
48
+ #
49
+ # Note: Moneris requires both the order_id and the transaction number of
50
+ # the original authorization. To maintain the same interface as the other
51
+ # gateways the two numbers are concatenated together with a ; separator as
52
+ # the authorization number returned by authorization
53
+ def capture(money, authorization, options = {})
54
+ commit 'us_completion', crediting_params(authorization, :comp_amount => amount(money))
55
+ end
56
+
57
+ # Voiding requires the original transaction ID and order ID of some open
58
+ # transaction. Closed transactions must be refunded. Note that the only
59
+ # methods which may be voided are +capture+ and +purchase+.
60
+ #
61
+ # Concatenate your transaction number and order_id by using a semicolon
62
+ # (';'). This is to keep the Moneris interface consistent with other
63
+ # gateways. (See +capture+ for details.)
64
+ def void(authorization, options = {})
65
+ commit 'us_purchasecorrection', crediting_params(authorization)
66
+ end
67
+
68
+ # Performs a refund. This method requires that the original transaction
69
+ # number and order number be included. Concatenate your transaction
70
+ # number and order_id by using a semicolon (';'). This is to keep the
71
+ # Moneris interface consistent with other gateways. (See +capture+ for
72
+ # details.)
73
+ def credit(money, authorization, options = {})
74
+ deprecated CREDIT_DEPRECATION_MESSAGE
75
+ refund(money, authorization, options)
76
+ end
77
+
78
+ def refund(money, authorization, options = {})
79
+ commit 'us_refund', crediting_params(authorization, :amount => amount(money))
80
+ end
81
+
82
+ def test?
83
+ @options[:test] || super
84
+ end
85
+ private # :nodoc: all
86
+
87
+ def expdate(creditcard)
88
+ sprintf("%.4i", creditcard.year)[-2..-1] + sprintf("%.2i", creditcard.month)
89
+ end
90
+
91
+ def debit_commit(commit_type, money, creditcard, options)
92
+ requires!(options, :order_id)
93
+ commit(commit_type, debit_params(money, creditcard, options))
94
+ end
95
+
96
+ # Common params used amongst the +purchase+ and +authorization+ methods
97
+ def debit_params(money, creditcard, options = {})
98
+ {
99
+ :order_id => options[:order_id],
100
+ :cust_id => options[:customer],
101
+ :amount => amount(money),
102
+ :pan => creditcard.number,
103
+ :expdate => expdate(creditcard),
104
+ :crypt_type => options[:crypt_type] || @options[:crypt_type]
105
+ }
106
+ end
107
+
108
+ # Common params used amongst the +credit+, +void+ and +capture+ methods
109
+ def crediting_params(authorization, options = {})
110
+ {
111
+ :txn_number => split_authorization(authorization).first,
112
+ :order_id => split_authorization(authorization).last,
113
+ :crypt_type => options[:crypt_type] || @options[:crypt_type]
114
+ }.merge(options)
115
+ end
116
+
117
+ # Splits an +authorization+ param and retrives the order id and
118
+ # transaction number in that order.
119
+ def split_authorization(authorization)
120
+ if authorization.nil? || authorization.empty? || authorization !~ /;/
121
+ raise ArgumentError, 'You must include a valid authorization code (e.g. "1234;567")'
122
+ else
123
+ authorization.split(';')
124
+ end
125
+ end
126
+
127
+ def commit(action, parameters = {})
128
+ response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, post_data(action, parameters)))
129
+
130
+ Response.new(successful?(response), message_from(response[:message]), response,
131
+ :test => test?,
132
+ :authorization => authorization_from(response)
133
+ )
134
+ end
135
+
136
+ # Generates a Moneris authorization string of the form 'trans_id;receipt_id'.
137
+ def authorization_from(response = {})
138
+ if response[:trans_id] && response[:receipt_id]
139
+ "#{response[:trans_id]};#{response[:receipt_id]}"
140
+ end
141
+ end
142
+
143
+ # Tests for a successful response from Moneris' servers
144
+ def successful?(response)
145
+ response[:response_code] &&
146
+ response[:complete] &&
147
+ (0..49).include?(response[:response_code].to_i)
148
+ end
149
+
150
+ def parse(xml)
151
+ response = { :message => "Global Error Receipt", :complete => false }
152
+ hashify_xml!(xml, response)
153
+ response
154
+ end
155
+
156
+ def hashify_xml!(xml, response)
157
+ xml = REXML::Document.new(xml)
158
+ return if xml.root.nil?
159
+ xml.elements.each('//receipt/*') do |node|
160
+ response[node.name.underscore.to_sym] = normalize(node.text)
161
+ end
162
+ end
163
+
164
+ def post_data(action, parameters = {})
165
+ xml = REXML::Document.new
166
+ root = xml.add_element("request")
167
+ root.add_element("store_id").text = options[:login]
168
+ root.add_element("api_token").text = options[:password]
169
+ transaction = root.add_element(action)
170
+
171
+ # Must add the elements in the correct order
172
+ actions[action].each do |key|
173
+ transaction.add_element(key.to_s).text = parameters[key] unless parameters[key].blank?
174
+ end
175
+
176
+ xml.to_s
177
+ end
178
+
179
+ def message_from(message)
180
+ return 'Unspecified error' if message.blank?
181
+ message.gsub(/[^\w]/, ' ').split.join(" ").capitalize
182
+ end
183
+
184
+ # Make a Ruby type out of the response string
185
+ def normalize(field)
186
+ case field
187
+ when "true" then true
188
+ when "false" then false
189
+ when '', "null" then nil
190
+ else field
191
+ end
192
+ end
193
+
194
+ def actions
195
+ {
196
+ "us_purchase" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
197
+ "us_preauth" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
198
+ "us_refund" => [:order_id, :amount, :txn_number, :crypt_type],
199
+ "us_ind_refund" => [:order_id, :cust_id, :amount, :pan, :expdate, :crypt_type],
200
+ "us_completion" => [:order_id, :comp_amount, :txn_number, :crypt_type],
201
+ "us_purchasecorrection" => [:order_id, :txn_number, :crypt_type],
202
+ "us_cavv_purchase" => [:order_id, :cust_id, :amount, :pan, :expdate, :cavv],
203
+ "us_cavv_preauth" => [:order_id, :cust_id, :amount, :pan, :expdate, :cavv],
204
+ "us_batchcloseall" => [],
205
+ "us_opentotals" => [:ecr_number],
206
+ "us_batchclose" => [:ecr_number]
207
+ }
208
+ end
209
+ end
210
+ end
211
+ end