aktivemerchant 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +1596 -0
- data/CONTRIBUTORS +511 -0
- data/MIT-LICENSE +20 -0
- data/README.md +18 -0
- data/lib/active_merchant.rb +108 -0
- data/lib/active_merchant/billing.rb +13 -0
- data/lib/active_merchant/billing/apple_pay_payment_token.rb +22 -0
- data/lib/active_merchant/billing/avs_result.rb +98 -0
- data/lib/active_merchant/billing/base.rb +72 -0
- data/lib/active_merchant/billing/check.rb +76 -0
- data/lib/active_merchant/billing/compatibility.rb +120 -0
- data/lib/active_merchant/billing/credit_card.rb +352 -0
- data/lib/active_merchant/billing/credit_card_formatting.rb +24 -0
- data/lib/active_merchant/billing/credit_card_methods.rb +160 -0
- data/lib/active_merchant/billing/cvv_result.rb +38 -0
- data/lib/active_merchant/billing/gateway.rb +268 -0
- data/lib/active_merchant/billing/gateways.rb +17 -0
- data/lib/active_merchant/billing/gateways/adyen.rb +209 -0
- data/lib/active_merchant/billing/gateways/alfabank.rb +117 -0
- data/lib/active_merchant/billing/gateways/app55.rb +176 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +419 -0
- data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +417 -0
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +976 -0
- data/lib/active_merchant/billing/gateways/balanced.rb +256 -0
- data/lib/active_merchant/billing/gateways/bank_frick.rb +225 -0
- data/lib/active_merchant/billing/gateways/banwire.rb +105 -0
- data/lib/active_merchant/billing/gateways/barclays_epdq.rb +314 -0
- data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +15 -0
- data/lib/active_merchant/billing/gateways/be2bill.rb +131 -0
- data/lib/active_merchant/billing/gateways/beanstream.rb +188 -0
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +393 -0
- data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
- data/lib/active_merchant/billing/gateways/blue_pay.rb +506 -0
- data/lib/active_merchant/billing/gateways/bogus.rb +140 -0
- data/lib/active_merchant/billing/gateways/borgun.rb +210 -0
- data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
- data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
- data/lib/active_merchant/billing/gateways/braintree_blue.rb +515 -0
- data/lib/active_merchant/billing/gateways/braintree_orange.rb +20 -0
- data/lib/active_merchant/billing/gateways/bridge_pay.rb +189 -0
- data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
- data/lib/active_merchant/billing/gateways/card_stream.rb +220 -0
- data/lib/active_merchant/billing/gateways/cashnet.rb +191 -0
- data/lib/active_merchant/billing/gateways/cc5.rb +201 -0
- data/lib/active_merchant/billing/gateways/cecabank.rb +229 -0
- data/lib/active_merchant/billing/gateways/certo_direct.rb +278 -0
- data/lib/active_merchant/billing/gateways/checkout.rb +213 -0
- data/lib/active_merchant/billing/gateways/commercegate.rb +143 -0
- data/lib/active_merchant/billing/gateways/conekta.rb +209 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +709 -0
- data/lib/active_merchant/billing/gateways/data_cash.rb +600 -0
- data/lib/active_merchant/billing/gateways/efsnet.rb +219 -0
- data/lib/active_merchant/billing/gateways/elavon.rb +348 -0
- data/lib/active_merchant/billing/gateways/epay.rb +275 -0
- data/lib/active_merchant/billing/gateways/evo_ca.rb +308 -0
- data/lib/active_merchant/billing/gateways/eway.rb +214 -0
- data/lib/active_merchant/billing/gateways/eway_managed.rb +291 -0
- data/lib/active_merchant/billing/gateways/eway_rapid.rb +524 -0
- data/lib/active_merchant/billing/gateways/exact.rb +218 -0
- data/lib/active_merchant/billing/gateways/fat_zebra.rb +173 -0
- data/lib/active_merchant/billing/gateways/federated_canada.rb +160 -0
- data/lib/active_merchant/billing/gateways/finansbank.rb +23 -0
- data/lib/active_merchant/billing/gateways/first_giving.rb +143 -0
- data/lib/active_merchant/billing/gateways/first_pay.rb +160 -0
- data/lib/active_merchant/billing/gateways/firstdata_e4.rb +355 -0
- data/lib/active_merchant/billing/gateways/garanti.rb +257 -0
- data/lib/active_merchant/billing/gateways/global_transport.rb +183 -0
- data/lib/active_merchant/billing/gateways/hdfc.rb +207 -0
- data/lib/active_merchant/billing/gateways/hps.rb +288 -0
- data/lib/active_merchant/billing/gateways/iats_payments.rb +251 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +246 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
- data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +66 -0
- data/lib/active_merchant/billing/gateways/inspire.rb +213 -0
- data/lib/active_merchant/billing/gateways/instapay.rb +163 -0
- data/lib/active_merchant/billing/gateways/iridium.rb +457 -0
- data/lib/active_merchant/billing/gateways/itransact.rb +448 -0
- data/lib/active_merchant/billing/gateways/jetpay.rb +275 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +438 -0
- data/lib/active_merchant/billing/gateways/litle.rb +346 -0
- data/lib/active_merchant/billing/gateways/maxipago.rb +197 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +170 -0
- data/lib/active_merchant/billing/gateways/merchant_one.rb +114 -0
- data/lib/active_merchant/billing/gateways/merchant_ware.rb +319 -0
- data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +268 -0
- data/lib/active_merchant/billing/gateways/merchant_warrior.rb +195 -0
- data/lib/active_merchant/billing/gateways/mercury.rb +333 -0
- data/lib/active_merchant/billing/gateways/metrics_global.rb +303 -0
- data/lib/active_merchant/billing/gateways/migs.rb +265 -0
- data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
- data/lib/active_merchant/billing/gateways/modern_payments.rb +37 -0
- data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +219 -0
- data/lib/active_merchant/billing/gateways/moneris.rb +309 -0
- data/lib/active_merchant/billing/gateways/moneris_us.rb +291 -0
- data/lib/active_merchant/billing/gateways/money_movers.rb +152 -0
- data/lib/active_merchant/billing/gateways/nab_transact.rb +280 -0
- data/lib/active_merchant/billing/gateways/net_registry.rb +198 -0
- data/lib/active_merchant/billing/gateways/netaxept.rb +181 -0
- data/lib/active_merchant/billing/gateways/netbilling.rb +190 -0
- data/lib/active_merchant/billing/gateways/netpay.rb +223 -0
- data/lib/active_merchant/billing/gateways/network_merchants.rb +242 -0
- data/lib/active_merchant/billing/gateways/nmi.rb +256 -0
- data/lib/active_merchant/billing/gateways/ogone.rb +435 -0
- data/lib/active_merchant/billing/gateways/openpay.rb +194 -0
- data/lib/active_merchant/billing/gateways/optimal_payment.rb +313 -0
- data/lib/active_merchant/billing/gateways/orbital.rb +803 -0
- data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +47 -0
- data/lib/active_merchant/billing/gateways/pac_net_raven.rb +207 -0
- data/lib/active_merchant/billing/gateways/pago_facil.rb +122 -0
- data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +261 -0
- data/lib/active_merchant/billing/gateways/pay_junction.rb +390 -0
- data/lib/active_merchant/billing/gateways/pay_secure.rb +112 -0
- data/lib/active_merchant/billing/gateways/pay_u_latam.rb +462 -0
- data/lib/active_merchant/billing/gateways/paybox_direct.rb +188 -0
- data/lib/active_merchant/billing/gateways/payex.rb +412 -0
- data/lib/active_merchant/billing/gateways/payflow.rb +304 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +209 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
- data/lib/active_merchant/billing/gateways/payflow_express.rb +224 -0
- data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
- data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
- data/lib/active_merchant/billing/gateways/payment_express.rb +353 -0
- data/lib/active_merchant/billing/gateways/paymill.rb +281 -0
- data/lib/active_merchant/billing/gateways/paypal.rb +117 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +670 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +65 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +262 -0
- data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
- data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +44 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +264 -0
- data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
- data/lib/active_merchant/billing/gateways/payscout.rb +162 -0
- data/lib/active_merchant/billing/gateways/paystation.rb +199 -0
- data/lib/active_merchant/billing/gateways/payway.rb +207 -0
- data/lib/active_merchant/billing/gateways/pin.rb +197 -0
- data/lib/active_merchant/billing/gateways/plugnpay.rb +283 -0
- data/lib/active_merchant/billing/gateways/psigate.rb +216 -0
- data/lib/active_merchant/billing/gateways/psl_card.rb +303 -0
- data/lib/active_merchant/billing/gateways/qbms.rb +292 -0
- data/lib/active_merchant/billing/gateways/quantum.rb +276 -0
- data/lib/active_merchant/billing/gateways/quickpay.rb +367 -0
- data/lib/active_merchant/billing/gateways/realex.rb +298 -0
- data/lib/active_merchant/billing/gateways/redsys.rb +391 -0
- data/lib/active_merchant/billing/gateways/sage.rb +175 -0
- data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +87 -0
- data/lib/active_merchant/billing/gateways/sage/sage_core.rb +114 -0
- data/lib/active_merchant/billing/gateways/sage/sage_vault.rb +149 -0
- data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +102 -0
- data/lib/active_merchant/billing/gateways/sage_pay.rb +398 -0
- data/lib/active_merchant/billing/gateways/sallie_mae.rb +143 -0
- data/lib/active_merchant/billing/gateways/secure_net.rb +252 -0
- data/lib/active_merchant/billing/gateways/secure_pay.rb +201 -0
- data/lib/active_merchant/billing/gateways/secure_pay_au.rb +281 -0
- data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +105 -0
- data/lib/active_merchant/billing/gateways/skip_jack.rb +452 -0
- data/lib/active_merchant/billing/gateways/smart_ps.rb +283 -0
- data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
- data/lib/active_merchant/billing/gateways/spreedly_core.rb +247 -0
- data/lib/active_merchant/billing/gateways/stripe.rb +411 -0
- data/lib/active_merchant/billing/gateways/swipe_checkout.rb +157 -0
- data/lib/active_merchant/billing/gateways/tns.rb +227 -0
- data/lib/active_merchant/billing/gateways/trans_first.rb +126 -0
- data/lib/active_merchant/billing/gateways/transax.rb +23 -0
- data/lib/active_merchant/billing/gateways/transnational.rb +10 -0
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +416 -0
- data/lib/active_merchant/billing/gateways/usa_epay.rb +25 -0
- data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1516 -0
- data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +254 -0
- data/lib/active_merchant/billing/gateways/verifi.rb +225 -0
- data/lib/active_merchant/billing/gateways/viaklix.rb +183 -0
- data/lib/active_merchant/billing/gateways/vindicia.rb +385 -0
- data/lib/active_merchant/billing/gateways/webpay.rb +97 -0
- data/lib/active_merchant/billing/gateways/wepay.rb +189 -0
- data/lib/active_merchant/billing/gateways/wirecard.rb +421 -0
- data/lib/active_merchant/billing/gateways/worldpay.rb +331 -0
- data/lib/active_merchant/billing/gateways/worldpay_us.rb +181 -0
- data/lib/active_merchant/billing/model.rb +30 -0
- data/lib/active_merchant/billing/payment_token.rb +21 -0
- data/lib/active_merchant/billing/rails.rb +3 -0
- data/lib/active_merchant/billing/response.rb +91 -0
- data/lib/active_merchant/country.rb +332 -0
- data/lib/active_merchant/empty.rb +20 -0
- data/lib/active_merchant/errors.rb +29 -0
- data/lib/active_merchant/offsite_payments_shim.rb +19 -0
- data/lib/active_merchant/version.rb +3 -0
- data/lib/activemerchant.rb +1 -0
- data/lib/support/gateway_support.rb +71 -0
- data/lib/support/outbound_hosts.rb +25 -0
- data/lib/support/ssl_verify.rb +93 -0
- metadata +400 -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
|
+
|