vibedeck-activemerchant 1.18.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +742 -0
- data/CONTRIBUTORS +257 -0
- data/MIT-LICENSE +20 -0
- data/gem-public_cert.pem +20 -0
- data/lib/active_merchant.rb +47 -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 +260 -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.rb +18 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +693 -0
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +857 -0
- data/lib/active_merchant/billing/gateways/barclays_epdq.rb +308 -0
- data/lib/active_merchant/billing/gateways/beanstream.rb +139 -0
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +282 -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 +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 +304 -0
- data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -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/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 +134 -0
- data/lib/active_merchant/billing/gateways/epay.rb +274 -0
- data/lib/active_merchant/billing/gateways/eway.rb +277 -0
- data/lib/active_merchant/billing/gateways/eway_managed.rb +264 -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/optimal_payment.rb +274 -0
- data/lib/active_merchant/billing/gateways/orbital.rb +321 -0
- data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -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.rb +253 -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_express.rb +223 -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.rb +121 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +354 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -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 +221 -0
- data/lib/active_merchant/billing/gateways/paypal_express_common.rb +25 -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 +297 -0
- data/lib/active_merchant/billing/gateways/realex.rb +315 -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/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/stripe.rb +212 -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/integrations.rb +17 -0
- data/lib/active_merchant/billing/integrations/action_view_helper.rb +68 -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/dwolla.rb +30 -0
- data/lib/active_merchant/billing/integrations/dwolla/helper.rb +28 -0
- data/lib/active_merchant/billing/integrations/dwolla/notification.rb +50 -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/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 +96 -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 +58 -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 +154 -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 +72 -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/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 +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/two_checkout.rb +23 -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/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/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 +340 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/smart_ps.rb'
|
2
|
+
require File.dirname(__FILE__) + '/braintree/braintree_common'
|
3
|
+
|
4
|
+
module ActiveMerchant #:nodoc:
|
5
|
+
module Billing #:nodoc:
|
6
|
+
class BraintreeOrangeGateway < SmartPs
|
7
|
+
include BraintreeCommon
|
8
|
+
|
9
|
+
self.display_name = 'Braintree (Orange Platform)'
|
10
|
+
|
11
|
+
def api_url
|
12
|
+
'https://secure.braintreepaymentgateway.com/api/transact.php'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class CardSaveGateway < IridiumGateway
|
4
|
+
#CardSave lets you handle failovers on payments by providing 3 gateways in case one happens to be down
|
5
|
+
#URLS = ['https://gw1.cardsaveonlinepayments.com:4430/','https://gw2.cardsaveonlinepayments.com:4430/','https://gw3.cardsaveonlinepayments.com:4430/']
|
6
|
+
|
7
|
+
self.money_format = :cents
|
8
|
+
self.default_currency = 'GBP'
|
9
|
+
self.supported_cardtypes = [ :visa, :switch, :maestro, :master, :solo, :american_express, :jcb ]
|
10
|
+
self.supported_countries = [ 'GB' ]
|
11
|
+
self.homepage_url = 'http://www.cardsave.net/'
|
12
|
+
self.display_name = 'CardSave'
|
13
|
+
|
14
|
+
def initialize(options={})
|
15
|
+
super
|
16
|
+
@test_url = 'https://gw1.cardsaveonlinepayments.com:4430/'
|
17
|
+
@live_url = 'https://gw1.cardsaveonlinepayments.com:4430/'
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,230 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
#
|
4
|
+
# CardStream supports the following credit cards, which are auto-detected by
|
5
|
+
# the gateway based on the card number used:
|
6
|
+
# * AM American Express
|
7
|
+
# * Diners Club
|
8
|
+
# * Electron
|
9
|
+
# * JCB
|
10
|
+
# * UK Maestro
|
11
|
+
# * Maestro International
|
12
|
+
# * Mastercard
|
13
|
+
# * Solo
|
14
|
+
# * Style
|
15
|
+
# * Switch
|
16
|
+
# * Visa Credit
|
17
|
+
# * Visa Debit
|
18
|
+
# * Visa Purchasing
|
19
|
+
#
|
20
|
+
class CardStreamGateway < Gateway
|
21
|
+
URL = 'https://gateway.cardstream.com/process.ashx'
|
22
|
+
|
23
|
+
self.money_format = :cents
|
24
|
+
self.default_currency = 'GBP'
|
25
|
+
self.supported_countries = ['GB']
|
26
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :discover, :jcb, :maestro, :solo, :switch]
|
27
|
+
self.homepage_url = 'http://www.cardstream.com/'
|
28
|
+
self.display_name = 'CardStream'
|
29
|
+
|
30
|
+
APPROVED = '00'
|
31
|
+
|
32
|
+
CURRENCY_CODES = {
|
33
|
+
"AUD"=> '036',
|
34
|
+
"CAD"=> '124',
|
35
|
+
"CZK"=> '203',
|
36
|
+
"DKK"=> '208',
|
37
|
+
"HKD"=> '344',
|
38
|
+
"ICK"=> '352',
|
39
|
+
"JPY"=> '392',
|
40
|
+
"NOK"=> '578',
|
41
|
+
"SGD"=> '702',
|
42
|
+
"SEK"=> '752',
|
43
|
+
"CHF"=> '756',
|
44
|
+
"GBP"=> '826',
|
45
|
+
"USD"=> '840',
|
46
|
+
"EUR"=> '978'
|
47
|
+
}
|
48
|
+
|
49
|
+
TRANSACTIONS = {
|
50
|
+
:purchase => 'ESALE_KEYED',
|
51
|
+
:refund => 'EREFUND_KEYED',
|
52
|
+
:authorization => 'ESALE_KEYED'
|
53
|
+
}
|
54
|
+
|
55
|
+
CVV_CODE = {
|
56
|
+
'0' => 'U',
|
57
|
+
'1' => 'P',
|
58
|
+
'2' => 'M',
|
59
|
+
'4' => 'N'
|
60
|
+
}
|
61
|
+
|
62
|
+
# 0 - No additional information available.
|
63
|
+
# 1 - Postcode not checked.
|
64
|
+
# 2 - Postcode matched.
|
65
|
+
# 4 - Postcode not matched.
|
66
|
+
# 8 - Postcode partially matched.
|
67
|
+
AVS_POSTAL_MATCH = {
|
68
|
+
"0" => nil,
|
69
|
+
"1" => nil,
|
70
|
+
"2" => "Y",
|
71
|
+
"4" => "N",
|
72
|
+
"8" => "N"
|
73
|
+
}
|
74
|
+
|
75
|
+
# 0 - No additional information available.
|
76
|
+
# 1 - Address numeric not checked.
|
77
|
+
# 2 - Address numeric matched.
|
78
|
+
# 4 - Address numeric not matched.
|
79
|
+
# 8 - Address numeric partially matched.
|
80
|
+
AVS_STREET_MATCH = {
|
81
|
+
"0" => nil,
|
82
|
+
"1" => nil,
|
83
|
+
"2" => "Y",
|
84
|
+
"4" => "N",
|
85
|
+
"8" => "N"
|
86
|
+
}
|
87
|
+
|
88
|
+
def initialize(options = {})
|
89
|
+
requires!(options, :login, :password)
|
90
|
+
@options = options
|
91
|
+
super
|
92
|
+
end
|
93
|
+
|
94
|
+
def purchase(money, credit_card, options = {})
|
95
|
+
requires!(options, :order_id)
|
96
|
+
|
97
|
+
post = {}
|
98
|
+
|
99
|
+
add_amount(post, money, options)
|
100
|
+
add_invoice(post, money, credit_card, options)
|
101
|
+
add_credit_card(post, credit_card)
|
102
|
+
add_address(post, options)
|
103
|
+
add_customer_data(post, options)
|
104
|
+
|
105
|
+
commit(:purchase, post)
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def add_amount(post, money, options)
|
111
|
+
add_pair(post, :Amount, amount(money), :required => true)
|
112
|
+
add_pair(post, :CurrencyCode, currency_code(options[:currency] || currency(money)), :required => true)
|
113
|
+
end
|
114
|
+
|
115
|
+
def add_customer_data(post, options)
|
116
|
+
add_pair(post, :BillingEmail, options[:email])
|
117
|
+
add_pair(post, :BillingPhoneNumber, options[:phone])
|
118
|
+
end
|
119
|
+
|
120
|
+
def add_address(post, options)
|
121
|
+
address = options[:billing_address] || options[:address]
|
122
|
+
|
123
|
+
return if address.nil?
|
124
|
+
|
125
|
+
add_pair(post, :BillingStreet, address[:address1])
|
126
|
+
add_pair(post, :BillingHouseNumber, address[:address2])
|
127
|
+
add_pair(post, :BillingCity, address[:city])
|
128
|
+
add_pair(post, :BillingState, address[:state])
|
129
|
+
add_pair(post, :BillingPostCode, address[:zip])
|
130
|
+
end
|
131
|
+
|
132
|
+
def add_invoice(post, money, credit_card, options)
|
133
|
+
add_pair(post, :TransactionUnique, options[:order_id], :required => true)
|
134
|
+
add_pair(post, :OrderDesc, options[:description] || options[:order_id], :required => true)
|
135
|
+
|
136
|
+
if [ 'american_express', 'diners_club' ].include?(card_brand(credit_card).to_s)
|
137
|
+
add_pair(post, :AEIT1Quantity, 1)
|
138
|
+
add_pair(post, :AEIT1Description, (options[:description] || options[:order_id]).slice(0, 15))
|
139
|
+
add_pair(post, :AEIT1GrossValue, amount(money))
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def add_credit_card(post, credit_card)
|
144
|
+
add_pair(post, :CardName, credit_card.name, :required => true)
|
145
|
+
add_pair(post, :CardNumber, credit_card.number, :required => true)
|
146
|
+
|
147
|
+
add_pair(post, :ExpiryDateMM, format(credit_card.month, :two_digits), :required => true)
|
148
|
+
add_pair(post, :ExpiryDateYY, format(credit_card.year, :two_digits), :required => true)
|
149
|
+
|
150
|
+
if requires_start_date_or_issue_number?(credit_card)
|
151
|
+
add_pair(post, :StartDateMM, format(credit_card.start_month, :two_digits))
|
152
|
+
add_pair(post, :StartDateYY, format(credit_card.start_year, :two_digits))
|
153
|
+
|
154
|
+
add_pair(post, :IssueNumber, credit_card.issue_number)
|
155
|
+
end
|
156
|
+
|
157
|
+
add_pair(post, :CV2, credit_card.verification_value)
|
158
|
+
end
|
159
|
+
|
160
|
+
def commit(action, parameters)
|
161
|
+
response = parse( ssl_post(URL, post_data(action, parameters)) )
|
162
|
+
|
163
|
+
Response.new(response[:response_code] == APPROVED, message_from(response), response,
|
164
|
+
:test => test?,
|
165
|
+
:authorization => response[:cross_reference],
|
166
|
+
:cvv_result => CVV_CODE[ response[:avscv2_response_code].to_s[0, 1] ],
|
167
|
+
:avs_result => {
|
168
|
+
:street_match => AVS_STREET_MATCH[ response[:avscv2_response_code].to_s[2, 1] ],
|
169
|
+
:postal_match => AVS_POSTAL_MATCH[ response[:avscv2_response_code].to_s[1, 1] ]
|
170
|
+
}
|
171
|
+
)
|
172
|
+
end
|
173
|
+
|
174
|
+
def message_from(results)
|
175
|
+
results[:response_code] == APPROVED ? "APPROVED" : results[:message]
|
176
|
+
end
|
177
|
+
|
178
|
+
def post_data(action, parameters = {})
|
179
|
+
parameters.update(
|
180
|
+
:MerchantPassword => @options[:password],
|
181
|
+
:MerchantID => @options[:login],
|
182
|
+
:MessageType => TRANSACTIONS[action],
|
183
|
+
:CallBack => "disable",
|
184
|
+
:DuplicateDelay => "0",
|
185
|
+
:EchoCardType => "YES",
|
186
|
+
:EchoAmount => "YES",
|
187
|
+
:EchoAVSCV2ResponseCode => "YES",
|
188
|
+
:ReturnAVSCV2Message => "YES",
|
189
|
+
:CountryCode => '826' # 826 for UK based merchant
|
190
|
+
)
|
191
|
+
|
192
|
+
add_pair(parameters, :Dispatch, action == :authorization ? "LATER" : "NOW")
|
193
|
+
|
194
|
+
parameters.collect { |key, value| "VP#{key}=#{CGI.escape(value.to_s)}" }.join("&")
|
195
|
+
end
|
196
|
+
|
197
|
+
# VPCrossReference
|
198
|
+
# The value in VPCrossReference on a success transaction will contain
|
199
|
+
# a unique reference that you may use to run future transactions.
|
200
|
+
# Please note that cross reference transactions must come a static IP
|
201
|
+
# addressed that has been pre-registered with Cardstream. To
|
202
|
+
# register an IP address please send it to support@cardstream.com
|
203
|
+
# with your Cardstream issued merchant ID and it will be added to
|
204
|
+
# your account.
|
205
|
+
def parse(body)
|
206
|
+
result = {}
|
207
|
+
pairs = body.split("&")
|
208
|
+
pairs.each do |pair|
|
209
|
+
a = pair.split("=")
|
210
|
+
result[a[0].gsub(/^VP/,'').underscore.to_sym] = a[1]
|
211
|
+
end
|
212
|
+
|
213
|
+
result
|
214
|
+
end
|
215
|
+
|
216
|
+
def test?
|
217
|
+
@options[:test] || Base.gateway_mode == :test
|
218
|
+
end
|
219
|
+
|
220
|
+
def currency_code(currency)
|
221
|
+
CURRENCY_CODES[currency]
|
222
|
+
end
|
223
|
+
|
224
|
+
def add_pair(post, key, value, options = {})
|
225
|
+
post[key] = value if !value.blank? || options[:required]
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
@@ -0,0 +1,430 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
# See the remote and mocked unit test files for example usage. Pay special attention to the contents of the options hash.
|
4
|
+
#
|
5
|
+
# Initial setup instructions can be found in http://cybersource.com/support_center/implementation/downloads/soap_api/SOAP_toolkits.pdf
|
6
|
+
#
|
7
|
+
# Debugging
|
8
|
+
# If you experience an issue with this gateway be sure to examine the transaction information from a general transaction search inside the CyberSource Business
|
9
|
+
# Center for the full error messages including field names.
|
10
|
+
#
|
11
|
+
# Important Notes
|
12
|
+
# * AVS and CVV only work against the production server. You will always get back X for AVS and no response for CVV against the test server.
|
13
|
+
# * Nexus is the list of states or provinces where you have a physical presence. Nexus is used to calculate tax. Leave blank to tax everyone.
|
14
|
+
# * If you want to calculate VAT for overseas customers you must supply a registration number in the options hash as vat_reg_number.
|
15
|
+
# * productCode is a value in the line_items hash that is used to tell CyberSource what kind of item you are selling. It is used when calculating tax/VAT.
|
16
|
+
# * All transactions use dollar values.
|
17
|
+
class CyberSourceGateway < Gateway
|
18
|
+
TEST_URL = 'https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor'
|
19
|
+
LIVE_URL = 'https://ics2ws.ic3.com/commerce/1.x/transactionProcessor'
|
20
|
+
|
21
|
+
# visa, master, american_express, discover
|
22
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :discover]
|
23
|
+
self.supported_countries = ['US']
|
24
|
+
self.default_currency = 'USD'
|
25
|
+
self.homepage_url = 'http://www.cybersource.com'
|
26
|
+
self.display_name = 'CyberSource'
|
27
|
+
|
28
|
+
# map credit card to the CyberSource expected representation
|
29
|
+
@@credit_card_codes = {
|
30
|
+
:visa => '001',
|
31
|
+
:master => '002',
|
32
|
+
:american_express => '003',
|
33
|
+
:discover => '004'
|
34
|
+
}
|
35
|
+
|
36
|
+
# map response codes to something humans can read
|
37
|
+
@@response_codes = {
|
38
|
+
:r100 => "Successful transaction",
|
39
|
+
:r101 => "Request is missing one or more required fields" ,
|
40
|
+
:r102 => "One or more fields contains invalid data",
|
41
|
+
:r150 => "General failure",
|
42
|
+
:r151 => "The request was received but a server time-out occurred",
|
43
|
+
:r152 => "The request was received, but a service timed out",
|
44
|
+
:r200 => "The authorization request was approved by the issuing bank but declined by CyberSource because it did not pass the AVS check",
|
45
|
+
:r201 => "The issuing bank has questions about the request",
|
46
|
+
:r202 => "Expired card",
|
47
|
+
:r203 => "General decline of the card",
|
48
|
+
:r204 => "Insufficient funds in the account",
|
49
|
+
:r205 => "Stolen or lost card",
|
50
|
+
:r207 => "Issuing bank unavailable",
|
51
|
+
:r208 => "Inactive card or card not authorized for card-not-present transactions",
|
52
|
+
:r209 => "American Express Card Identifiction Digits (CID) did not match",
|
53
|
+
:r210 => "The card has reached the credit limit",
|
54
|
+
:r211 => "Invalid card verification number",
|
55
|
+
:r221 => "The customer matched an entry on the processor's negative file",
|
56
|
+
:r230 => "The authorization request was approved by the issuing bank but declined by CyberSource because it did not pass the card verification check",
|
57
|
+
:r231 => "Invalid account number",
|
58
|
+
:r232 => "The card type is not accepted by the payment processor",
|
59
|
+
:r233 => "General decline by the processor",
|
60
|
+
:r234 => "A problem exists with your CyberSource merchant configuration",
|
61
|
+
:r235 => "The requested amount exceeds the originally authorized amount",
|
62
|
+
:r236 => "Processor failure",
|
63
|
+
:r237 => "The authorization has already been reversed",
|
64
|
+
:r238 => "The authorization has already been captured",
|
65
|
+
:r239 => "The requested transaction amount must match the previous transaction amount",
|
66
|
+
:r240 => "The card type sent is invalid or does not correlate with the credit card number",
|
67
|
+
:r241 => "The request ID is invalid",
|
68
|
+
:r242 => "You requested a capture, but there is no corresponding, unused authorization record.",
|
69
|
+
:r243 => "The transaction has already been settled or reversed",
|
70
|
+
:r244 => "The bank account number failed the validation check",
|
71
|
+
:r246 => "The capture or credit is not voidable because the capture or credit information has already been submitted to your processor",
|
72
|
+
:r247 => "You requested a credit for a capture that was previously voided",
|
73
|
+
:r250 => "The request was received, but a time-out occurred with the payment processor",
|
74
|
+
:r254 => "Your CyberSource account is prohibited from processing stand-alone refunds",
|
75
|
+
:r255 => "Your CyberSource account is not configured to process the service in the country you specified"
|
76
|
+
}
|
77
|
+
|
78
|
+
# These are the options that can be used when creating a new CyberSource Gateway object.
|
79
|
+
#
|
80
|
+
# :login => your username
|
81
|
+
#
|
82
|
+
# :password => the transaction key you generated in the Business Center
|
83
|
+
#
|
84
|
+
# :test => true sets the gateway to test mode
|
85
|
+
#
|
86
|
+
# :vat_reg_number => your VAT registration number
|
87
|
+
#
|
88
|
+
# :nexus => "WI CA QC" sets the states/provinces where you have a physical presense for tax purposes
|
89
|
+
#
|
90
|
+
# :ignore_avs => true don't want to use AVS so continue processing even if AVS would have failed
|
91
|
+
#
|
92
|
+
# :ignore_cvv => true don't want to use CVV so continue processing even if CVV would have failed
|
93
|
+
def initialize(options = {})
|
94
|
+
requires!(options, :login, :password)
|
95
|
+
@options = options
|
96
|
+
super
|
97
|
+
end
|
98
|
+
|
99
|
+
# Should run against the test servers or not?
|
100
|
+
def test?
|
101
|
+
@options[:test] || Base.gateway_mode == :test
|
102
|
+
end
|
103
|
+
|
104
|
+
# Request an authorization for an amount from CyberSource
|
105
|
+
#
|
106
|
+
# You must supply an :order_id in the options hash
|
107
|
+
def authorize(money, creditcard, options = {})
|
108
|
+
requires!(options, :order_id, :email)
|
109
|
+
setup_address_hash(options)
|
110
|
+
commit(build_auth_request(money, creditcard, options), options )
|
111
|
+
end
|
112
|
+
|
113
|
+
def auth_reversal(money, identification, options = {})
|
114
|
+
commit(build_auth_reversal_request(money, identification, options), options)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Capture an authorization that has previously been requested
|
118
|
+
def capture(money, authorization, options = {})
|
119
|
+
setup_address_hash(options)
|
120
|
+
commit(build_capture_request(money, authorization, options), options)
|
121
|
+
end
|
122
|
+
|
123
|
+
# Purchase is an auth followed by a capture
|
124
|
+
# You must supply an order_id in the options hash
|
125
|
+
def purchase(money, creditcard, options = {})
|
126
|
+
requires!(options, :order_id, :email)
|
127
|
+
setup_address_hash(options)
|
128
|
+
commit(build_purchase_request(money, creditcard, options), options)
|
129
|
+
end
|
130
|
+
|
131
|
+
def void(identification, options = {})
|
132
|
+
commit(build_void_request(identification, options), options)
|
133
|
+
end
|
134
|
+
|
135
|
+
def refund(money, identification, options = {})
|
136
|
+
commit(build_credit_request(money, identification, options), options)
|
137
|
+
end
|
138
|
+
|
139
|
+
def credit(money, identification, options = {})
|
140
|
+
deprecated CREDIT_DEPRECATION_MESSAGE
|
141
|
+
refund(money, identification, options)
|
142
|
+
end
|
143
|
+
|
144
|
+
# CyberSource requires that you provide line item information for tax calculations
|
145
|
+
# If you do not have prices for each item or want to simplify the situation then pass in one fake line item that costs the subtotal of the order
|
146
|
+
#
|
147
|
+
# The line_item hash goes in the options hash and should look like
|
148
|
+
#
|
149
|
+
# :line_items => [
|
150
|
+
# {
|
151
|
+
# :declared_value => '1',
|
152
|
+
# :quantity => '2',
|
153
|
+
# :code => 'default',
|
154
|
+
# :description => 'Giant Walrus',
|
155
|
+
# :sku => 'WA323232323232323'
|
156
|
+
# },
|
157
|
+
# {
|
158
|
+
# :declared_value => '6',
|
159
|
+
# :quantity => '1',
|
160
|
+
# :code => 'default',
|
161
|
+
# :description => 'Marble Snowcone',
|
162
|
+
# :sku => 'FAKE1232132113123'
|
163
|
+
# }
|
164
|
+
# ]
|
165
|
+
#
|
166
|
+
# This functionality is only supported by this particular gateway may
|
167
|
+
# be changed at any time
|
168
|
+
def calculate_tax(creditcard, options)
|
169
|
+
requires!(options, :line_items)
|
170
|
+
setup_address_hash(options)
|
171
|
+
commit(build_tax_calculation_request(creditcard, options), options)
|
172
|
+
end
|
173
|
+
|
174
|
+
private
|
175
|
+
# Create all address hash key value pairs so that we still function if we were only provided with one or two of them
|
176
|
+
def setup_address_hash(options)
|
177
|
+
options[:billing_address] = options[:billing_address] || options[:address] || {}
|
178
|
+
options[:shipping_address] = options[:shipping_address] || {}
|
179
|
+
end
|
180
|
+
|
181
|
+
def build_auth_request(money, creditcard, options)
|
182
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
183
|
+
add_address(xml, creditcard, options[:billing_address], options)
|
184
|
+
add_purchase_data(xml, money, true, options)
|
185
|
+
add_creditcard(xml, creditcard)
|
186
|
+
add_auth_service(xml)
|
187
|
+
add_business_rules_data(xml)
|
188
|
+
xml.target!
|
189
|
+
end
|
190
|
+
|
191
|
+
def build_tax_calculation_request(creditcard, options)
|
192
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
193
|
+
add_address(xml, creditcard, options[:billing_address], options, false)
|
194
|
+
add_address(xml, creditcard, options[:shipping_address], options, true)
|
195
|
+
add_line_item_data(xml, options)
|
196
|
+
add_purchase_data(xml, 0, false, options)
|
197
|
+
add_tax_service(xml)
|
198
|
+
add_business_rules_data(xml)
|
199
|
+
xml.target!
|
200
|
+
end
|
201
|
+
|
202
|
+
def build_capture_request(money, authorization, options)
|
203
|
+
order_id, request_id, request_token = authorization.split(";")
|
204
|
+
options[:order_id] = order_id
|
205
|
+
|
206
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
207
|
+
add_purchase_data(xml, money, true, options)
|
208
|
+
add_capture_service(xml, request_id, request_token)
|
209
|
+
add_business_rules_data(xml)
|
210
|
+
xml.target!
|
211
|
+
end
|
212
|
+
|
213
|
+
def build_purchase_request(money, creditcard, options)
|
214
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
215
|
+
add_address(xml, creditcard, options[:billing_address], options)
|
216
|
+
add_purchase_data(xml, money, true, options)
|
217
|
+
add_creditcard(xml, creditcard)
|
218
|
+
add_purchase_service(xml, options)
|
219
|
+
add_business_rules_data(xml)
|
220
|
+
xml.target!
|
221
|
+
end
|
222
|
+
|
223
|
+
def build_void_request(identification, options)
|
224
|
+
order_id, request_id, request_token = identification.split(";")
|
225
|
+
options[:order_id] = order_id
|
226
|
+
|
227
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
228
|
+
add_void_service(xml, request_id, request_token)
|
229
|
+
xml.target!
|
230
|
+
end
|
231
|
+
|
232
|
+
def build_auth_reversal_request(money, identification, options)
|
233
|
+
order_id, request_id, request_token = identification.split(";")
|
234
|
+
options[:order_id] = order_id
|
235
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
236
|
+
add_purchase_data(xml, money, true, options)
|
237
|
+
add_auth_reversal_service(xml, request_id, request_token)
|
238
|
+
xml.target!
|
239
|
+
end
|
240
|
+
|
241
|
+
def build_credit_request(money, identification, options)
|
242
|
+
order_id, request_id, request_token = identification.split(";")
|
243
|
+
options[:order_id] = order_id
|
244
|
+
|
245
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
246
|
+
add_purchase_data(xml, money, true, options)
|
247
|
+
add_credit_service(xml, request_id, request_token)
|
248
|
+
|
249
|
+
xml.target!
|
250
|
+
end
|
251
|
+
|
252
|
+
def add_business_rules_data(xml)
|
253
|
+
xml.tag! 'businessRules' do
|
254
|
+
xml.tag!('ignoreAVSResult', 'true') if @options[:ignore_avs]
|
255
|
+
xml.tag!('ignoreCVResult', 'true') if @options[:ignore_cvv]
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
def add_line_item_data(xml, options)
|
260
|
+
options[:line_items].each_with_index do |value, index|
|
261
|
+
xml.tag! 'item', {'id' => index} do
|
262
|
+
xml.tag! 'unitPrice', amount(value[:declared_value])
|
263
|
+
xml.tag! 'quantity', value[:quantity]
|
264
|
+
xml.tag! 'productCode', value[:code] || 'shipping_only'
|
265
|
+
xml.tag! 'productName', value[:description]
|
266
|
+
xml.tag! 'productSKU', value[:sku]
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
def add_merchant_data(xml, options)
|
272
|
+
xml.tag! 'merchantID', @options[:login]
|
273
|
+
xml.tag! 'merchantReferenceCode', options[:order_id]
|
274
|
+
xml.tag! 'clientLibrary' ,'Ruby Active Merchant'
|
275
|
+
xml.tag! 'clientLibraryVersion', '1.0'
|
276
|
+
xml.tag! 'clientEnvironment' , 'Linux'
|
277
|
+
end
|
278
|
+
|
279
|
+
def add_purchase_data(xml, money = 0, include_grand_total = false, options={})
|
280
|
+
xml.tag! 'purchaseTotals' do
|
281
|
+
xml.tag! 'currency', options[:currency] || currency(money)
|
282
|
+
xml.tag!('grandTotalAmount', amount(money)) if include_grand_total
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
def add_address(xml, creditcard, address, options, shipTo = false)
|
287
|
+
xml.tag! shipTo ? 'shipTo' : 'billTo' do
|
288
|
+
xml.tag! 'firstName', creditcard.first_name
|
289
|
+
xml.tag! 'lastName', creditcard.last_name
|
290
|
+
xml.tag! 'street1', address[:address1]
|
291
|
+
xml.tag! 'street2', address[:address2]
|
292
|
+
xml.tag! 'city', address[:city]
|
293
|
+
xml.tag! 'state', address[:state]
|
294
|
+
xml.tag! 'postalCode', address[:zip]
|
295
|
+
xml.tag! 'country', address[:country]
|
296
|
+
xml.tag! 'email', options[:email]
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
def add_creditcard(xml, creditcard)
|
301
|
+
xml.tag! 'card' do
|
302
|
+
xml.tag! 'accountNumber', creditcard.number
|
303
|
+
xml.tag! 'expirationMonth', format(creditcard.month, :two_digits)
|
304
|
+
xml.tag! 'expirationYear', format(creditcard.year, :four_digits)
|
305
|
+
xml.tag!('cvNumber', creditcard.verification_value) unless (@options[:ignore_cvv] || creditcard.verification_value.blank? )
|
306
|
+
xml.tag! 'cardType', @@credit_card_codes[card_brand(creditcard).to_sym]
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
def add_tax_service(xml)
|
311
|
+
xml.tag! 'taxService', {'run' => 'true'} do
|
312
|
+
xml.tag!('nexus', @options[:nexus]) unless @options[:nexus].blank?
|
313
|
+
xml.tag!('sellerRegistration', @options[:vat_reg_number]) unless @options[:vat_reg_number].blank?
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
def add_auth_service(xml)
|
318
|
+
xml.tag! 'ccAuthService', {'run' => 'true'}
|
319
|
+
end
|
320
|
+
|
321
|
+
def add_capture_service(xml, request_id, request_token)
|
322
|
+
xml.tag! 'ccCaptureService', {'run' => 'true'} do
|
323
|
+
xml.tag! 'authRequestID', request_id
|
324
|
+
xml.tag! 'authRequestToken', request_token
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
def add_purchase_service(xml, options)
|
329
|
+
xml.tag! 'ccAuthService', {'run' => 'true'}
|
330
|
+
xml.tag! 'ccCaptureService', {'run' => 'true'}
|
331
|
+
end
|
332
|
+
|
333
|
+
def add_void_service(xml, request_id, request_token)
|
334
|
+
xml.tag! 'voidService', {'run' => 'true'} do
|
335
|
+
xml.tag! 'voidRequestID', request_id
|
336
|
+
xml.tag! 'voidRequestToken', request_token
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
def add_auth_reversal_service(xml, request_id, request_token)
|
341
|
+
xml.tag! 'ccAuthReversalService', {'run' => 'true'} do
|
342
|
+
xml.tag! 'authRequestID', request_id
|
343
|
+
xml.tag! 'authRequestToken', request_token
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
def add_credit_service(xml, request_id, request_token)
|
348
|
+
xml.tag! 'ccCreditService', {'run' => 'true'} do
|
349
|
+
xml.tag! 'captureRequestID', request_id
|
350
|
+
xml.tag! 'captureRequestToken', request_token
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
|
355
|
+
# Where we actually build the full SOAP request using builder
|
356
|
+
def build_request(body, options)
|
357
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
358
|
+
xml.instruct!
|
359
|
+
xml.tag! 's:Envelope', {'xmlns:s' => 'http://schemas.xmlsoap.org/soap/envelope/'} do
|
360
|
+
xml.tag! 's:Header' do
|
361
|
+
xml.tag! 'wsse:Security', {'s:mustUnderstand' => '1', 'xmlns:wsse' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'} do
|
362
|
+
xml.tag! 'wsse:UsernameToken' do
|
363
|
+
xml.tag! 'wsse:Username', @options[:login]
|
364
|
+
xml.tag! 'wsse:Password', @options[:password], 'Type' => 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'
|
365
|
+
end
|
366
|
+
end
|
367
|
+
end
|
368
|
+
xml.tag! 's:Body', {'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema'} do
|
369
|
+
xml.tag! 'requestMessage', {'xmlns' => 'urn:schemas-cybersource-com:transaction-data-1.32'} do
|
370
|
+
add_merchant_data(xml, options)
|
371
|
+
xml << body
|
372
|
+
end
|
373
|
+
end
|
374
|
+
end
|
375
|
+
xml.target!
|
376
|
+
end
|
377
|
+
|
378
|
+
# Contact CyberSource, make the SOAP request, and parse the reply into a Response object
|
379
|
+
def commit(request, options)
|
380
|
+
response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, build_request(request, options)))
|
381
|
+
|
382
|
+
success = response[:decision] == "ACCEPT"
|
383
|
+
message = @@response_codes[('r' + response[:reasonCode]).to_sym] rescue response[:message]
|
384
|
+
authorization = success ? [ options[:order_id], response[:requestID], response[:requestToken] ].compact.join(";") : nil
|
385
|
+
|
386
|
+
Response.new(success, message, response,
|
387
|
+
:test => test?,
|
388
|
+
:authorization => authorization,
|
389
|
+
:avs_result => { :code => response[:avsCode] },
|
390
|
+
:cvv_result => response[:cvCode]
|
391
|
+
)
|
392
|
+
end
|
393
|
+
|
394
|
+
# Parse the SOAP response
|
395
|
+
# Technique inspired by the Paypal Gateway
|
396
|
+
def parse(xml)
|
397
|
+
reply = {}
|
398
|
+
xml = REXML::Document.new(xml)
|
399
|
+
if root = REXML::XPath.first(xml, "//c:replyMessage")
|
400
|
+
root.elements.to_a.each do |node|
|
401
|
+
case node.name
|
402
|
+
when 'c:reasonCode'
|
403
|
+
reply[:message] = reply(node.text)
|
404
|
+
else
|
405
|
+
parse_element(reply, node)
|
406
|
+
end
|
407
|
+
end
|
408
|
+
elsif root = REXML::XPath.first(xml, "//soap:Fault")
|
409
|
+
parse_element(reply, root)
|
410
|
+
reply[:message] = "#{reply[:faultcode]}: #{reply[:faultstring]}"
|
411
|
+
end
|
412
|
+
return reply
|
413
|
+
end
|
414
|
+
|
415
|
+
def parse_element(reply, node)
|
416
|
+
if node.has_elements?
|
417
|
+
node.elements.each{|e| parse_element(reply, e) }
|
418
|
+
else
|
419
|
+
if node.parent.name =~ /item/
|
420
|
+
parent = node.parent.name + (node.parent.attributes["id"] ? "_" + node.parent.attributes["id"] : '')
|
421
|
+
reply[(parent + '_' + node.name).to_sym] = node.text
|
422
|
+
else
|
423
|
+
reply[node.name.to_sym] = node.text
|
424
|
+
end
|
425
|
+
end
|
426
|
+
return reply
|
427
|
+
end
|
428
|
+
end
|
429
|
+
end
|
430
|
+
end
|