start_activemerchant 1.50.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +1769 -0
  3. data/CONTRIBUTORS +540 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +226 -0
  6. data/lib/active_merchant.rb +67 -0
  7. data/lib/active_merchant/billing.rb +15 -0
  8. data/lib/active_merchant/billing/apple_pay_payment_token.rb +22 -0
  9. data/lib/active_merchant/billing/avs_result.rb +98 -0
  10. data/lib/active_merchant/billing/base.rb +72 -0
  11. data/lib/active_merchant/billing/check.rb +76 -0
  12. data/lib/active_merchant/billing/compatibility.rb +120 -0
  13. data/lib/active_merchant/billing/credit_card.rb +404 -0
  14. data/lib/active_merchant/billing/credit_card_formatting.rb +24 -0
  15. data/lib/active_merchant/billing/credit_card_methods.rb +195 -0
  16. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  17. data/lib/active_merchant/billing/gateway.rb +291 -0
  18. data/lib/active_merchant/billing/gateways.rb +14 -0
  19. data/lib/active_merchant/billing/gateways/allied_wallet.rb +203 -0
  20. data/lib/active_merchant/billing/gateways/app55.rb +176 -0
  21. data/lib/active_merchant/billing/gateways/authorize_net.rb +510 -0
  22. data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +417 -0
  23. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +976 -0
  24. data/lib/active_merchant/billing/gateways/axcessms.rb +181 -0
  25. data/lib/active_merchant/billing/gateways/balanced.rb +256 -0
  26. data/lib/active_merchant/billing/gateways/bank_frick.rb +225 -0
  27. data/lib/active_merchant/billing/gateways/banwire.rb +105 -0
  28. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +314 -0
  29. data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +15 -0
  30. data/lib/active_merchant/billing/gateways/be2bill.rb +131 -0
  31. data/lib/active_merchant/billing/gateways/beanstream.rb +192 -0
  32. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +389 -0
  33. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +58 -0
  34. data/lib/active_merchant/billing/gateways/blue_pay.rb +506 -0
  35. data/lib/active_merchant/billing/gateways/bogus.rb +140 -0
  36. data/lib/active_merchant/billing/gateways/borgun.rb +211 -0
  37. data/lib/active_merchant/billing/gateways/bpoint.rb +277 -0
  38. data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
  39. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  40. data/lib/active_merchant/billing/gateways/braintree_blue.rb +574 -0
  41. data/lib/active_merchant/billing/gateways/braintree_orange.rb +20 -0
  42. data/lib/active_merchant/billing/gateways/bridge_pay.rb +189 -0
  43. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  44. data/lib/active_merchant/billing/gateways/card_stream.rb +238 -0
  45. data/lib/active_merchant/billing/gateways/cashnet.rb +202 -0
  46. data/lib/active_merchant/billing/gateways/cc5.rb +201 -0
  47. data/lib/active_merchant/billing/gateways/cecabank.rb +229 -0
  48. data/lib/active_merchant/billing/gateways/cenpos.rb +262 -0
  49. data/lib/active_merchant/billing/gateways/certo_direct.rb +278 -0
  50. data/lib/active_merchant/billing/gateways/checkout.rb +216 -0
  51. data/lib/active_merchant/billing/gateways/checkout_v2.rb +200 -0
  52. data/lib/active_merchant/billing/gateways/commercegate.rb +143 -0
  53. data/lib/active_merchant/billing/gateways/conekta.rb +210 -0
  54. data/lib/active_merchant/billing/gateways/cyber_source.rb +720 -0
  55. data/lib/active_merchant/billing/gateways/data_cash.rb +600 -0
  56. data/lib/active_merchant/billing/gateways/dibs.rb +206 -0
  57. data/lib/active_merchant/billing/gateways/efsnet.rb +219 -0
  58. data/lib/active_merchant/billing/gateways/elavon.rb +348 -0
  59. data/lib/active_merchant/billing/gateways/epay.rb +274 -0
  60. data/lib/active_merchant/billing/gateways/evo_ca.rb +308 -0
  61. data/lib/active_merchant/billing/gateways/eway.rb +214 -0
  62. data/lib/active_merchant/billing/gateways/eway_managed.rb +291 -0
  63. data/lib/active_merchant/billing/gateways/eway_rapid.rb +522 -0
  64. data/lib/active_merchant/billing/gateways/exact.rb +227 -0
  65. data/lib/active_merchant/billing/gateways/ezic.rb +206 -0
  66. data/lib/active_merchant/billing/gateways/fat_zebra.rb +213 -0
  67. data/lib/active_merchant/billing/gateways/federated_canada.rb +160 -0
  68. data/lib/active_merchant/billing/gateways/finansbank.rb +23 -0
  69. data/lib/active_merchant/billing/gateways/first_giving.rb +143 -0
  70. data/lib/active_merchant/billing/gateways/first_pay.rb +160 -0
  71. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +413 -0
  72. data/lib/active_merchant/billing/gateways/flo2cash.rb +215 -0
  73. data/lib/active_merchant/billing/gateways/flo2cash_simple.rb +20 -0
  74. data/lib/active_merchant/billing/gateways/garanti.rb +261 -0
  75. data/lib/active_merchant/billing/gateways/global_transport.rb +179 -0
  76. data/lib/active_merchant/billing/gateways/hdfc.rb +207 -0
  77. data/lib/active_merchant/billing/gateways/hps.rb +287 -0
  78. data/lib/active_merchant/billing/gateways/iats_payments.rb +277 -0
  79. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +246 -0
  80. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  81. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  82. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +66 -0
  83. data/lib/active_merchant/billing/gateways/inspire.rb +219 -0
  84. data/lib/active_merchant/billing/gateways/instapay.rb +163 -0
  85. data/lib/active_merchant/billing/gateways/ipp.rb +175 -0
  86. data/lib/active_merchant/billing/gateways/iridium.rb +457 -0
  87. data/lib/active_merchant/billing/gateways/itransact.rb +448 -0
  88. data/lib/active_merchant/billing/gateways/jetpay.rb +275 -0
  89. data/lib/active_merchant/billing/gateways/linkpoint.rb +438 -0
  90. data/lib/active_merchant/billing/gateways/litle.rb +345 -0
  91. data/lib/active_merchant/billing/gateways/maxipago.rb +197 -0
  92. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +170 -0
  93. data/lib/active_merchant/billing/gateways/merchant_one.rb +114 -0
  94. data/lib/active_merchant/billing/gateways/merchant_partners.rb +245 -0
  95. data/lib/active_merchant/billing/gateways/merchant_ware.rb +319 -0
  96. data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +268 -0
  97. data/lib/active_merchant/billing/gateways/merchant_warrior.rb +195 -0
  98. data/lib/active_merchant/billing/gateways/mercury.rb +326 -0
  99. data/lib/active_merchant/billing/gateways/metrics_global.rb +303 -0
  100. data/lib/active_merchant/billing/gateways/migs.rb +280 -0
  101. data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
  102. data/lib/active_merchant/billing/gateways/modern_payments.rb +37 -0
  103. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +219 -0
  104. data/lib/active_merchant/billing/gateways/monei.rb +307 -0
  105. data/lib/active_merchant/billing/gateways/moneris.rb +309 -0
  106. data/lib/active_merchant/billing/gateways/moneris_us.rb +298 -0
  107. data/lib/active_merchant/billing/gateways/money_movers.rb +152 -0
  108. data/lib/active_merchant/billing/gateways/nab_transact.rb +290 -0
  109. data/lib/active_merchant/billing/gateways/net_registry.rb +198 -0
  110. data/lib/active_merchant/billing/gateways/netaxept.rb +181 -0
  111. data/lib/active_merchant/billing/gateways/netbilling.rb +224 -0
  112. data/lib/active_merchant/billing/gateways/netpay.rb +223 -0
  113. data/lib/active_merchant/billing/gateways/network_merchants.rb +242 -0
  114. data/lib/active_merchant/billing/gateways/nmi.rb +256 -0
  115. data/lib/active_merchant/billing/gateways/ogone.rb +435 -0
  116. data/lib/active_merchant/billing/gateways/omise.rb +319 -0
  117. data/lib/active_merchant/billing/gateways/openpay.rb +194 -0
  118. data/lib/active_merchant/billing/gateways/optimal_payment.rb +314 -0
  119. data/lib/active_merchant/billing/gateways/orbital.rb +834 -0
  120. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +47 -0
  121. data/lib/active_merchant/billing/gateways/pac_net_raven.rb +207 -0
  122. data/lib/active_merchant/billing/gateways/pago_facil.rb +122 -0
  123. data/lib/active_merchant/billing/gateways/pay_conex.rb +246 -0
  124. data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +277 -0
  125. data/lib/active_merchant/billing/gateways/pay_hub.rb +213 -0
  126. data/lib/active_merchant/billing/gateways/pay_junction.rb +390 -0
  127. data/lib/active_merchant/billing/gateways/pay_secure.rb +112 -0
  128. data/lib/active_merchant/billing/gateways/paybox_direct.rb +188 -0
  129. data/lib/active_merchant/billing/gateways/payex.rb +412 -0
  130. data/lib/active_merchant/billing/gateways/payflow.rb +308 -0
  131. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +220 -0
  132. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  133. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  134. data/lib/active_merchant/billing/gateways/payflow_express.rb +224 -0
  135. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  136. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  137. data/lib/active_merchant/billing/gateways/payment_express.rb +353 -0
  138. data/lib/active_merchant/billing/gateways/paymill.rb +282 -0
  139. data/lib/active_merchant/billing/gateways/paypal.rb +129 -0
  140. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +679 -0
  141. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +65 -0
  142. data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +262 -0
  143. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  144. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +44 -0
  145. data/lib/active_merchant/billing/gateways/paypal_express.rb +264 -0
  146. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
  147. data/lib/active_merchant/billing/gateways/payscout.rb +162 -0
  148. data/lib/active_merchant/billing/gateways/paystation.rb +199 -0
  149. data/lib/active_merchant/billing/gateways/payu_in.rb +247 -0
  150. data/lib/active_merchant/billing/gateways/payway.rb +207 -0
  151. data/lib/active_merchant/billing/gateways/pin.rb +207 -0
  152. data/lib/active_merchant/billing/gateways/plugnpay.rb +283 -0
  153. data/lib/active_merchant/billing/gateways/psigate.rb +216 -0
  154. data/lib/active_merchant/billing/gateways/psl_card.rb +303 -0
  155. data/lib/active_merchant/billing/gateways/qbms.rb +292 -0
  156. data/lib/active_merchant/billing/gateways/quantum.rb +276 -0
  157. data/lib/active_merchant/billing/gateways/quickbooks.rb +280 -0
  158. data/lib/active_merchant/billing/gateways/quickpay.rb +26 -0
  159. data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +188 -0
  160. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +240 -0
  161. data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +227 -0
  162. data/lib/active_merchant/billing/gateways/qvalent.rb +179 -0
  163. data/lib/active_merchant/billing/gateways/realex.rb +298 -0
  164. data/lib/active_merchant/billing/gateways/redsys.rb +406 -0
  165. data/lib/active_merchant/billing/gateways/s5.rb +226 -0
  166. data/lib/active_merchant/billing/gateways/sage.rb +173 -0
  167. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +89 -0
  168. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +115 -0
  169. data/lib/active_merchant/billing/gateways/sage/sage_vault.rb +149 -0
  170. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  171. data/lib/active_merchant/billing/gateways/sage_pay.rb +399 -0
  172. data/lib/active_merchant/billing/gateways/sallie_mae.rb +143 -0
  173. data/lib/active_merchant/billing/gateways/secure_net.rb +263 -0
  174. data/lib/active_merchant/billing/gateways/secure_pay.rb +201 -0
  175. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +281 -0
  176. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +105 -0
  177. data/lib/active_merchant/billing/gateways/skip_jack.rb +451 -0
  178. data/lib/active_merchant/billing/gateways/smart_ps.rb +283 -0
  179. data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
  180. data/lib/active_merchant/billing/gateways/spreedly_core.rb +247 -0
  181. data/lib/active_merchant/billing/gateways/stripe.rb +489 -0
  182. data/lib/active_merchant/billing/gateways/swipe_checkout.rb +157 -0
  183. data/lib/active_merchant/billing/gateways/tns.rb +227 -0
  184. data/lib/active_merchant/billing/gateways/trans_first.rb +126 -0
  185. data/lib/active_merchant/billing/gateways/transax.rb +23 -0
  186. data/lib/active_merchant/billing/gateways/transnational.rb +10 -0
  187. data/lib/active_merchant/billing/gateways/trust_commerce.rb +416 -0
  188. data/lib/active_merchant/billing/gateways/usa_epay.rb +25 -0
  189. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1516 -0
  190. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +259 -0
  191. data/lib/active_merchant/billing/gateways/vanco.rb +280 -0
  192. data/lib/active_merchant/billing/gateways/verifi.rb +225 -0
  193. data/lib/active_merchant/billing/gateways/viaklix.rb +183 -0
  194. data/lib/active_merchant/billing/gateways/webpay.rb +97 -0
  195. data/lib/active_merchant/billing/gateways/wepay.rb +205 -0
  196. data/lib/active_merchant/billing/gateways/wirecard.rb +420 -0
  197. data/lib/active_merchant/billing/gateways/worldpay.rb +331 -0
  198. data/lib/active_merchant/billing/gateways/worldpay_online_payments.rb +204 -0
  199. data/lib/active_merchant/billing/gateways/worldpay_us.rb +181 -0
  200. data/lib/active_merchant/billing/model.rb +30 -0
  201. data/lib/active_merchant/billing/network_tokenization_credit_card.rb +24 -0
  202. data/lib/active_merchant/billing/payment_token.rb +21 -0
  203. data/lib/active_merchant/billing/rails.rb +3 -0
  204. data/lib/active_merchant/billing/response.rb +92 -0
  205. data/lib/active_merchant/connection.rb +172 -0
  206. data/lib/active_merchant/country.rb +332 -0
  207. data/lib/active_merchant/empty.rb +20 -0
  208. data/lib/active_merchant/errors.rb +35 -0
  209. data/lib/active_merchant/network_connection_retries.rb +79 -0
  210. data/lib/active_merchant/post_data.rb +24 -0
  211. data/lib/active_merchant/posts_data.rb +84 -0
  212. data/lib/active_merchant/version.rb +3 -0
  213. data/lib/activemerchant.rb +1 -0
  214. data/lib/certs/cacert.pem +3866 -0
  215. data/lib/support/gateway_support.rb +71 -0
  216. data/lib/support/outbound_hosts.rb +28 -0
  217. data/lib/support/ssl_verify.rb +93 -0
  218. metadata +387 -0
