jelaniharris-activemerchant 1.24.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +893 -0
- data/CONTRIBUTORS +307 -0
- data/MIT-LICENSE +20 -0
- data/README.md +196 -0
- data/gem-public_cert.pem +20 -0
- data/lib/active_merchant.rb +63 -0
- data/lib/active_merchant/billing.rb +9 -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 +274 -0
- data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
- data/lib/active_merchant/billing/credit_card_methods.rb +143 -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.rb +18 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +694 -0
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +946 -0
- data/lib/active_merchant/billing/gateways/barclays_epdq.rb +308 -0
- data/lib/active_merchant/billing/gateways/beanstream.rb +167 -0
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +388 -0
- data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
- data/lib/active_merchant/billing/gateways/blue_pay.rb +492 -0
- data/lib/active_merchant/billing/gateways/bogus.rb +142 -0
- data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
- data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
- data/lib/active_merchant/billing/gateways/braintree_blue.rb +335 -0
- data/lib/active_merchant/billing/gateways/braintree_orange.rb +21 -0
- data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
- data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
- data/lib/active_merchant/billing/gateways/certo_direct.rb +279 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +430 -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 +137 -0
- data/lib/active_merchant/billing/gateways/epay.rb +276 -0
- data/lib/active_merchant/billing/gateways/eway.rb +277 -0
- data/lib/active_merchant/billing/gateways/eway_managed.rb +265 -0
- data/lib/active_merchant/billing/gateways/exact.rb +227 -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/itransact.rb +450 -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/litle.rb +275 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +157 -0
- data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
- data/lib/active_merchant/billing/gateways/migs.rb +259 -0
- data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -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 +250 -0
- data/lib/active_merchant/billing/gateways/moneris_us.rb +211 -0
- data/lib/active_merchant/billing/gateways/nab_transact.rb +255 -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 +422 -0
- data/lib/active_merchant/billing/gateways/optimal_payment.rb +277 -0
- data/lib/active_merchant/billing/gateways/orbital.rb +353 -0
- data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
- data/lib/active_merchant/billing/gateways/pay_junction.rb +397 -0
- data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
- data/lib/active_merchant/billing/gateways/paybox_direct.rb +199 -0
- data/lib/active_merchant/billing/gateways/payflow.rb +266 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +211 -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 +282 -0
- data/lib/active_merchant/billing/gateways/paypal.rb +106 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +640 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +245 -0
- data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
- data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +43 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +178 -0
- data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
- data/lib/active_merchant/billing/gateways/paystation.rb +201 -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 +297 -0
- data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
- data/lib/active_merchant/billing/gateways/quickpay.rb +298 -0
- data/lib/active_merchant/billing/gateways/realex.rb +313 -0
- data/lib/active_merchant/billing/gateways/sage.rb +146 -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_pay.rb +320 -0
- data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
- data/lib/active_merchant/billing/gateways/samurai.rb +121 -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 +281 -0
- data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
- data/lib/active_merchant/billing/gateways/skip_jack.rb +458 -0
- data/lib/active_merchant/billing/gateways/smart_ps.rb +271 -0
- data/lib/active_merchant/billing/gateways/stripe.rb +236 -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 +437 -0
- data/lib/active_merchant/billing/gateways/usa_epay.rb +23 -0
- data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1496 -0
- data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +202 -0
- data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
- data/lib/active_merchant/billing/gateways/viaklix.rb +194 -0
- data/lib/active_merchant/billing/gateways/vindicia.rb +359 -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/integrations.rb +17 -0
- data/lib/active_merchant/billing/integrations/action_view_helper.rb +72 -0
- data/lib/active_merchant/billing/integrations/authorize_net_sim.rb +38 -0
- data/lib/active_merchant/billing/integrations/authorize_net_sim/helper.rb +228 -0
- data/lib/active_merchant/billing/integrations/authorize_net_sim/notification.rb +340 -0
- data/lib/active_merchant/billing/integrations/bogus.rb +23 -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/chronopay.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/direc_pay.rb +41 -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/directebanking.rb +47 -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/dotpay.rb +22 -0
- data/lib/active_merchant/billing/integrations/dotpay/helper.rb +77 -0
- data/lib/active_merchant/billing/integrations/dotpay/notification.rb +86 -0
- data/lib/active_merchant/billing/integrations/dotpay/return.rb +11 -0
- data/lib/active_merchant/billing/integrations/dwolla.rb +30 -0
- data/lib/active_merchant/billing/integrations/dwolla/helper.rb +31 -0
- data/lib/active_merchant/billing/integrations/dwolla/notification.rb +55 -0
- data/lib/active_merchant/billing/integrations/dwolla/return.rb +38 -0
- data/lib/active_merchant/billing/integrations/e_payment_plans.rb +48 -0
- data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +34 -0
- data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +84 -0
- data/lib/active_merchant/billing/integrations/epay.rb +21 -0
- data/lib/active_merchant/billing/integrations/epay/helper.rb +55 -0
- data/lib/active_merchant/billing/integrations/epay/notification.rb +110 -0
- data/lib/active_merchant/billing/integrations/gestpay.rb +25 -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/helper.rb +113 -0
- data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -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/moneybookers.rb +26 -0
- data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
- data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
- data/lib/active_merchant/billing/integrations/nochex.rb +88 -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/notification.rb +62 -0
- data/lib/active_merchant/billing/integrations/payflow_link.rb +21 -0
- data/lib/active_merchant/billing/integrations/payflow_link/helper.rb +100 -0
- data/lib/active_merchant/billing/integrations/payflow_link/notification.rb +78 -0
- data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
- data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
- data/lib/active_merchant/billing/integrations/paypal/notification.rb +155 -0
- data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
- data/lib/active_merchant/billing/integrations/quickpay/helper.rb +71 -0
- data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
- data/lib/active_merchant/billing/integrations/return.rb +42 -0
- data/lib/active_merchant/billing/integrations/robokassa.rb +49 -0
- data/lib/active_merchant/billing/integrations/robokassa/common.rb +19 -0
- data/lib/active_merchant/billing/integrations/robokassa/helper.rb +50 -0
- data/lib/active_merchant/billing/integrations/robokassa/notification.rb +55 -0
- data/lib/active_merchant/billing/integrations/robokassa/return.rb +17 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -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 +129 -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/two_checkout.rb +44 -0
- data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +91 -0
- data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +139 -0
- data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
- data/lib/active_merchant/billing/integrations/valitor.rb +33 -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 +97 -0
- data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
- data/lib/active_merchant/billing/integrations/verkkomaksut.rb +20 -0
- data/lib/active_merchant/billing/integrations/verkkomaksut/helper.rb +87 -0
- data/lib/active_merchant/billing/integrations/verkkomaksut/notification.rb +59 -0
- data/lib/active_merchant/billing/integrations/world_pay.rb +27 -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/response.rb +32 -0
- data/lib/active_merchant/version.rb +3 -0
- data/lib/activemerchant.rb +1 -0
- data/lib/support/gateway_support.rb +58 -0
- data/lib/support/outbound_hosts.rb +25 -0
- metadata +447 -0
@@ -0,0 +1,258 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
# For more information on the Iridium Gateway please download the
|
4
|
+
# documentation from their Merchant Management System.
|
5
|
+
#
|
6
|
+
# The login and password are not the username and password you use to
|
7
|
+
# login to the Iridium Merchant Management System. Instead, you will
|
8
|
+
# use the API username and password you were issued separately.
|
9
|
+
class IridiumGateway < Gateway
|
10
|
+
|
11
|
+
# The countries the gateway supports merchants from as 2 digit ISO country codes
|
12
|
+
self.supported_countries = ['GB', 'ES']
|
13
|
+
self.default_currency = 'EUR'
|
14
|
+
self.money_format = :cents
|
15
|
+
|
16
|
+
# The card types supported by the payment gateway
|
17
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :discover]
|
18
|
+
|
19
|
+
# The homepage URL of the gateway
|
20
|
+
self.homepage_url = 'http://www.iridiumcorp.co.uk/'
|
21
|
+
|
22
|
+
# The name of the gateway
|
23
|
+
self.display_name = 'Iridium'
|
24
|
+
|
25
|
+
CURRENCY_CODES = {
|
26
|
+
"AUD" => '036',
|
27
|
+
"CAD" => '124',
|
28
|
+
"EUR" => '978',
|
29
|
+
"GBP" => '826',
|
30
|
+
"MXN" => '484',
|
31
|
+
"NZD" => '554',
|
32
|
+
"USD" => '840',
|
33
|
+
}
|
34
|
+
|
35
|
+
def initialize(options = {})
|
36
|
+
requires!(options, :login, :password)
|
37
|
+
@options = options
|
38
|
+
@test_url = 'https://gw1.iridiumcorp.net/'
|
39
|
+
@live_url = 'https://gw1.iridiumcorp.net/'
|
40
|
+
super
|
41
|
+
end
|
42
|
+
|
43
|
+
def authorize(money, creditcard, options = {})
|
44
|
+
commit(build_purchase_request('PREAUTH', money, creditcard, options), options)
|
45
|
+
end
|
46
|
+
|
47
|
+
def purchase(money, payment_source, options = {})
|
48
|
+
setup_address_hash(options)
|
49
|
+
|
50
|
+
if payment_source.respond_to?(:number)
|
51
|
+
commit(build_purchase_request('SALE', money, payment_source, options), options)
|
52
|
+
else
|
53
|
+
commit(build_reference_request('SALE', money, payment_source, options), options)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def capture(money, authorization, options = {})
|
58
|
+
commit(build_reference_request('COLLECTION', money, authorization, options), options)
|
59
|
+
end
|
60
|
+
|
61
|
+
def credit(money, authorization, options={})
|
62
|
+
deprecated CREDIT_DEPRECATION_MESSAGE
|
63
|
+
refund(money, authorization, options)
|
64
|
+
end
|
65
|
+
|
66
|
+
def refund(money, authorization, options={})
|
67
|
+
commit(build_reference_request('REFUND', money, authorization, options), options)
|
68
|
+
end
|
69
|
+
|
70
|
+
def void(authorization, options={})
|
71
|
+
commit(build_reference_request('VOID', nil, authorization, options), options)
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def build_purchase_request(type, money, creditcard, options)
|
77
|
+
options.merge!(:action => 'CardDetailsTransaction')
|
78
|
+
build_request(options) do |xml|
|
79
|
+
add_purchase_data(xml, type, money, options)
|
80
|
+
add_creditcard(xml, creditcard)
|
81
|
+
add_customerdetails(xml, creditcard, options[:billing_address], options)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def build_reference_request(type, money, authorization, options)
|
86
|
+
options.merge!(:action => 'CrossReferenceTransaction')
|
87
|
+
order_id, cross_reference, auth_id = authorization.split(";")
|
88
|
+
build_request(options) do |xml|
|
89
|
+
if money
|
90
|
+
details = {'CurrencyCode' => currency_code(options[:currency] || default_currency), 'Amount' => amount(money)}
|
91
|
+
else
|
92
|
+
details = {'CurrencyCode' => currency_code(default_currency), 'Amount' => '0'}
|
93
|
+
end
|
94
|
+
xml.tag! 'TransactionDetails', details do
|
95
|
+
xml.tag! 'MessageDetails', {'TransactionType' => type, 'CrossReference' => cross_reference}
|
96
|
+
xml.tag! 'OrderID', (options[:order_id] || order_id)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def build_request(options)
|
102
|
+
requires!(options, :action)
|
103
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
104
|
+
xml.instruct!(:xml, :version => '1.0', :encoding => 'utf-8')
|
105
|
+
xml.tag! 'soap:Envelope', { 'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/',
|
106
|
+
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
|
107
|
+
'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema'} do
|
108
|
+
xml.tag! 'soap:Body' do
|
109
|
+
xml.tag! options[:action], {'xmlns' => "https://www.thepaymentgateway.net/"} do
|
110
|
+
xml.tag! 'PaymentMessage' do
|
111
|
+
add_merchant_data(xml, options)
|
112
|
+
yield(xml)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
xml.target!
|
118
|
+
end
|
119
|
+
|
120
|
+
def setup_address_hash(options)
|
121
|
+
options[:billing_address] = options[:billing_address] || options[:address] || {}
|
122
|
+
options[:shipping_address] = options[:shipping_address] || {}
|
123
|
+
end
|
124
|
+
|
125
|
+
def add_purchase_data(xml, type, money, options)
|
126
|
+
requires!(options, :order_id)
|
127
|
+
xml.tag! 'TransactionDetails', {'Amount' => amount(money), 'CurrencyCode' => currency_code(options[:currency] || currency(money))} do
|
128
|
+
xml.tag! 'MessageDetails', {'TransactionType' => type}
|
129
|
+
xml.tag! 'OrderID', options[:order_id]
|
130
|
+
xml.tag! 'TransactionControl' do
|
131
|
+
xml.tag! 'ThreeDSecureOverridePolicy', 'FALSE'
|
132
|
+
xml.tag! 'EchoAVSCheckResult', 'TRUE'
|
133
|
+
xml.tag! 'EchoCV2CheckResult', 'TRUE'
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def add_customerdetails(xml, creditcard, address, options, shipTo = false)
|
139
|
+
xml.tag! 'CustomerDetails' do
|
140
|
+
if address
|
141
|
+
unless address[:country].blank?
|
142
|
+
country_code = Country.find(address[:country]).code(:numeric)
|
143
|
+
end
|
144
|
+
xml.tag! 'BillingAddress' do
|
145
|
+
xml.tag! 'Address1', address[:address1]
|
146
|
+
xml.tag! 'Address2', address[:address2]
|
147
|
+
xml.tag! 'City', address[:city]
|
148
|
+
xml.tag! 'State', address[:state]
|
149
|
+
xml.tag! 'PostCode', address[:zip]
|
150
|
+
xml.tag! 'CountryCode', country_code if country_code
|
151
|
+
end
|
152
|
+
xml.tag! 'PhoneNumber', address[:phone]
|
153
|
+
end
|
154
|
+
|
155
|
+
xml.tag! 'EmailAddress', options[:email]
|
156
|
+
xml.tag! 'CustomerIPAddress', options[:ip] || "127.0.0.1"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def add_creditcard(xml, creditcard)
|
161
|
+
xml.tag! 'CardDetails' do
|
162
|
+
xml.tag! 'CardName', creditcard.name
|
163
|
+
xml.tag! 'CV2', creditcard.verification_value if creditcard.verification_value
|
164
|
+
xml.tag! 'CardNumber', creditcard.number
|
165
|
+
xml.tag! 'ExpiryDate', { 'Month' => creditcard.month.to_s.rjust(2, "0"), 'Year' => creditcard.year.to_s[/\d\d$/] }
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def add_merchant_data(xml, options)
|
170
|
+
xml.tag! 'MerchantAuthentication', {"MerchantID" => @options[:login], "Password" => @options[:password]}
|
171
|
+
end
|
172
|
+
|
173
|
+
def commit(request, options)
|
174
|
+
requires!(options, :action)
|
175
|
+
response = parse(ssl_post(test? ? @test_url : @live_url, request,
|
176
|
+
{"SOAPAction" => "https://www.thepaymentgateway.net/#{options[:action]}",
|
177
|
+
"Content-Type" => "text/xml; charset=utf-8" }))
|
178
|
+
|
179
|
+
success = response[:transaction_result][:status_code] == "0"
|
180
|
+
message = response[:transaction_result][:message]
|
181
|
+
authorization = success ? [ options[:order_id], response[:transaction_output_data][:cross_reference], response[:transaction_output_data][:auth_code] ].compact.join(";") : nil
|
182
|
+
|
183
|
+
Response.new(success, message, response,
|
184
|
+
:test => test?,
|
185
|
+
:authorization => authorization)
|
186
|
+
end
|
187
|
+
|
188
|
+
def parse(xml)
|
189
|
+
reply = {}
|
190
|
+
xml = REXML::Document.new(xml)
|
191
|
+
if (root = REXML::XPath.first(xml, "//CardDetailsTransactionResponse")) or
|
192
|
+
(root = REXML::XPath.first(xml, "//CrossReferenceTransactionResponse"))
|
193
|
+
root.elements.to_a.each do |node|
|
194
|
+
case node.name
|
195
|
+
when 'Message'
|
196
|
+
reply[:message] = reply(node.text)
|
197
|
+
else
|
198
|
+
parse_element(reply, node)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
elsif root = REXML::XPath.first(xml, "//soap:Fault")
|
202
|
+
parse_element(reply, root)
|
203
|
+
reply[:message] = "#{reply[:faultcode]}: #{reply[:faultstring]}"
|
204
|
+
end
|
205
|
+
reply
|
206
|
+
end
|
207
|
+
|
208
|
+
def parse_element(reply, node)
|
209
|
+
case node.name
|
210
|
+
when "CrossReferenceTransactionResult"
|
211
|
+
reply[:transaction_result] = {}
|
212
|
+
node.attributes.each do |a,b|
|
213
|
+
reply[:transaction_result][a.underscore.to_sym] = b
|
214
|
+
end
|
215
|
+
node.elements.each{|e| parse_element(reply[:transaction_result], e) } if node.has_elements?
|
216
|
+
|
217
|
+
when "CardDetailsTransactionResult"
|
218
|
+
reply[:transaction_result] = {}
|
219
|
+
node.attributes.each do |a,b|
|
220
|
+
reply[:transaction_result][a.underscore.to_sym] = b
|
221
|
+
end
|
222
|
+
node.elements.each{|e| parse_element(reply[:transaction_result], e) } if node.has_elements?
|
223
|
+
|
224
|
+
when "TransactionOutputData"
|
225
|
+
reply[:transaction_output_data] = {}
|
226
|
+
node.attributes.each{|a,b| reply[:transaction_output_data][a.underscore.to_sym] = b }
|
227
|
+
node.elements.each{|e| parse_element(reply[:transaction_output_data], e) } if node.has_elements?
|
228
|
+
when "CustomVariables"
|
229
|
+
reply[:custom_variables] = {}
|
230
|
+
node.attributes.each{|a,b| reply[:custom_variables][a.underscore.to_sym] = b }
|
231
|
+
node.elements.each{|e| parse_element(reply[:custom_variables], e) } if node.has_elements?
|
232
|
+
when "GatewayEntryPoints"
|
233
|
+
reply[:gateway_entry_points] = {}
|
234
|
+
node.attributes.each{|a,b| reply[:gateway_entry_points][a.underscore.to_sym] = b }
|
235
|
+
node.elements.each{|e| parse_element(reply[:gateway_entry_points], e) } if node.has_elements?
|
236
|
+
else
|
237
|
+
k = node.name.underscore.to_sym
|
238
|
+
if node.has_elements?
|
239
|
+
reply[k] = {}
|
240
|
+
node.elements.each{|e| parse_element(reply[k], e) }
|
241
|
+
else
|
242
|
+
if node.has_attributes?
|
243
|
+
reply[k] = {}
|
244
|
+
node.attributes.each{|a,b| reply[k][a.underscore.to_sym] = b }
|
245
|
+
else
|
246
|
+
reply[k] = node.text
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
reply
|
251
|
+
end
|
252
|
+
|
253
|
+
def currency_code(currency)
|
254
|
+
CURRENCY_CODES[currency]
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
@@ -0,0 +1,450 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module ActiveMerchant #:nodoc:
|
4
|
+
module Billing #:nodoc:
|
5
|
+
# iTransact, Inc. is an authorized reseller of the PaymentClearing gateway. If your merchant service provider uses PaymentClearing.com to process payments, you can use this module.
|
6
|
+
#
|
7
|
+
#
|
8
|
+
# Please note, the username and API Access Key are not what you use to log into the Merchant Control Panel.
|
9
|
+
#
|
10
|
+
# ==== How to get your GatewayID and API Access Key
|
11
|
+
#
|
12
|
+
# 1. If you don't already have a Gateway Account, go to http://www.itransact.com/merchant/test.html to sign up.
|
13
|
+
# 2. Go to http://support.paymentclearing.com and login or register, if necessary.
|
14
|
+
# 3. Click on "Submit a Ticket."
|
15
|
+
# 4. Select "Merchant Support" as the department and click "Next"
|
16
|
+
# 5. Enter *both* your company name and GatewayID. Put "API Access Key" in the subject. In the body, you can request a username, but it may already be in use.
|
17
|
+
#
|
18
|
+
# ==== Initialization
|
19
|
+
#
|
20
|
+
# Once you have the username, API Access Key, and your GatewayId, you're ready
|
21
|
+
# to begin. You initialize the Gateway like so:
|
22
|
+
#
|
23
|
+
# gateway = ActiveMerchant::Billing::ItransactGateway.new(
|
24
|
+
# :login => "#{THE_USERNAME}",
|
25
|
+
# :password => "#{THE_API_ACCESS_KEY}",
|
26
|
+
# :gateway_id => "#{THE_GATEWAY_ID}"
|
27
|
+
# )
|
28
|
+
#
|
29
|
+
# ==== Important Notes
|
30
|
+
# 1. Recurring is not implemented
|
31
|
+
# 1. CreditTransactions are not implemented (these are credits not related to a previously run transaction).
|
32
|
+
# 1. TransactionStatus is not implemented
|
33
|
+
#
|
34
|
+
class ItransactGateway < Gateway
|
35
|
+
URL = 'https://secure.paymentclearing.com/cgi-bin/rc/xmltrans2.cgi'
|
36
|
+
|
37
|
+
# The countries the gateway supports merchants from as 2 digit ISO country codes
|
38
|
+
self.supported_countries = ['US']
|
39
|
+
|
40
|
+
# The card types supported by the payment gateway
|
41
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :discover]
|
42
|
+
|
43
|
+
# The homepage URL of the gateway
|
44
|
+
self.homepage_url = 'http://www.itransact.com/'
|
45
|
+
|
46
|
+
# The name of the gateway
|
47
|
+
self.display_name = 'iTransact'
|
48
|
+
|
49
|
+
#
|
50
|
+
# Creates a new instance of the iTransact Gateway.
|
51
|
+
#
|
52
|
+
# ==== Parameters
|
53
|
+
# * <tt>options</tt> - A Hash of options
|
54
|
+
#
|
55
|
+
# ==== Options Hash
|
56
|
+
# * <tt>:login</tt> - A String containing your PaymentClearing assigned API Access Username
|
57
|
+
# * <tt>:password</tt> - A String containing your PaymentClearing assigned API Access Key
|
58
|
+
# * <tt>:gateway_id</tt> - A String containing your PaymentClearing assigned GatewayID
|
59
|
+
# * <tt>:test_mode</tt> - <tt>true</tt> or <tt>false</tt>. Run *all* transactions with the 'TestMode' element set to 'TRUE'.
|
60
|
+
#
|
61
|
+
def initialize(options = {})
|
62
|
+
requires!(options, :login, :password, :gateway_id)
|
63
|
+
@options = options
|
64
|
+
super
|
65
|
+
end
|
66
|
+
|
67
|
+
# Performs an authorize transaction. In PaymentClearing's documentation
|
68
|
+
# this is known as a "PreAuth" transaction.
|
69
|
+
#
|
70
|
+
# ==== Parameters
|
71
|
+
# * <tt>money</tt> - The amount to be captured. Should be an Integer amount in cents.
|
72
|
+
# * <tt>creditcard</tt> - The CreditCard details for the transaction
|
73
|
+
# * <tt>options</tt> - A Hash of options
|
74
|
+
#
|
75
|
+
# ==== Options Hash
|
76
|
+
# The standard options apply here (:order_id, :ip, :customer, :invoice, :merchant, :description, :email, :currency, :address, :billing_address, :shipping_address), as well as:
|
77
|
+
# * <tt>:order_items</tt> - An Array of Hash objects with the keys <tt>:description</tt>, <tt>:cost</tt> (in cents!), and <tt>:quantity</tt>. If this is provided, <tt>:description</tt> and <tt>money</tt> will be ignored.
|
78
|
+
# * <tt>:vendor_data</tt> - An Array of Hash objects with the keys being the name of the VendorData element and value being the value.
|
79
|
+
# * <tt>:send_customer_email</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'SendCustomerEmail' element set to 'TRUE' or 'FALSE'.
|
80
|
+
# * <tt>:send_merchant_email</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'SendMerchantEmail' element set to 'TRUE' or 'FALSE'.
|
81
|
+
# * <tt>:email_text</tt> - An Array of (up to ten (10)) String objects to be included in emails
|
82
|
+
# * <tt>:test_mode</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'TestMode' element set to 'TRUE' or 'FALSE'.
|
83
|
+
#
|
84
|
+
# ==== Examples
|
85
|
+
# response = gateway.authorize(1000, creditcard,
|
86
|
+
# :order_id => '1212', :address => {...}, :email => 'test@test.com',
|
87
|
+
# :order_items => [
|
88
|
+
# {:description => 'Line Item 1', :cost => '8.98', :quantity => '6'},
|
89
|
+
# {:description => 'Line Item 2', :cost => '6.99', :quantity => '4'}
|
90
|
+
# ],
|
91
|
+
# :vendor_data => [{'repId' => '1234567'}, {'customerId' => '9886'}],
|
92
|
+
# :send_customer_email => true,
|
93
|
+
# :send_merchant_email => true,
|
94
|
+
# :email_text => ['line1', 'line2', 'line3'],
|
95
|
+
# :test_mode => true
|
96
|
+
# )
|
97
|
+
#
|
98
|
+
def authorize(money, payment_source, options = {})
|
99
|
+
payload = Nokogiri::XML::Builder.new do |xml|
|
100
|
+
xml.AuthTransaction {
|
101
|
+
xml.Preauth
|
102
|
+
add_customer_data(xml, payment_source, options)
|
103
|
+
add_invoice(xml, money, options)
|
104
|
+
add_payment_source(xml, payment_source)
|
105
|
+
add_transaction_control(xml, options)
|
106
|
+
add_vendor_data(xml, options)
|
107
|
+
}
|
108
|
+
end.doc
|
109
|
+
|
110
|
+
commit(payload)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Performs an authorize and capture in single transaction. In PaymentClearing's
|
114
|
+
# documentation this is known as an "Auth" or a "Sale" transaction
|
115
|
+
#
|
116
|
+
# ==== Parameters
|
117
|
+
# * <tt>money</tt> - The amount to be captured. Should be <tt>nil</tt> or an Integer amount in cents.
|
118
|
+
# * <tt>creditcard</tt> - The CreditCard details for the transaction
|
119
|
+
# * <tt>options</tt> - A Hash of options
|
120
|
+
#
|
121
|
+
# ==== Options Hash
|
122
|
+
# The standard options apply here (:order_id, :ip, :customer, :invoice, :merchant, :description, :email, :currency, :address, :billing_address, :shipping_address), as well as:
|
123
|
+
# * <tt>:order_items</tt> - An Array of Hash objects with the keys <tt>:description</tt>, <tt>:cost</tt> (in cents!), and <tt>:quantity</tt>. If this is provided, <tt>:description</tt> and <tt>money</tt> will be ignored.
|
124
|
+
# * <tt>:vendor_data</tt> - An Array of Hash objects with the keys being the name of the VendorData element and value being the value.
|
125
|
+
# * <tt>:send_customer_email</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'SendCustomerEmail' element set to 'TRUE' or 'FALSE'.
|
126
|
+
# * <tt>:send_merchant_email</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'SendMerchantEmail' element set to 'TRUE' or 'FALSE'.
|
127
|
+
# * <tt>:email_text</tt> - An Array of (up to ten (10)) String objects to be included in emails
|
128
|
+
# * <tt>:test_mode</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'TestMode' element set to 'TRUE' or 'FALSE'.
|
129
|
+
#
|
130
|
+
# ==== Examples
|
131
|
+
# response = gateway.purchase(1000, creditcard,
|
132
|
+
# :order_id => '1212', :address => {...}, :email => 'test@test.com',
|
133
|
+
# :order_items => [
|
134
|
+
# {:description => 'Line Item 1', :cost => '8.98', :quantity => '6'},
|
135
|
+
# {:description => 'Line Item 2', :cost => '6.99', :quantity => '4'}
|
136
|
+
# ],
|
137
|
+
# :vendor_data => [{'repId' => '1234567'}, {'customerId' => '9886'}],
|
138
|
+
# :send_customer_email => true,
|
139
|
+
# :send_merchant_email => true,
|
140
|
+
# :email_text => ['line1', 'line2', 'line3'],
|
141
|
+
# :test_mode => true
|
142
|
+
# )
|
143
|
+
#
|
144
|
+
def purchase(money, payment_source, options = {})
|
145
|
+
payload = Nokogiri::XML::Builder.new do |xml|
|
146
|
+
xml.AuthTransaction {
|
147
|
+
add_customer_data(xml, payment_source, options)
|
148
|
+
add_invoice(xml, money, options)
|
149
|
+
add_payment_source(xml, payment_source)
|
150
|
+
add_transaction_control(xml, options)
|
151
|
+
add_vendor_data(xml, options)
|
152
|
+
}
|
153
|
+
end.doc
|
154
|
+
|
155
|
+
commit(payload)
|
156
|
+
end
|
157
|
+
|
158
|
+
# Captures the funds from an authorize transaction. In PaymentClearing's
|
159
|
+
# documentation this is known as a "PostAuth" transaction.
|
160
|
+
#
|
161
|
+
# ==== Parameters
|
162
|
+
# * <tt>money</tt> - The amount to be captured. Should be an Integer amount in cents
|
163
|
+
# * <tt>authorization</tt> - The authorization returned from the previous capture or purchase request
|
164
|
+
# * <tt>options</tt> - A Hash of options, all are optional.
|
165
|
+
#
|
166
|
+
# ==== Options Hash
|
167
|
+
# The standard options apply here (:order_id, :ip, :customer, :invoice, :merchant, :description, :email, :currency, :address, :billing_address, :shipping_address), as well as:
|
168
|
+
# * <tt>:vendor_data</tt> - An Array of Hash objects with the keys being the name of the VendorData element and value being the value.
|
169
|
+
# * <tt>:send_customer_email</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'SendCustomerEmail' element set to 'TRUE' or 'FALSE'.
|
170
|
+
# * <tt>:send_merchant_email</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'SendMerchantEmail' element set to 'TRUE' or 'FALSE'.
|
171
|
+
# * <tt>:email_text</tt> - An Array of (up to ten (10)) String objects to be included in emails
|
172
|
+
# * <tt>:test_mode</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'TestMode' element set to 'TRUE' or 'FALSE'.
|
173
|
+
#
|
174
|
+
# ==== Examples
|
175
|
+
# response = gateway.capture(1000, creditcard,
|
176
|
+
# :vendor_data => [{'repId' => '1234567'}, {'customerId' => '9886'}],
|
177
|
+
# :send_customer_email => true,
|
178
|
+
# :send_merchant_email => true,
|
179
|
+
# :email_text => ['line1', 'line2', 'line3'],
|
180
|
+
# :test_mode => true
|
181
|
+
# )
|
182
|
+
#
|
183
|
+
def capture(money, authorization, options = {})
|
184
|
+
payload = Nokogiri::XML::Builder.new do |xml|
|
185
|
+
xml.PostAuthTransaction {
|
186
|
+
xml.OperationXID(authorization)
|
187
|
+
add_invoice(xml, money, options)
|
188
|
+
add_transaction_control(xml, options)
|
189
|
+
add_vendor_data(xml, options)
|
190
|
+
}
|
191
|
+
end.doc
|
192
|
+
|
193
|
+
commit(payload)
|
194
|
+
end
|
195
|
+
|
196
|
+
# This will reverse a previously run transaction which *has* *not* settled.
|
197
|
+
#
|
198
|
+
# ==== Parameters
|
199
|
+
# * <tt>money</tt> - This parameter is ignored -- the PaymentClearing gateway does not allow partial voids.
|
200
|
+
# * <tt>authorization</tt> - The authorization returned from the previous capture or purchase request
|
201
|
+
# * <tt>options</tt> - A Hash of options, all are optional
|
202
|
+
#
|
203
|
+
# ==== Options Hash
|
204
|
+
# The standard options (:order_id, :ip, :customer, :invoice, :merchant, :description, :email, :currency, :address, :billing_address, :shipping_address) are ignored.
|
205
|
+
# * <tt>:vendor_data</tt> - An Array of Hash objects with the keys being the name of the VendorData element and value being the value.
|
206
|
+
# * <tt>:send_customer_email</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'SendCustomerEmail' element set to 'TRUE' or 'FALSE'.
|
207
|
+
# * <tt>:send_merchant_email</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'SendMerchantEmail' element set to 'TRUE' or 'FALSE'.
|
208
|
+
# * <tt>:email_text</tt> - An Array of (up to ten (10)) String objects to be included in emails
|
209
|
+
# * <tt>:test_mode</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'TestMode' element set to 'TRUE' or 'FALSE'.
|
210
|
+
#
|
211
|
+
# ==== Examples
|
212
|
+
# response = gateway.void(nil, '9999999999',
|
213
|
+
# :vendor_data => [{'repId' => '1234567'}, {'customerId' => '9886'}],
|
214
|
+
# :send_customer_email => true,
|
215
|
+
# :send_merchant_email => true,
|
216
|
+
# :email_text => ['line1', 'line2', 'line3'],
|
217
|
+
# :test_mode => true
|
218
|
+
# )
|
219
|
+
#
|
220
|
+
def void(money, authorization, options = {})
|
221
|
+
payload = Nokogiri::XML::Builder.new do |xml|
|
222
|
+
xml.VoidTransaction {
|
223
|
+
xml.OperationXID(authorization)
|
224
|
+
add_transaction_control(xml, options)
|
225
|
+
add_vendor_data(xml, options)
|
226
|
+
}
|
227
|
+
end.doc
|
228
|
+
|
229
|
+
commit(payload)
|
230
|
+
end
|
231
|
+
|
232
|
+
# This will reverse a previously run transaction which *has* settled.
|
233
|
+
#
|
234
|
+
# ==== Parameters
|
235
|
+
# * <tt>money</tt> - The amount to be credited. Should be <tt>nil</tt> or an Integer amount in cents
|
236
|
+
# * <tt>authorization</tt> - The authorization returned from the previous capture or purchase request
|
237
|
+
# * <tt>options</tt> - A Hash of options, all are optional
|
238
|
+
#
|
239
|
+
# ==== Options Hash
|
240
|
+
# The standard options (:order_id, :ip, :customer, :invoice, :merchant, :description, :email, :currency, :address, :billing_address, :shipping_address) are ignored.
|
241
|
+
# * <tt>:vendor_data</tt> - An Array of Hash objects with the keys being the name of the VendorData element and value being the value.
|
242
|
+
# * <tt>:send_customer_email</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'SendCustomerEmail' element set to 'TRUE' or 'FALSE'.
|
243
|
+
# * <tt>:send_merchant_email</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'SendMerchantEmail' element set to 'TRUE' or 'FALSE'.
|
244
|
+
# * <tt>:email_text</tt> - An Array of (up to ten (10)) String objects to be included in emails
|
245
|
+
# * <tt>:test_mode</tt> - <tt>true</tt> or <tt>false</tt>. Runs the transaction with the 'TestMode' element set to 'TRUE' or 'FALSE'.
|
246
|
+
#
|
247
|
+
# ==== Examples
|
248
|
+
# response = gateway.credit(nil, '9999999999',
|
249
|
+
# :vendor_data => [{'repId' => '1234567'}, {'customerId' => '9886'}],
|
250
|
+
# :send_customer_email => true,
|
251
|
+
# :send_merchant_email => true,
|
252
|
+
# :email_text => ['line1', 'line2', 'line3'],
|
253
|
+
# :test_mode => true
|
254
|
+
# )
|
255
|
+
#
|
256
|
+
def credit(money, authorization, options = {})
|
257
|
+
payload = Nokogiri::XML::Builder.new do |xml|
|
258
|
+
xml.TranCreditTransaction {
|
259
|
+
xml.OperationXID(authorization)
|
260
|
+
add_invoice(xml, money, options)
|
261
|
+
add_transaction_control(xml, options)
|
262
|
+
add_vendor_data(xml, options)
|
263
|
+
}
|
264
|
+
end.doc
|
265
|
+
|
266
|
+
commit(payload)
|
267
|
+
end
|
268
|
+
|
269
|
+
private
|
270
|
+
|
271
|
+
def add_customer_data(xml, payment_source, options)
|
272
|
+
billing_address = options[:billing_address] || options[:address]
|
273
|
+
shipping_address = options[:shipping_address] || options[:address]
|
274
|
+
|
275
|
+
xml.CustomerData {
|
276
|
+
xml.Email(options[:email]) unless options[:email].blank?
|
277
|
+
xml.CustId(options[:order_id]) unless options[:order_id].blank?
|
278
|
+
xml.BillingAddress {
|
279
|
+
xml.FirstName(payment_source.first_name || parse_first_name(billing_address[:name]))
|
280
|
+
xml.LastName(payment_source.last_name || parse_last_name(billing_address[:name]))
|
281
|
+
xml.Address1(billing_address[:address1])
|
282
|
+
xml.Address2(billing_address[:address2]) unless billing_address[:address2].blank?
|
283
|
+
xml.City(billing_address[:city])
|
284
|
+
xml.State(billing_address[:state])
|
285
|
+
xml.Zip(billing_address[:zip])
|
286
|
+
xml.Country(billing_address[:country])
|
287
|
+
xml.Phone(billing_address[:phone])
|
288
|
+
}
|
289
|
+
xml.ShippingAddress {
|
290
|
+
xml.FirstName(payment_source.first_name || parse_first_name(shipping_address[:name]))
|
291
|
+
xml.LastName(payment_source.last_name || parse_last_name(shipping_address[:name]))
|
292
|
+
xml.Address1(shipping_address[:address1])
|
293
|
+
xml.Address2(shipping_address[:address2]) unless shipping_address[:address2].blank?
|
294
|
+
xml.City(shipping_address[:city])
|
295
|
+
xml.State(shipping_address[:state])
|
296
|
+
xml.Zip(shipping_address[:zip])
|
297
|
+
xml.Country(shipping_address[:country])
|
298
|
+
xml.Phone(shipping_address[:phone])
|
299
|
+
} unless shipping_address.blank?
|
300
|
+
}
|
301
|
+
end
|
302
|
+
|
303
|
+
def add_invoice(xml, money, options)
|
304
|
+
xml.AuthCode options[:force] if options[:force]
|
305
|
+
if options[:order_items].blank?
|
306
|
+
xml.Total(amount(money)) unless(money.nil? || money < 0.01)
|
307
|
+
xml.Description(options[:description]) unless( options[:description].blank?)
|
308
|
+
else
|
309
|
+
xml.OrderItems {
|
310
|
+
options[:order_items].each do |item|
|
311
|
+
xml.Item {
|
312
|
+
xml.Description(item[:description])
|
313
|
+
xml.Cost(amount(item[:cost]))
|
314
|
+
xml.Qty(item[:quantity].to_s)
|
315
|
+
}
|
316
|
+
end
|
317
|
+
}
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
def add_payment_source(xml, source)
|
322
|
+
case determine_funding_source(source)
|
323
|
+
when :credit_card then add_creditcard(xml, source)
|
324
|
+
when :check then add_check(xml, source)
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
def determine_funding_source(payment_source)
|
329
|
+
case payment_source
|
330
|
+
when ActiveMerchant::Billing::CreditCard
|
331
|
+
:credit_card
|
332
|
+
when ActiveMerchant::Billing::Check
|
333
|
+
:check
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
def add_creditcard(xml, creditcard)
|
338
|
+
xml.AccountInfo {
|
339
|
+
xml.CardAccount {
|
340
|
+
xml.AccountNumber(creditcard.number.to_s)
|
341
|
+
xml.ExpirationMonth(creditcard.month.to_s.rjust(2,'0'))
|
342
|
+
xml.ExpirationYear(creditcard.year.to_s)
|
343
|
+
xml.CVVNumber(creditcard.verification_value.to_s) unless creditcard.verification_value.blank?
|
344
|
+
}
|
345
|
+
}
|
346
|
+
end
|
347
|
+
|
348
|
+
def add_check(xml, check)
|
349
|
+
xml.AccountInfo {
|
350
|
+
xml.ABA(check.routing_number.to_s)
|
351
|
+
xml.AccountNumber(check.account_number.to_s)
|
352
|
+
xml.AccountSource(check.account_type.to_s)
|
353
|
+
xml.AccountType(check.account_holder_type.to_s)
|
354
|
+
xml.CheckNumber(check.number.to_s)
|
355
|
+
}
|
356
|
+
end
|
357
|
+
|
358
|
+
def add_transaction_control(xml, options)
|
359
|
+
xml.TransactionControl {
|
360
|
+
# if there was a 'global' option set...
|
361
|
+
xml.TestMode(@options[:test_mode].upcase) if !@options[:test_mode].blank?
|
362
|
+
# allow the global option to be overridden...
|
363
|
+
xml.TestMode(options[:test_mode].upcase) if !options[:test_mode].blank?
|
364
|
+
xml.SendCustomerEmail(options[:send_customer_email].upcase) unless options[:send_customer_email].blank?
|
365
|
+
xml.SendMerchantEmail(options[:send_merchant_email].upcase) unless options[:send_merchant_email].blank?
|
366
|
+
xml.EmailText {
|
367
|
+
options[:email_text].each do |item|
|
368
|
+
xml.EmailTextItem(item)
|
369
|
+
end
|
370
|
+
} if options[:email_text]
|
371
|
+
}
|
372
|
+
end
|
373
|
+
|
374
|
+
def add_vendor_data(xml, options)
|
375
|
+
return if options[:vendor_data].blank?
|
376
|
+
xml.VendorData {
|
377
|
+
options[:vendor_data].each do |k,v|
|
378
|
+
xml.Element {
|
379
|
+
xml.Name(k)
|
380
|
+
xml.Key(v)
|
381
|
+
}
|
382
|
+
end
|
383
|
+
}
|
384
|
+
end
|
385
|
+
|
386
|
+
def commit(payload)
|
387
|
+
# Set the Content-Type header -- otherwise the URL decoding messes up
|
388
|
+
# the Base64 encoded payload signature!
|
389
|
+
response = parse(ssl_post(URL, post_data(payload), 'Content-Type' => 'text/xml'))
|
390
|
+
|
391
|
+
Response.new(successful?(response), response[:error_message], response,
|
392
|
+
:test => test?,
|
393
|
+
:authorization => response[:xid],
|
394
|
+
:avs_result => { :code => response[:avs_response] },
|
395
|
+
:cvv_result => response[:cvv_response])
|
396
|
+
end
|
397
|
+
|
398
|
+
def post_data(payload)
|
399
|
+
payload_xml = payload.root.to_xml(:indent => 0)
|
400
|
+
|
401
|
+
payload_signature = sign_payload(payload_xml)
|
402
|
+
|
403
|
+
request = Nokogiri::XML::Builder.new do |xml|
|
404
|
+
xml.GatewayInterface {
|
405
|
+
xml.APICredentials {
|
406
|
+
xml.Username(@options[:login])
|
407
|
+
xml.PayloadSignature(payload_signature)
|
408
|
+
xml.TargetGateway(@options[:gateway_id])
|
409
|
+
}
|
410
|
+
}
|
411
|
+
end.doc
|
412
|
+
|
413
|
+
request.root.children.first.after payload.root
|
414
|
+
request.to_xml(:indent => 0)
|
415
|
+
end
|
416
|
+
|
417
|
+
def parse(raw_xml)
|
418
|
+
doc = REXML::Document.new(raw_xml)
|
419
|
+
response = Hash.new
|
420
|
+
transaction_result = doc.root.get_elements('TransactionResponse/TransactionResult/*')
|
421
|
+
transaction_result.each do |e|
|
422
|
+
response[e.name.to_s.underscore.to_sym] = e.text unless e.text.blank?
|
423
|
+
end
|
424
|
+
response
|
425
|
+
end
|
426
|
+
|
427
|
+
def successful?(response)
|
428
|
+
# Turns out the PaymentClearing gateway is not consistent...
|
429
|
+
response[:status].downcase =='ok'
|
430
|
+
end
|
431
|
+
|
432
|
+
def test_mode?(response)
|
433
|
+
# The '1' is a legacy thing; most of the time it should be 'TRUE'...
|
434
|
+
response[:test_mode] == 'TRUE' || response[:test_mode] == '1'
|
435
|
+
end
|
436
|
+
|
437
|
+
def message_from(response)
|
438
|
+
response[:error_message]
|
439
|
+
end
|
440
|
+
|
441
|
+
def sign_payload(payload)
|
442
|
+
key = @options[:password].to_s
|
443
|
+
digest=OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new(key), key, payload)
|
444
|
+
signature = Base64.encode64(digest)
|
445
|
+
signature.chomp!
|
446
|
+
end
|
447
|
+
end
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|