activemerchant-kiddy 1.15.0.kiddy
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +688 -0
- data/CONTRIBUTORS +233 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +164 -0
- data/gem-public_cert.pem +20 -0
- data/lib/active_merchant/billing/avs_result.rb +98 -0
- data/lib/active_merchant/billing/base.rb +57 -0
- data/lib/active_merchant/billing/check.rb +68 -0
- data/lib/active_merchant/billing/credit_card.rb +172 -0
- data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
- data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
- data/lib/active_merchant/billing/cvv_result.rb +38 -0
- data/lib/active_merchant/billing/expiry_date.rb +34 -0
- data/lib/active_merchant/billing/gateway.rb +170 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +671 -0
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +858 -0
- data/lib/active_merchant/billing/gateways/barclays_epdq.rb +309 -0
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +282 -0
- data/lib/active_merchant/billing/gateways/beanstream.rb +139 -0
- data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
- data/lib/active_merchant/billing/gateways/blue_pay.rb +11 -0
- data/lib/active_merchant/billing/gateways/bogus.rb +132 -0
- data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
- data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
- data/lib/active_merchant/billing/gateways/braintree_blue.rb +293 -0
- data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
- data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +410 -0
- data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
- data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
- data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
- data/lib/active_merchant/billing/gateways/epay.rb +268 -0
- data/lib/active_merchant/billing/gateways/eway.rb +277 -0
- data/lib/active_merchant/billing/gateways/eway_managed.rb +231 -0
- data/lib/active_merchant/billing/gateways/exact.rb +222 -0
- data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
- data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
- data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +250 -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 +55 -0
- data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
- data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
- data/lib/active_merchant/billing/gateways/iridium.rb +258 -0
- data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +454 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +156 -0
- data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
- data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
- data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
- data/lib/active_merchant/billing/gateways/moneris.rb +209 -0
- data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
- data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
- data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
- data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
- data/lib/active_merchant/billing/gateways/ogone.rb +292 -0
- data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
- data/lib/active_merchant/billing/gateways/orbital.rb +317 -0
- data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
- data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
- data/lib/active_merchant/billing/gateways/paybox_direct.rb +207 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -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.rb +253 -0
- data/lib/active_merchant/billing/gateways/payflow_express.rb +222 -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 +235 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +351 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
- data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
- data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +177 -0
- data/lib/active_merchant/billing/gateways/paypal_express_common.rb +25 -0
- data/lib/active_merchant/billing/gateways/plugnpay.rb +298 -0
- data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
- data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
- data/lib/active_merchant/billing/gateways/qbms.rb +295 -0
- data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
- data/lib/active_merchant/billing/gateways/quickpay.rb +218 -0
- data/lib/active_merchant/billing/gateways/realex.rb +311 -0
- data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
- data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
- data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
- data/lib/active_merchant/billing/gateways/sage.rb +146 -0
- data/lib/active_merchant/billing/gateways/sage_pay.rb +320 -0
- data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
- data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
- data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
- data/lib/active_merchant/billing/gateways/secure_pay_au.rb +193 -0
- data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
- data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
- data/lib/active_merchant/billing/gateways/smart_ps.rb +271 -0
- data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
- data/lib/active_merchant/billing/gateways/transax.rb +25 -0
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +423 -0
- data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
- data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
- data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
- data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
- data/lib/active_merchant/billing/gateways/worldpay.rb +280 -0
- data/lib/active_merchant/billing/gateways.rb +18 -0
- data/lib/active_merchant/billing/integrations/action_view_helper.rb +68 -0
- data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
- data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
- data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
- data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
- data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
- data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
- data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
- data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
- data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
- data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
- data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
- data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
- data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
- data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
- data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
- data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
- data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
- data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
- data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
- data/lib/active_merchant/billing/integrations/helper.rb +96 -0
- data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
- data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
- data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
- data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
- data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +48 -0
- data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
- data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
- data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
- data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
- data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
- data/lib/active_merchant/billing/integrations/notification.rb +62 -0
- data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
- data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
- data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
- data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
- data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
- data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
- data/lib/active_merchant/billing/integrations/return.rb +42 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +111 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
- data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
- data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
- data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
- data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
- data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
- data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
- data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +88 -0
- data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
- data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
- data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
- data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
- data/lib/active_merchant/billing/integrations/world_pay.rb +38 -0
- data/lib/active_merchant/billing/integrations.rb +17 -0
- data/lib/active_merchant/billing/response.rb +32 -0
- data/lib/active_merchant/billing.rb +9 -0
- data/lib/active_merchant/common/connection.rb +177 -0
- data/lib/active_merchant/common/country.rb +328 -0
- data/lib/active_merchant/common/error.rb +26 -0
- data/lib/active_merchant/common/post_data.rb +24 -0
- data/lib/active_merchant/common/posts_data.rb +63 -0
- data/lib/active_merchant/common/requires_parameters.rb +16 -0
- data/lib/active_merchant/common/utils.rb +22 -0
- data/lib/active_merchant/common/validateable.rb +81 -0
- data/lib/active_merchant/common.rb +14 -0
- data/lib/active_merchant/version.rb +3 -0
- data/lib/active_merchant.rb +50 -0
- data/lib/activemerchant.rb +1 -0
- data/lib/certs/cacert.pem +7815 -0
- data/lib/support/gateway_support.rb +58 -0
- data/lib/support/outbound_hosts.rb +25 -0
- metadata +273 -0
@@ -0,0 +1,289 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class MerchantWareGateway < Gateway
|
4
|
+
URL = 'https://ps1.merchantware.net/MerchantWARE/ws/RetailTransaction/TXRetail.asmx'
|
5
|
+
|
6
|
+
self.supported_countries = ['US']
|
7
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :discover]
|
8
|
+
self.homepage_url = 'http://merchantwarehouse.com/merchantware'
|
9
|
+
self.display_name = 'MerchantWARE'
|
10
|
+
|
11
|
+
ENV_NAMESPACES = { "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
|
12
|
+
"xmlns:xsd" => "http://www.w3.org/2001/XMLSchema",
|
13
|
+
"xmlns:env" => "http://schemas.xmlsoap.org/soap/envelope/"
|
14
|
+
}
|
15
|
+
TX_NAMESPACE = "http://merchantwarehouse.com/MerchantWARE/Client/TransactionRetail"
|
16
|
+
|
17
|
+
ACTIONS = {
|
18
|
+
:purchase => "IssueKeyedSale",
|
19
|
+
:authorize => "IssueKeyedPreAuth",
|
20
|
+
:capture => "IssuePostAuth",
|
21
|
+
:void => "IssueVoid",
|
22
|
+
:credit => "IssueKeyedRefund",
|
23
|
+
:reference_credit => "IssueRefundByReference"
|
24
|
+
}
|
25
|
+
|
26
|
+
# Creates a new MerchantWareGateway
|
27
|
+
#
|
28
|
+
# The gateway requires that a valid login, password, and name be passed
|
29
|
+
# in the +options+ hash.
|
30
|
+
#
|
31
|
+
# ==== Options
|
32
|
+
#
|
33
|
+
# * <tt>:login</tt> - The MerchantWARE SiteID.
|
34
|
+
# * <tt>:password</tt> - The MerchantWARE Key.
|
35
|
+
# * <tt>:name</tt> - The MerchantWARE Name.
|
36
|
+
def initialize(options = {})
|
37
|
+
requires!(options, :login, :password, :name)
|
38
|
+
@options = options
|
39
|
+
super
|
40
|
+
end
|
41
|
+
|
42
|
+
# Authorize a credit card for a given amount.
|
43
|
+
#
|
44
|
+
# ==== Parameters
|
45
|
+
# * <tt>money</tt> - The amount to be authorized as an Integer value in cents.
|
46
|
+
# * <tt>credit_card</tt> - The CreditCard details for the transaction.
|
47
|
+
# * <tt>options</tt>
|
48
|
+
# * <tt>:order_id</tt> - A unique reference for this order (required).
|
49
|
+
# * <tt>:billing_address</tt> - The billing address for the cardholder.
|
50
|
+
def authorize(money, credit_card, options = {})
|
51
|
+
request = build_purchase_request(:authorize, money, credit_card, options)
|
52
|
+
commit(:authorize, request)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Authorize and immediately capture funds from a credit card.
|
56
|
+
#
|
57
|
+
# ==== Parameters
|
58
|
+
# * <tt>money</tt> - The amount to be authorized as anInteger value in cents.
|
59
|
+
# * <tt>credit_card</tt> - The CreditCard details for the transaction.
|
60
|
+
# * <tt>options</tt>
|
61
|
+
# * <tt>:order_id</tt> - A unique reference for this order (required).
|
62
|
+
# * <tt>:billing_address</tt> - The billing address for the cardholder.
|
63
|
+
def purchase(money, credit_card, options = {})
|
64
|
+
request = build_purchase_request(:purchase, money, credit_card, options)
|
65
|
+
commit(:purchase, request)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Capture authorized funds from a credit card.
|
69
|
+
#
|
70
|
+
# ==== Parameters
|
71
|
+
# * <tt>money</tt> - The amount to be captured as anInteger value in cents.
|
72
|
+
# * <tt>authorization</tt> - The authorization string returned from the initial authorization.
|
73
|
+
def capture(money, authorization, options = {})
|
74
|
+
request = build_capture_request(:capture, money, authorization, options)
|
75
|
+
commit(:capture, request)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Void a transaction.
|
79
|
+
#
|
80
|
+
# ==== Parameters
|
81
|
+
# * <tt>authorization</tt> - The authorization string returned from the initial authorization or purchase.
|
82
|
+
def void(authorization, options = {})
|
83
|
+
reference, options[:order_id] = split_reference(authorization)
|
84
|
+
|
85
|
+
request = soap_request(:void) do |xml|
|
86
|
+
add_reference(xml, reference)
|
87
|
+
end
|
88
|
+
commit(:void, request)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Refund an amount back a cardholder
|
92
|
+
#
|
93
|
+
# ==== Parameters
|
94
|
+
#
|
95
|
+
# * <tt>money</tt> - The amount to be refunded as an Integer value in cents.
|
96
|
+
# * <tt>identification</tt> - The credit card you want to refund or the authorization for the existing transaction you are refunding.
|
97
|
+
# * <tt>options</tt>
|
98
|
+
# * <tt>:order_id</tt> - A unique reference for this order (required when performing a non-referenced credit)
|
99
|
+
def credit(money, identification, options = {})
|
100
|
+
if identification.is_a?(String)
|
101
|
+
deprecated CREDIT_DEPRECATION_MESSAGE
|
102
|
+
refund(money, identification, options)
|
103
|
+
else
|
104
|
+
perform_credit(money, identification, options)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def refund(money, reference, options = {})
|
109
|
+
perform_reference_credit(money, reference, options)
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
def soap_request(action)
|
116
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
117
|
+
xml.instruct!
|
118
|
+
xml.tag! "env:Envelope", ENV_NAMESPACES do
|
119
|
+
xml.tag! "env:Body" do
|
120
|
+
xml.tag! ACTIONS[action], "xmlns" => TX_NAMESPACE do
|
121
|
+
add_credentials(xml)
|
122
|
+
yield xml
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
xml.target!
|
127
|
+
end
|
128
|
+
|
129
|
+
def build_purchase_request(action, money, credit_card, options)
|
130
|
+
requires!(options, :order_id)
|
131
|
+
|
132
|
+
request = soap_request(action) do |xml|
|
133
|
+
add_invoice(xml, options)
|
134
|
+
add_amount(xml, money)
|
135
|
+
add_credit_card(xml, credit_card)
|
136
|
+
add_address(xml, options)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def build_capture_request(action, money, identification, options)
|
141
|
+
reference, options[:order_id] = split_reference(identification)
|
142
|
+
|
143
|
+
request = soap_request(action) do |xml|
|
144
|
+
add_reference(xml, reference)
|
145
|
+
add_invoice(xml, options)
|
146
|
+
add_amount(xml, money)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def perform_reference_credit(money, identification, options)
|
151
|
+
reference, options[:order_id] = split_reference(identification)
|
152
|
+
|
153
|
+
request = soap_request(:reference_credit) do |xml|
|
154
|
+
add_reference(xml, reference)
|
155
|
+
add_invoice(xml, options)
|
156
|
+
add_amount(xml, money, "strOverrideAmount")
|
157
|
+
end
|
158
|
+
|
159
|
+
commit(:reference_credit, request)
|
160
|
+
end
|
161
|
+
|
162
|
+
def perform_credit(money, credit_card, options)
|
163
|
+
requires!(options, :order_id)
|
164
|
+
|
165
|
+
request = soap_request(:credit) do |xml|
|
166
|
+
add_invoice(xml, options)
|
167
|
+
add_amount(xml, money)
|
168
|
+
add_credit_card(xml, credit_card)
|
169
|
+
end
|
170
|
+
|
171
|
+
commit(:credit, request)
|
172
|
+
end
|
173
|
+
|
174
|
+
def add_credentials(xml)
|
175
|
+
xml.tag! "strSiteId", @options[:login]
|
176
|
+
xml.tag! "strKey", @options[:password]
|
177
|
+
xml.tag! "strName", @options[:name]
|
178
|
+
end
|
179
|
+
|
180
|
+
def expdate(credit_card)
|
181
|
+
year = sprintf("%.4i", credit_card.year)
|
182
|
+
month = sprintf("%.2i", credit_card.month)
|
183
|
+
|
184
|
+
"#{month}#{year[-2..-1]}"
|
185
|
+
end
|
186
|
+
|
187
|
+
def add_invoice(xml, options)
|
188
|
+
xml.tag! "strOrderNumber", options[:order_id].to_s.gsub(/[^\w]/, '').slice(0, 25)
|
189
|
+
end
|
190
|
+
|
191
|
+
def add_amount(xml, money, tag = "strAmount")
|
192
|
+
xml.tag! tag, amount(money)
|
193
|
+
end
|
194
|
+
|
195
|
+
def add_reference(xml, reference)
|
196
|
+
xml.tag! "strReferenceCode", reference
|
197
|
+
end
|
198
|
+
|
199
|
+
def add_address(xml, options)
|
200
|
+
if address = options[:billing_address] || options[:address]
|
201
|
+
xml.tag! "strAVSStreetAddress", address[:address1]
|
202
|
+
xml.tag! "strAVSZipCode", address[:zip]
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def add_credit_card(xml, credit_card)
|
207
|
+
xml.tag! "strPAN", credit_card.number
|
208
|
+
xml.tag! "strExpDate", expdate(credit_card)
|
209
|
+
xml.tag! "strCardHolder", credit_card.name
|
210
|
+
xml.tag! "strCVCode", credit_card.verification_value if credit_card.verification_value?
|
211
|
+
end
|
212
|
+
|
213
|
+
def split_reference(reference)
|
214
|
+
reference.to_s.split(";")
|
215
|
+
end
|
216
|
+
|
217
|
+
def parse(action, data)
|
218
|
+
response = {}
|
219
|
+
xml = REXML::Document.new(data)
|
220
|
+
|
221
|
+
root = REXML::XPath.first(xml, "//#{ACTIONS[action]}Response/#{ACTIONS[action]}Result")
|
222
|
+
|
223
|
+
root.elements.each do |element|
|
224
|
+
response[element.name] = element.text
|
225
|
+
end
|
226
|
+
|
227
|
+
status, code, message = response["ApprovalStatus"].split(";")
|
228
|
+
response[:status] = status
|
229
|
+
|
230
|
+
if response[:success] = status == "APPROVED"
|
231
|
+
response[:message] = status
|
232
|
+
else
|
233
|
+
response[:message] = message
|
234
|
+
response[:failure_code] = code
|
235
|
+
end
|
236
|
+
|
237
|
+
response
|
238
|
+
end
|
239
|
+
|
240
|
+
def parse_error(http_response)
|
241
|
+
response = {}
|
242
|
+
response[:http_code] = http_response.code
|
243
|
+
response[:http_message] = http_response.message
|
244
|
+
response[:success] = false
|
245
|
+
|
246
|
+
document = REXML::Document.new(http_response.body)
|
247
|
+
|
248
|
+
node = REXML::XPath.first(document, "//soap:Fault")
|
249
|
+
|
250
|
+
node.elements.each do |element|
|
251
|
+
response[element.name] = element.text
|
252
|
+
end
|
253
|
+
|
254
|
+
response[:message] = response["faultstring"].to_s.gsub("\n", " ")
|
255
|
+
response
|
256
|
+
rescue REXML::ParseException => e
|
257
|
+
response[:http_body] = http_response.body
|
258
|
+
response[:message] = "Failed to parse the failed response"
|
259
|
+
response
|
260
|
+
end
|
261
|
+
|
262
|
+
def commit(action, request)
|
263
|
+
begin
|
264
|
+
data = ssl_post(URL, request,
|
265
|
+
"Content-Type" => 'text/xml; charset=utf-8',
|
266
|
+
"SOAPAction" => "http://merchantwarehouse.com/MerchantWARE/Client/TransactionRetail/#{ACTIONS[action]}"
|
267
|
+
)
|
268
|
+
response = parse(action, data)
|
269
|
+
rescue ActiveMerchant::ResponseError => e
|
270
|
+
response = parse_error(e.response)
|
271
|
+
end
|
272
|
+
|
273
|
+
Response.new(response[:success], response[:message], response,
|
274
|
+
:test => test?,
|
275
|
+
:authorization => authorization_from(response),
|
276
|
+
:avs_result => { :code => response["AVSResponse"] },
|
277
|
+
:cvv_result => response["CVResponse"]
|
278
|
+
)
|
279
|
+
end
|
280
|
+
|
281
|
+
def authorization_from(response)
|
282
|
+
if response[:success]
|
283
|
+
[ response["ReferenceID"], response["OrderNumber"] ].join(";")
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/modern_payments_cim'
|
2
|
+
|
3
|
+
module ActiveMerchant #:nodoc:
|
4
|
+
module Billing #:nodoc:
|
5
|
+
class ModernPaymentsGateway < Gateway
|
6
|
+
self.supported_countries = ModernPaymentsCimGateway.supported_countries
|
7
|
+
self.supported_cardtypes = ModernPaymentsCimGateway.supported_cardtypes
|
8
|
+
self.homepage_url = ModernPaymentsCimGateway.homepage_url
|
9
|
+
self.display_name = ModernPaymentsCimGateway.display_name
|
10
|
+
|
11
|
+
def initialize(options = {})
|
12
|
+
requires!(options, :login, :password)
|
13
|
+
@options = options
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def purchase(money, credit_card, options = {})
|
18
|
+
customer_response = cim.create_customer(options)
|
19
|
+
return customer_response unless customer_response.success?
|
20
|
+
|
21
|
+
customer_id = customer_response.params["create_customer_result"]
|
22
|
+
|
23
|
+
card_response = cim.modify_customer_credit_card(customer_id, credit_card)
|
24
|
+
return card_response unless card_response.success?
|
25
|
+
|
26
|
+
cim.authorize_credit_card_payment(customer_id, money)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def cim
|
31
|
+
@cim ||= ModernPaymentsCimGateway.new(@options)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,220 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class ModernPaymentsCimGateway < Gateway #:nodoc:
|
4
|
+
TEST_URL = "https://secure.modpay.com/netservices/test/ModpayTest.asmx"
|
5
|
+
LIVE_URL = 'https://secure.modpay.com/ws/modpay.asmx'
|
6
|
+
|
7
|
+
LIVE_XMLNS = "https://secure.modpay.com/ws/"
|
8
|
+
TEST_XMLNS = "https://secure.modpay.com/netservices/test/"
|
9
|
+
|
10
|
+
self.supported_countries = ['US']
|
11
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :discover]
|
12
|
+
self.homepage_url = 'http://www.modpay.com'
|
13
|
+
self.display_name = 'Modern Payments'
|
14
|
+
|
15
|
+
SUCCESS_MESSAGE = "Transaction accepted"
|
16
|
+
FAILURE_MESSAGE = "Transaction failed"
|
17
|
+
ERROR_MESSAGE = "Transaction error"
|
18
|
+
|
19
|
+
PAYMENT_METHOD = {
|
20
|
+
:check => 1,
|
21
|
+
:credit_card => 2
|
22
|
+
}
|
23
|
+
|
24
|
+
def initialize(options = {})
|
25
|
+
requires!(options, :login, :password)
|
26
|
+
@options = options
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_customer(options = {})
|
31
|
+
post = {}
|
32
|
+
add_customer_data(post, options)
|
33
|
+
add_address(post, options)
|
34
|
+
|
35
|
+
commit('CreateCustomer', post)
|
36
|
+
end
|
37
|
+
|
38
|
+
def modify_customer_credit_card(customer_id, credit_card)
|
39
|
+
raise ArgumentError, "The customer_id cannot be blank" if customer_id.blank?
|
40
|
+
|
41
|
+
post = {}
|
42
|
+
add_customer_id(post, customer_id)
|
43
|
+
add_credit_card(post, credit_card)
|
44
|
+
|
45
|
+
commit('ModifyCustomerCreditCard', post)
|
46
|
+
end
|
47
|
+
|
48
|
+
def authorize_credit_card_payment(customer_id, amount)
|
49
|
+
raise ArgumentError, "The customer_id cannot be blank" if customer_id.blank?
|
50
|
+
|
51
|
+
post = {}
|
52
|
+
add_customer_id(post, customer_id)
|
53
|
+
add_amount(post, amount)
|
54
|
+
|
55
|
+
commit('AuthorizeCreditCardPayment', post)
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_payment(customer_id, amount, options = {})
|
59
|
+
raise ArgumentError, "The customer_id cannot be blank" if customer_id.blank?
|
60
|
+
|
61
|
+
post = {}
|
62
|
+
add_customer_id(post, customer_id)
|
63
|
+
add_amount(post, amount)
|
64
|
+
add_payment_details(post, options)
|
65
|
+
|
66
|
+
commit('CreatePayment', post)
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
def add_payment_details(post, options)
|
71
|
+
post[:pmtDate] = (options[:payment_date] || Time.now.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
72
|
+
post[:pmtType] = PAYMENT_METHOD[options[:payment_method] || :credit_card]
|
73
|
+
end
|
74
|
+
|
75
|
+
def add_amount(post, money)
|
76
|
+
post[:pmtAmount] = amount(money)
|
77
|
+
end
|
78
|
+
|
79
|
+
def add_customer_id(post, customer_id)
|
80
|
+
post[:custId] = customer_id
|
81
|
+
end
|
82
|
+
|
83
|
+
def add_customer_data(post, options)
|
84
|
+
post[:acctNum] = options[:customer]
|
85
|
+
end
|
86
|
+
|
87
|
+
def add_address(post, options)
|
88
|
+
address = options[:billing_address] || options[:address] || {}
|
89
|
+
|
90
|
+
if name = address[:name]
|
91
|
+
segments = name.split(' ')
|
92
|
+
post[:lastName] = segments.pop
|
93
|
+
post[:firstName] = segments.join(' ')
|
94
|
+
else
|
95
|
+
post[:firstName] = address[:first_name]
|
96
|
+
post[:lastName] = address[:last_name]
|
97
|
+
end
|
98
|
+
|
99
|
+
post[:address] = address[:address1]
|
100
|
+
post[:city] = address[:city]
|
101
|
+
post[:state] = address[:state]
|
102
|
+
post[:zip] = address[:zip]
|
103
|
+
post[:phone] = address[:phone]
|
104
|
+
post[:fax] = address[:fax]
|
105
|
+
post[:email] = options[:email]
|
106
|
+
end
|
107
|
+
|
108
|
+
def add_credit_card(post, credit_card)
|
109
|
+
post[:ccName] = credit_card.name
|
110
|
+
post[:ccNum] = credit_card.number
|
111
|
+
post[:expMonth] = credit_card.month
|
112
|
+
post[:expYear] = credit_card.year
|
113
|
+
end
|
114
|
+
|
115
|
+
def build_request(action, params)
|
116
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
117
|
+
xml.instruct!
|
118
|
+
xml.tag! 'env:Envelope',
|
119
|
+
{ 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
|
120
|
+
'xmlns:env' => 'http://schemas.xmlsoap.org/soap/envelope/',
|
121
|
+
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance' } do
|
122
|
+
|
123
|
+
xml.tag! 'env:Body' do
|
124
|
+
xml.tag! action, { "xmlns" => xmlns(action) } do
|
125
|
+
xml.tag! "clientId", @options[:login]
|
126
|
+
xml.tag! "clientCode", @options[:password]
|
127
|
+
params.each {|key, value| xml.tag! key, value }
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
xml.target!
|
132
|
+
end
|
133
|
+
|
134
|
+
def xmlns(action)
|
135
|
+
if test? && action == 'AuthorizeCreditCardPayment'
|
136
|
+
TEST_XMLNS
|
137
|
+
else
|
138
|
+
LIVE_XMLNS
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def url(action)
|
143
|
+
if test? && action == 'AuthorizeCreditCardPayment'
|
144
|
+
TEST_URL
|
145
|
+
else
|
146
|
+
LIVE_URL
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def commit(action, params)
|
151
|
+
data = ssl_post(url(action), build_request(action, params),
|
152
|
+
{ 'Content-Type' =>'text/xml; charset=utf-8',
|
153
|
+
'SOAPAction' => "#{xmlns(action)}#{action}" }
|
154
|
+
)
|
155
|
+
|
156
|
+
response = parse(action, data)
|
157
|
+
Response.new(successful?(action, response), message_from(action, response), response,
|
158
|
+
:test => test?,
|
159
|
+
:authorization => authorization_from(action, response),
|
160
|
+
:avs_result => { :code => response[:avs_code] }
|
161
|
+
)
|
162
|
+
end
|
163
|
+
|
164
|
+
def authorization_from(action, response)
|
165
|
+
response[authorization_key(action)]
|
166
|
+
end
|
167
|
+
|
168
|
+
def authorization_key(action)
|
169
|
+
action == "AuthorizeCreditCardPayment" ? :trans_id : "#{action.underscore}_result".to_sym
|
170
|
+
end
|
171
|
+
|
172
|
+
def successful?(action, response)
|
173
|
+
key = authorization_key(action)
|
174
|
+
|
175
|
+
if key == :trans_id
|
176
|
+
response[:approved] == "true"
|
177
|
+
else
|
178
|
+
response[key].to_i > 0
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def message_from(action, response)
|
183
|
+
if response[:faultcode]
|
184
|
+
ERROR_MESSAGE
|
185
|
+
elsif successful?(action, response)
|
186
|
+
SUCCESS_MESSAGE
|
187
|
+
else
|
188
|
+
FAILURE_MESSAGE
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def parse(action, xml)
|
193
|
+
response = {}
|
194
|
+
response[:action] = action
|
195
|
+
|
196
|
+
xml = REXML::Document.new(xml)
|
197
|
+
if root = REXML::XPath.first(xml, "//#{action}Response")
|
198
|
+
root.elements.to_a.each do |node|
|
199
|
+
parse_element(response, node)
|
200
|
+
end
|
201
|
+
elsif root = REXML::XPath.first(xml, "//soap:Fault")
|
202
|
+
root.elements.to_a.each do |node|
|
203
|
+
response[node.name.underscore.to_sym] = node.text
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
response
|
208
|
+
end
|
209
|
+
|
210
|
+
def parse_element(response, node)
|
211
|
+
if node.has_elements?
|
212
|
+
node.elements.each{|e| parse_element(response, e) }
|
213
|
+
else
|
214
|
+
response[node.name.underscore.to_sym] = node.text.to_s.strip
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|