@@ -0,0 +1,197 @@
1
+ require 'nokogiri'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class MaxipagoGateway < Gateway
6
+ API_VERSION = '3.1.1.15'
7
+
8
+ self.live_url = 'https://api.maxipago.net/UniversalAPI/postXML'
9
+ self.test_url = 'https://testapi.maxipago.net/UniversalAPI/postXML'
10
+
11
+ self.supported_countries = ['BR']
12
+ self.default_currency = 'BRL'
13
+ self.money_format = :dollars
14
+ self.supported_cardtypes = [:visa, :master, :discover, :american_express, :diners_club]
15
+ self.homepage_url = 'http://www.maxipago.com/'
16
+ self.display_name = 'maxiPago!'
17
+
18
+ def initialize(options = {})
19
+ requires!(options, :login, :password)
20
+ super
21
+ end
22
+
23
+ def purchase(money, creditcard, options = {})
24
+ post = {}
25
+ add_aux_data(post, options)
26
+ add_amount(post, money)
27
+ add_creditcard(post, creditcard)
28
+ add_name(post, creditcard)
29
+ add_address(post, options)
30
+
31
+ commit(build_sale_request(post))
32
+ end
33
+
34
+ def authorize(money, creditcard, options = {})
35
+ post = {}
36
+ add_aux_data(post, options)
37
+ add_amount(post, money)
38
+ add_creditcard(post, creditcard)
39
+ add_name(post, creditcard)
40
+ add_address(post, options)
41
+
42
+ commit(build_sale_request(post, "auth"))
43
+ end
44
+
45
+ def capture(money, authorization, options = {})
46
+ post = {}
47
+ add_amount(post, money)
48
+ add_aux_data(post, options)
49
+ commit(build_capture_request(authorization, post))
50
+ end
51
+
52
+ private
53
+
54
+ def commit(request)
55
+ url = (test? ? self.test_url : self.live_url)
56
+ response = parse(ssl_post(url, request, 'Content-Type' => 'text/xml'))
57
+ Response.new(
58
+ success?(response),
59
+ message_from(response),
60
+ response,
61
+ test: test?,
62
+ authorization: response[:order_id]
63
+ )
64
+ end
65
+
66
+ def success?(response)
67
+ (response[:response_code] == '0')
68
+ end
69
+
70
+ def message_from(response)
71
+ return response[:error_message] if response[:error_message].present?
72
+ return response[:processor_message] if response[:processor_message].present?
73
+ return response[:response_message] if response[:response_message].present?
74
+ return (success?(response) ? 'success' : 'error')
75
+ end
76
+
77
+ def add_aux_data(post, options)
78
+ post[:processorID] = (test? ? 1 : 4) # test: 1, redecard: 2, cielo: 4
79
+ post[:referenceNum] = options[:order_id]
80
+ post[:installments] = options[:installments] if options.has_key?(:installments) && options[:installments] > 1 # only send installments if it is a deferred payment
81
+ end
82
+
83
+ def add_amount(post, money)
84
+ post[:amount] = amount(money)
85
+ end
86
+
87
+ def add_creditcard(post, creditcard)
88
+ post[:card_number] = creditcard.number
89
+ post[:card_exp_month] = creditcard.month
90
+ post[:card_exp_year] = creditcard.year
91
+ post[:card_cvv] = creditcard.verification_value
92
+ end
93
+
94
+ def add_name(post, creditcard)
95
+ post[:billing_name] = creditcard.name
96
+ end
97
+
98
+ def add_address(post, options)
99
+ if(address = (options[:address] || options[:billing_address]))
100
+ post[:billing_address] = address[:address1]
101
+ post[:billing_address2] = address[:address2]
102
+ post[:billing_city] = address[:city]
103
+ post[:billing_state] = address[:state]
104
+ post[:billing_postalcode] = address[:zip]
105
+ post[:billing_country] = address[:country]
106
+ post[:billing_phone] = address[:phone]
107
+ end
108
+ end
109
+
110
+ def build_capture_request(authorization, params)
111
+ build_request(params) do |xml|
112
+ xml.capture! {
113
+ xml.orderID authorization
114
+ xml.referenceNum params[:referenceNum]
115
+ xml.payment {
116
+ xml.chargeTotal params[:amount]
117
+ }
118
+ }
119
+ end
120
+ end
121
+
122
+ def build_sale_request(params, action="sale")
123
+ build_request(params) do |xml|
124
+ xml.send(action) {
125
+ xml.processorID params[:processorID]
126
+ xml.fraudCheck 'N'
127
+ xml.referenceNum params[:referenceNum] # spree_order
128
+ xml.transactionDetail {
129
+ xml.payType {
130
+ xml.creditCard {
131
+ xml.number params[:card_number]
132
+ xml.expMonth params[:card_exp_month]
133
+ xml.expYear params[:card_exp_year]
134
+ xml.cvvNumber params[:card_cvv]
135
+ }
136
+ }
137
+ }
138
+ xml.payment {
139
+ xml.chargeTotal params[:amount]
140
+ if params[:installments].present?
141
+ xml.creditInstallment {
142
+ xml.numberOfInstallments params[:installments]
143
+ xml.chargeInterest 'N'
144
+ }
145
+ end
146
+ }
147
+ xml.billing {
148
+ xml.name params[:billing_name]
149
+ xml.address params[:billing_address] if params[:billing_address].present?
150
+ xml.address2 params[:billing_address2] if params[:billing_address2].present?
151
+ xml.city params[:billing_city] if params[:billing_city].present?
152
+ xml.state params[:billing_state] if params[:billing_state].present?
153
+ xml.postalcode params[:billing_postalcode] if params[:billing_postalcode].present?
154
+ xml.country params[:billing_country] if params[:billing_country].present?
155
+ xml.phone params[:billing_phone] if params[:billing_phone].present?
156
+ }
157
+ }
158
+ end
159
+ end
160
+
161
+ def build_request(params)
162
+ builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
163
+ xml.send("transaction-request") {
164
+ xml.version API_VERSION
165
+ xml.verification {
166
+ xml.merchantId @options[:login]
167
+ xml.merchantKey @options[:password]
168
+ }
169
+ xml.order {
170
+ yield(xml)
171
+ }
172
+ }
173
+ end
174
+ builder.to_xml(indent: 2)
175
+ end
176
+
177
+ def parse(body)
178
+ xml = REXML::Document.new(body)
179
+
180
+ response = {}
181
+ xml.root.elements.to_a.each do |node|
182
+ parse_element(response, node)
183
+ end
184
+ response
185
+ end
186
+
187
+ def parse_element(response, node)
188
+ if node.has_elements?
189
+ node.elements.each{|element| parse_element(response, element) }
190
+ else
191
+ response[node.name.underscore.to_sym] = node.text
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
197
+
@@ -0,0 +1,170 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class MerchantESolutionsGateway < Gateway
4
+ self.test_url = 'https://cert.merchante-solutions.com/mes-api/tridentApi'
5
+ self.live_url = 'https://api.merchante-solutions.com/mes-api/tridentApi'
6
+
7
+ # The countries the gateway supports merchants from as 2 digit ISO country codes
8
+ self.supported_countries = ['US']
9
+
10
+ # The card types supported by the payment gateway
11
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover, :jcb]
12
+
13
+ # The homepage URL of the gateway
14
+ self.homepage_url = 'http://www.merchante-solutions.com/'
15
+
16
+ # The name of the gateway
17
+ self.display_name = 'Merchant e-Solutions'
18
+
19
+ def initialize(options = {})
20
+ requires!(options, :login, :password)
21
+ super
22
+ end
23
+
24
+ def authorize(money, creditcard_or_card_id, options = {})
25
+ post = {}
26
+ post[:client_reference_number] = options[:customer] if options.has_key?(:customer)
27
+ post[:moto_ecommerce_ind] = options[:moto_ecommerce_ind] if options.has_key?(:moto_ecommerce_ind)
28
+ add_invoice(post, options)
29
+ add_payment_source(post, creditcard_or_card_id, options)
30
+ add_address(post, options)
31
+ commit('P', money, post)
32
+ end
33
+
34
+ def purchase(money, creditcard_or_card_id, options = {})
35
+ post = {}
36
+ post[:client_reference_number] = options[:customer] if options.has_key?(:customer)
37
+ post[:moto_ecommerce_ind] = options[:moto_ecommerce_ind] if options.has_key?(:moto_ecommerce_ind)
38
+ add_invoice(post, options)
39
+ add_payment_source(post, creditcard_or_card_id, options)
40
+ add_address(post, options)
41
+ commit('D', money, post)
42
+ end
43
+
44
+ def capture(money, transaction_id, options = {})
45
+ post ={}
46
+ post[:transaction_id] = transaction_id
47
+ post[:client_reference_number] = options[:customer] if options.has_key?(:customer)
48
+ commit('S', money, post)
49
+ end
50
+
51
+ def store(creditcard, options = {})
52
+ post = {}
53
+ post[:client_reference_number] = options[:customer] if options.has_key?(:customer)
54
+ add_creditcard(post, creditcard, options)
55
+ commit('T', nil, post)
56
+ end
57
+
58
+ def unstore(card_id, options = {})
59
+ post = {}
60
+ post[:client_reference_number] = options[:customer] if options.has_key?(:customer)
61
+ post[:card_id] = card_id
62
+ commit('X', nil, post)
63
+ end
64
+
65
+ def refund(money, identification, options = {})
66
+ post = {}
67
+ post[:transaction_id] = identification
68
+ post[:client_reference_number] = options[:customer] if options.has_key?(:customer)
69
+ options.delete(:customer)
70
+ options.delete(:billing_address)
71
+ commit('U', money, options.merge(post))
72
+ end
73
+
74
+ def credit(money, creditcard_or_card_id, options = {})
75
+ post = {}
76
+ post[:client_reference_number] = options[:customer] if options.has_key?(:customer)
77
+ add_invoice(post, options)
78
+ add_payment_source(post, creditcard_or_card_id, options)
79
+ commit('C', money, post)
80
+ end
81
+
82
+ def void(transaction_id, options = {})
83
+ post = {}
84
+ post[:transaction_id] = transaction_id
85
+ post[:client_reference_number] = options[:customer] if options.has_key?(:customer)
86
+ options.delete(:customer)
87
+ options.delete(:billing_address)
88
+ commit('V', nil, options.merge(post))
89
+ end
90
+
91
+ private
92
+
93
+ def add_address(post, options)
94
+ if address = options[:billing_address] || options[:address]
95
+ post[:cardholder_street_address] = address[:address1].to_s.gsub(/[^\w.]/, '+')
96
+ post[:cardholder_zip] = address[:zip].to_s
97
+ end
98
+ end
99
+
100
+ def add_invoice(post, options)
101
+ if options.has_key? :order_id
102
+ post[:invoice_number] = options[:order_id].to_s.gsub(/[^\w.]/, '')
103
+ end
104
+ end
105
+
106
+ def add_payment_source(post, creditcard_or_card_id, options)
107
+ if creditcard_or_card_id.is_a?(String)
108
+ # using stored card
109
+ post[:card_id] = creditcard_or_card_id
110
+ post[:card_exp_date] = options[:expiration_date] if options[:expiration_date]
111
+ else
112
+ # card info is provided
113
+ add_creditcard(post, creditcard_or_card_id, options)
114
+ end
115
+ end
116
+
117
+ def add_creditcard(post, creditcard, options)
118
+ post[:card_number] = creditcard.number
119
+ post[:cvv2] = creditcard.verification_value if creditcard.verification_value?
120
+ post[:card_exp_date] = expdate(creditcard)
121
+ end
122
+
123
+ def parse(body)
124
+ results = {}
125
+ body.split(/&/).each do |pair|
126
+ key,val = pair.split(/=/)
127
+ results[key] = val
128
+ end
129
+ results
130
+ end
131
+
132
+ def commit(action, money, parameters)
133
+ url = test? ? self.test_url : self.live_url
134
+ parameters[:transaction_amount] = amount(money) if money unless action == 'V'
135
+
136
+
137
+ response = begin
138
+ parse( ssl_post(url, post_data(action,parameters)) )
139
+ rescue ActiveMerchant::ResponseError => e
140
+ { "error_code" => "404", "auth_response_text" => e.to_s }
141
+ end
142
+
143
+ Response.new(response["error_code"] == "000", message_from(response), response,
144
+ :authorization => response["transaction_id"],
145
+ :test => test?,
146
+ :cvv_result => response["cvv2_result"],
147
+ :avs_result => { :code => response["avs_result"] }
148
+ )
149
+ end
150
+
151
+ def message_from(response)
152
+ if response["error_code"] == "000"
153
+ "This transaction has been approved"
154
+ else
155
+ response["auth_response_text"]
156
+ end
157
+ end
158
+
159
+ def post_data(action, parameters = {})
160
+ post = {}
161
+ post[:profile_id] = @options[:login]
162
+ post[:profile_key] = @options[:password]
163
+ post[:transaction_type] = action if action
164
+
165
+ request = post.merge(parameters).map {|key,value| "#{key}=#{CGI.escape(value.to_s)}"}.join("&")
166
+ request
167
+ end
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,114 @@
1
+ require "cgi"
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ class MerchantOneGateway < Gateway
6
+
7
+ class MerchantOneSslConnection < ActiveMerchant::Connection
8
+ def configure_ssl(http)
9
+ super(http)
10
+ http.use_ssl = true
11
+ end
12
+ end
13
+
14
+ BASE_URL = 'https://secure.merchantonegateway.com/api/transact.php'
15
+
16
+ self.supported_countries = ['US']
17
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
18
+ self.homepage_url = 'http://merchantone.com/'
19
+ self.display_name = 'Merchant One Gateway'
20
+ self.money_format = :dollars
21
+
22
+ def initialize(options = {})
23
+ requires!(options, :username, :password)
24
+ super
25
+ end
26
+
27
+ def authorize(money, creditcard, options = {})
28
+ post = {}
29
+ add_customer_data(post, options)
30
+ add_creditcard(post, creditcard)
31
+ add_address(post, creditcard, options)
32
+ add_customer_data(post, options)
33
+ add_amount(post, money, options)
34
+ commit('auth', money, post)
35
+ end
36
+
37
+ def purchase(money, creditcard, options = {})
38
+ post = {}
39
+ add_customer_data(post, options)
40
+ add_creditcard(post, creditcard)
41
+ add_address(post, creditcard, options)
42
+ add_customer_data(post, options)
43
+ add_amount(post, money, options)
44
+ commit('sale', money, post)
45
+ end
46
+
47
+ def capture(money, authorization, options = {})
48
+ post = {}
49
+ post.merge!(:transactionid => authorization)
50
+ add_amount(post, money, options)
51
+ commit('capture', money, post)
52
+ end
53
+
54
+ def new_connection(endpoint)
55
+ MerchantOneSslConnection.new(endpoint)
56
+ end
57
+
58
+ private
59
+
60
+ def add_customer_data(post, options)
61
+ post['firstname'] = options[:billing_address][:first_name]
62
+ post['lastname'] = options[:billing_address][:last_name]
63
+ end
64
+
65
+ def add_amount(post, money, options)
66
+ post['amount'] = amount(money)
67
+ end
68
+
69
+ def add_address(post, creditcard, options)
70
+ post['address1'] = options[:billing_address][:address1]
71
+ post['city'] = options[:billing_address][:city]
72
+ post['state'] = options[:billing_address][:state]
73
+ post['zip'] = options[:billing_address][:zip]
74
+ post['country'] = options[:billing_address][:country]
75
+ end
76
+
77
+ def add_creditcard(post, creditcard)
78
+ post['cvv'] = creditcard.verification_value
79
+ post['ccnumber'] = creditcard.number
80
+ post['ccexp'] = "#{sprintf("%02d", creditcard.month)}#{"#{creditcard.year}"[-2, 2]}"
81
+ end
82
+
83
+ def commit(action, money, parameters={})
84
+ parameters['username'] = @options[:username]
85
+ parameters['password'] = @options[:password]
86
+ parse(ssl_post(BASE_URL,post_data(action, parameters)))
87
+ end
88
+
89
+ def post_data(action, parameters = {})
90
+ parameters.merge!({:type => action})
91
+ ret = ""
92
+ for key in parameters.keys
93
+ ret += "#{key}=#{CGI.escape(parameters[key].to_s)}"
94
+ if key != parameters.keys.last
95
+ ret += "&"
96
+ end
97
+ end
98
+ ret.to_s
99
+ end
100
+
101
+ def parse(data)
102
+ responses = CGI.parse(data).inject({}){|h,(k, v)| h[k] = v.first; h}
103
+ Response.new(
104
+ (responses["response"].to_i == 1),
105
+ responses["responsetext"],
106
+ responses,
107
+ :test => test?,
108
+ :authorization => responses["transactionid"]
109
+ )
110
+ end
111
+ end
112
+ end
113
+ end
114
+