tlconnor-activemerchant 1.20.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +805 -0
- data/CONTRIBUTORS +274 -0
- data/MIT-LICENSE +20 -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 +264 -0
- data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
- data/lib/active_merchant/billing/credit_card_methods.rb +129 -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 +944 -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 +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 +308 -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 +135 -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 +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/jetpay.rb +276 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +454 -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/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 +239 -0
- data/lib/active_merchant/billing/gateways/nab_transact.rb +244 -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 +330 -0
- data/lib/active_merchant/billing/gateways/optimal_payment.rb +277 -0
- data/lib/active_merchant/billing/gateways/orbital.rb +344 -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 +207 -0
- data/lib/active_merchant/billing/gateways/payflow.rb +261 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +208 -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 +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.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_express.rb +229 -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 +298 -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/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 +280 -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 +244 -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 +23 -0
- data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1496 -0
- data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +206 -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 +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/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/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 +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 +127 -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 +22 -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 +411 -0
@@ -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
|
@@ -0,0 +1,597 @@
|
|
1
|
+
module ActiveMerchant
|
2
|
+
module Billing
|
3
|
+
class DataCashGateway < Gateway
|
4
|
+
self.default_currency = 'GBP'
|
5
|
+
self.supported_countries = ['GB']
|
6
|
+
|
7
|
+
# From the DataCash docs; Page 13, the following cards are
|
8
|
+
# usable:
|
9
|
+
# American Express, ATM, Carte Blanche, Diners Club, Discover,
|
10
|
+
# EnRoute, GE Capital, JCB, Laser, Maestro, Mastercard, Solo,
|
11
|
+
# Switch, Visa, Visa Delta, VISA Electron, Visa Purchasing
|
12
|
+
#
|
13
|
+
# Note continuous authority is only supported for :visa, :master and :american_express card types
|
14
|
+
self.supported_cardtypes = [ :visa, :master, :american_express, :discover, :diners_club, :jcb, :maestro, :switch, :solo, :laser ]
|
15
|
+
|
16
|
+
self.homepage_url = 'http://www.datacash.com/'
|
17
|
+
self.display_name = 'DataCash'
|
18
|
+
|
19
|
+
# Datacash server URLs
|
20
|
+
TEST_URL = 'https://testserver.datacash.com/Transaction'
|
21
|
+
LIVE_URL = 'https://mars.transaction.datacash.com/Transaction'
|
22
|
+
|
23
|
+
# Different Card Transaction Types
|
24
|
+
AUTH_TYPE = 'auth'
|
25
|
+
CANCEL_TYPE = 'cancel'
|
26
|
+
FULFILL_TYPE = 'fulfill'
|
27
|
+
PRE_TYPE = 'pre'
|
28
|
+
REFUND_TYPE = 'refund'
|
29
|
+
TRANSACTION_REFUND_TYPE = 'txn_refund'
|
30
|
+
|
31
|
+
# Constant strings for use in the ExtendedPolicy complex element for
|
32
|
+
# CV2 checks
|
33
|
+
POLICY_ACCEPT = 'accept'
|
34
|
+
POLICY_REJECT = 'reject'
|
35
|
+
|
36
|
+
# Datacash success code
|
37
|
+
DATACASH_SUCCESS = '1'
|
38
|
+
|
39
|
+
# Creates a new DataCashGateway
|
40
|
+
#
|
41
|
+
# The gateway requires that a valid login and password be passed
|
42
|
+
# in the +options+ hash.
|
43
|
+
#
|
44
|
+
# ==== Options
|
45
|
+
#
|
46
|
+
# * <tt>:login</tt> -- The Datacash account login.
|
47
|
+
# * <tt>:password</tt> -- The Datacash account password.
|
48
|
+
# * <tt>:test => +true+ or +false+</tt> -- Use the test or live Datacash url.
|
49
|
+
#
|
50
|
+
def initialize(options = {})
|
51
|
+
requires!(options, :login, :password)
|
52
|
+
@options = options
|
53
|
+
super
|
54
|
+
end
|
55
|
+
|
56
|
+
# Perform a purchase, which is essentially an authorization and capture in a single operation.
|
57
|
+
#
|
58
|
+
# ==== Parameters
|
59
|
+
# * <tt>money</tt> The amount to be authorized as an Integer value in cents.
|
60
|
+
# * <tt>authorization_or_credit_card</tt>:: The continuous authority reference or CreditCard details for the transaction.
|
61
|
+
# * <tt>options</tt> A hash of optional parameters.
|
62
|
+
# * <tt>:order_id</tt> A unique reference for this order (corresponds to merchantreference in datacash documentation)
|
63
|
+
# * <tt>:set_up_continuous_authority</tt>
|
64
|
+
# Set to true to set up a recurring historic transaction account be set up.
|
65
|
+
# Only supported for :visa, :master and :american_express card types
|
66
|
+
# See http://www.datacash.com/services/recurring/historic.php for more details of historic transactions.
|
67
|
+
# * <tt>:address</tt>:: billing address for card
|
68
|
+
#
|
69
|
+
# The continuous authority reference will be available in response#params['ca_referece'] if you have requested one
|
70
|
+
def purchase(money, authorization_or_credit_card, options = {})
|
71
|
+
requires!(options, :order_id)
|
72
|
+
|
73
|
+
if authorization_or_credit_card.is_a?(String)
|
74
|
+
request = build_purchase_or_authorization_request_with_continuous_authority_reference_request(AUTH_TYPE, money, authorization_or_credit_card, options)
|
75
|
+
else
|
76
|
+
request = build_purchase_or_authorization_request_with_credit_card_request(AUTH_TYPE, money, authorization_or_credit_card, options)
|
77
|
+
end
|
78
|
+
|
79
|
+
commit(request)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Performs an authorization, which reserves the funds on the customer's credit card, but does not
|
83
|
+
# charge the card.
|
84
|
+
#
|
85
|
+
# ==== Parameters
|
86
|
+
#
|
87
|
+
# * <tt>money</tt> The amount to be authorized as an Integer value in cents.
|
88
|
+
# * <tt>authorization_or_credit_card</tt>:: The continuous authority reference or CreditCard details for the transaction.
|
89
|
+
# * <tt>options</tt> A hash of optional parameters.
|
90
|
+
# * <tt>:order_id</tt> A unique reference for this order (corresponds to merchantreference in datacash documentation)
|
91
|
+
# * <tt>:set_up_continuous_authority</tt>::
|
92
|
+
# Set to true to set up a recurring historic transaction account be set up.
|
93
|
+
# Only supported for :visa, :master and :american_express card types
|
94
|
+
# See http://www.datacash.com/services/recurring/historic.php for more details of historic transactions.
|
95
|
+
# * <tt>:address</tt>:: billing address for card
|
96
|
+
#
|
97
|
+
# The continuous authority reference will be available in response#params['ca_referece'] if you have requested one
|
98
|
+
def authorize(money, authorization_or_credit_card, options = {})
|
99
|
+
requires!(options, :order_id)
|
100
|
+
|
101
|
+
if authorization_or_credit_card.is_a?(String)
|
102
|
+
request = build_purchase_or_authorization_request_with_continuous_authority_reference_request(AUTH_TYPE, money, authorization_or_credit_card, options)
|
103
|
+
else
|
104
|
+
request = build_purchase_or_authorization_request_with_credit_card_request(PRE_TYPE, money, authorization_or_credit_card, options)
|
105
|
+
end
|
106
|
+
|
107
|
+
commit(request)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Captures the funds from an authorized transaction.
|
111
|
+
#
|
112
|
+
# ==== Parameters
|
113
|
+
#
|
114
|
+
# * <tt>money</tt> -- The amount to be captured as anInteger value in cents.
|
115
|
+
# * <tt>authorization</tt> -- The authorization returned from the previous authorize request.
|
116
|
+
def capture(money, authorization, options = {})
|
117
|
+
commit(build_void_or_capture_request(FULFILL_TYPE, money, authorization, options))
|
118
|
+
end
|
119
|
+
|
120
|
+
# Void a previous transaction
|
121
|
+
#
|
122
|
+
# ==== Parameters
|
123
|
+
#
|
124
|
+
# * <tt>authorization</tt> - The authorization returned from the previous authorize request.
|
125
|
+
def void(authorization, options = {})
|
126
|
+
request = build_void_or_capture_request(CANCEL_TYPE, nil, authorization, options)
|
127
|
+
|
128
|
+
commit(request)
|
129
|
+
end
|
130
|
+
|
131
|
+
# Refund to a card
|
132
|
+
#
|
133
|
+
# ==== Parameters
|
134
|
+
#
|
135
|
+
# * <tt>money</tt> The amount to be refunded as an Integer value in cents. Set to nil for a full refund on existing transaction.
|
136
|
+
# * <tt>reference_or_credit_card</tt> The credit card you want to refund OR the datacash_reference for the existing transaction you are refunding
|
137
|
+
# * <tt>options</tt> Are ignored when refunding via reference to an existing transaction, otherwise
|
138
|
+
# * <tt>:order_id</tt> A unique reference for this order (corresponds to merchantreference in datacash documentation)
|
139
|
+
# * <tt>:address</tt>:: billing address for card
|
140
|
+
def credit(money, reference_or_credit_card, options = {})
|
141
|
+
if reference_or_credit_card.is_a?(String)
|
142
|
+
deprecated CREDIT_DEPRECATION_MESSAGE
|
143
|
+
refund(money, reference_or_credit_card)
|
144
|
+
else
|
145
|
+
request = build_refund_request(money, reference_or_credit_card, options)
|
146
|
+
commit(request)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def refund(money, reference, options = {})
|
151
|
+
commit(build_transaction_refund_request(money, reference))
|
152
|
+
end
|
153
|
+
|
154
|
+
# Is the gateway running in test mode?
|
155
|
+
def test?
|
156
|
+
@options[:test] || super
|
157
|
+
end
|
158
|
+
|
159
|
+
private
|
160
|
+
# Create the xml document for a 'cancel' or 'fulfill' transaction.
|
161
|
+
#
|
162
|
+
# Final XML should look like:
|
163
|
+
# <Request>
|
164
|
+
# <Authentication>
|
165
|
+
# <client>99000001</client>
|
166
|
+
# <password>******</password>
|
167
|
+
# </Authentication>
|
168
|
+
# <Transaction>
|
169
|
+
# <TxnDetails>
|
170
|
+
# <amount>25.00</amount>
|
171
|
+
# </TxnDetails>
|
172
|
+
# <HistoricTxn>
|
173
|
+
# <reference>4900200000000001</reference>
|
174
|
+
# <authcode>A6</authcode>
|
175
|
+
# <method>fulfill</method>
|
176
|
+
# </HistoricTxn>
|
177
|
+
# </Transaction>
|
178
|
+
# </Request>
|
179
|
+
#
|
180
|
+
# Parameters:
|
181
|
+
# * <tt>type</tt> must be FULFILL_TYPE or CANCEL_TYPE
|
182
|
+
# * <tt>money</tt> - optional - Integer value in cents
|
183
|
+
# * <tt>authorization</tt> - the Datacash authorization from a previous succesful authorize transaction
|
184
|
+
# * <tt>options</tt>
|
185
|
+
# * <tt>order_id</tt> - A unique reference for the transaction
|
186
|
+
#
|
187
|
+
# Returns:
|
188
|
+
# -Builder xml document
|
189
|
+
#
|
190
|
+
def build_void_or_capture_request(type, money, authorization, options)
|
191
|
+
reference, auth_code, ca_reference = authorization.to_s.split(';')
|
192
|
+
|
193
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
194
|
+
xml.instruct!
|
195
|
+
xml.tag! :Request do
|
196
|
+
add_authentication(xml)
|
197
|
+
|
198
|
+
xml.tag! :Transaction do
|
199
|
+
xml.tag! :HistoricTxn do
|
200
|
+
xml.tag! :reference, reference
|
201
|
+
xml.tag! :authcode, auth_code
|
202
|
+
xml.tag! :method, type
|
203
|
+
end
|
204
|
+
|
205
|
+
if money
|
206
|
+
xml.tag! :TxnDetails do
|
207
|
+
xml.tag! :merchantreference, format_reference_number(options[:order_id])
|
208
|
+
xml.tag! :amount, amount(money), :currency => options[:currency] || currency(money)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
xml.target!
|
214
|
+
end
|
215
|
+
|
216
|
+
# Create the xml document for an 'auth' or 'pre' transaction with a credit card
|
217
|
+
#
|
218
|
+
# Final XML should look like:
|
219
|
+
#
|
220
|
+
# <Request>
|
221
|
+
# <Authentication>
|
222
|
+
# <client>99000000</client>
|
223
|
+
# <password>*******</password>
|
224
|
+
# </Authentication>
|
225
|
+
# <Transaction>
|
226
|
+
# <TxnDetails>
|
227
|
+
# <merchantreference>123456</merchantreference>
|
228
|
+
# <amount currency="EUR">10.00</amount>
|
229
|
+
# </TxnDetails>
|
230
|
+
# <CardTxn>
|
231
|
+
# <Card>
|
232
|
+
# <pan>4444********1111</pan>
|
233
|
+
# <expirydate>03/04</expirydate>
|
234
|
+
# <Cv2Avs>
|
235
|
+
# <street_address1>Flat 7</street_address1>
|
236
|
+
# <street_address2>89 Jumble
|
237
|
+
# Street</street_address2>
|
238
|
+
# <street_address3>Mytown</street_address3>
|
239
|
+
# <postcode>AV12FR</postcode>
|
240
|
+
# <cv2>123</cv2>
|
241
|
+
# <ExtendedPolicy>
|
242
|
+
# <cv2_policy notprovided="reject"
|
243
|
+
# notchecked="accept"
|
244
|
+
# matched="accept"
|
245
|
+
# notmatched="reject"
|
246
|
+
# partialmatch="reject"/>
|
247
|
+
# <postcode_policy notprovided="reject"
|
248
|
+
# notchecked="accept"
|
249
|
+
# matched="accept"
|
250
|
+
# notmatched="reject"
|
251
|
+
# partialmatch="accept"/>
|
252
|
+
# <address_policy notprovided="reject"
|
253
|
+
# notchecked="accept"
|
254
|
+
# matched="accept"
|
255
|
+
# notmatched="reject"
|
256
|
+
# partialmatch="accept"/>
|
257
|
+
# </ExtendedPolicy>
|
258
|
+
# </Cv2Avs>
|
259
|
+
# </Card>
|
260
|
+
# <method>auth</method>
|
261
|
+
# </CardTxn>
|
262
|
+
# </Transaction>
|
263
|
+
# </Request>
|
264
|
+
#
|
265
|
+
# Parameters:
|
266
|
+
# -type must be 'auth' or 'pre'
|
267
|
+
# -money - A money object with the price and currency
|
268
|
+
# -credit_card - The credit_card details to use
|
269
|
+
# -options:
|
270
|
+
# :order_id is the merchant reference number
|
271
|
+
# :billing_address is the billing address for the cc
|
272
|
+
# :address is the delivery address
|
273
|
+
#
|
274
|
+
# Returns:
|
275
|
+
# -xml: Builder document containing the markup
|
276
|
+
#
|
277
|
+
def build_purchase_or_authorization_request_with_credit_card_request(type, money, credit_card, options)
|
278
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
279
|
+
xml.instruct!
|
280
|
+
xml.tag! :Request do
|
281
|
+
add_authentication(xml)
|
282
|
+
|
283
|
+
xml.tag! :Transaction do
|
284
|
+
if options[:set_up_continuous_authority]
|
285
|
+
xml.tag! :ContAuthTxn, :type => 'setup'
|
286
|
+
end
|
287
|
+
xml.tag! :CardTxn do
|
288
|
+
xml.tag! :method, type
|
289
|
+
add_credit_card(xml, credit_card, options[:billing_address])
|
290
|
+
end
|
291
|
+
xml.tag! :TxnDetails do
|
292
|
+
xml.tag! :merchantreference, format_reference_number(options[:order_id])
|
293
|
+
xml.tag! :amount, amount(money), :currency => options[:currency] || currency(money)
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|
297
|
+
xml.target!
|
298
|
+
end
|
299
|
+
|
300
|
+
# Create the xml document for an 'auth' or 'pre' transaction with
|
301
|
+
# continuous authorization
|
302
|
+
#
|
303
|
+
# Final XML should look like:
|
304
|
+
#
|
305
|
+
# <Request>
|
306
|
+
# <Transaction>
|
307
|
+
# <ContAuthTxn type="historic" />
|
308
|
+
# <TxnDetails>
|
309
|
+
# <merchantreference>3851231</merchantreference>
|
310
|
+
# <capturemethod>cont_auth</capturemethod>
|
311
|
+
# <amount currency="GBP">18.50</amount>
|
312
|
+
# </TxnDetails>
|
313
|
+
# <HistoricTxn>
|
314
|
+
# <reference>4500200040925092</reference>
|
315
|
+
# <method>auth</method>
|
316
|
+
# </HistoricTxn>
|
317
|
+
# </Transaction>
|
318
|
+
# <Authentication>
|
319
|
+
# <client>99000001</client>
|
320
|
+
# <password>mypasswd</password>
|
321
|
+
# </Authentication>
|
322
|
+
# </Request>
|
323
|
+
#
|
324
|
+
# Parameters:
|
325
|
+
# -type must be 'auth' or 'pre'
|
326
|
+
# -money - A money object with the price and currency
|
327
|
+
# -authorization - The authorization containing a continuous authority reference previously set up on a credit card
|
328
|
+
# -options:
|
329
|
+
# :order_id is the merchant reference number
|
330
|
+
#
|
331
|
+
# Returns:
|
332
|
+
# -xml: Builder document containing the markup
|
333
|
+
#
|
334
|
+
def build_purchase_or_authorization_request_with_continuous_authority_reference_request(type, money, authorization, options)
|
335
|
+
reference, auth_code, ca_reference = authorization.to_s.split(';')
|
336
|
+
raise ArgumentError, "The continuous authority reference is required for continuous authority transactions" if ca_reference.blank?
|
337
|
+
|
338
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
339
|
+
xml.instruct!
|
340
|
+
xml.tag! :Request do
|
341
|
+
add_authentication(xml)
|
342
|
+
xml.tag! :Transaction do
|
343
|
+
xml.tag! :ContAuthTxn, :type => 'historic'
|
344
|
+
xml.tag! :HistoricTxn do
|
345
|
+
xml.tag! :reference, ca_reference
|
346
|
+
xml.tag! :method, type
|
347
|
+
end
|
348
|
+
xml.tag! :TxnDetails do
|
349
|
+
xml.tag! :merchantreference, format_reference_number(options[:order_id])
|
350
|
+
xml.tag! :amount, amount(money), :currency => options[:currency] || currency(money)
|
351
|
+
xml.tag! :capturemethod, 'cont_auth'
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|
355
|
+
xml.target!
|
356
|
+
end
|
357
|
+
|
358
|
+
# Create the xml document for a full or partial refund transaction with
|
359
|
+
#
|
360
|
+
# Final XML should look like:
|
361
|
+
#
|
362
|
+
# <Request>
|
363
|
+
# <Authentication>
|
364
|
+
# <client>99000001</client>
|
365
|
+
# <password>*******</password>
|
366
|
+
# </Authentication>
|
367
|
+
# <Transaction>
|
368
|
+
# <HistoricTxn>
|
369
|
+
# <method>txn_refund</method>
|
370
|
+
# <reference>12345678</reference>
|
371
|
+
# </HistoricTxn>
|
372
|
+
# <TxnDetails>
|
373
|
+
# <amount>10.00</amount>
|
374
|
+
# </TxnDetails>
|
375
|
+
# </Transaction>
|
376
|
+
# </Request>
|
377
|
+
#
|
378
|
+
def build_transaction_refund_request(money, reference)
|
379
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
380
|
+
xml.instruct!
|
381
|
+
xml.tag! :Request do
|
382
|
+
add_authentication(xml)
|
383
|
+
xml.tag! :Transaction do
|
384
|
+
xml.tag! :HistoricTxn do
|
385
|
+
xml.tag! :reference, reference
|
386
|
+
xml.tag! :method, TRANSACTION_REFUND_TYPE
|
387
|
+
end
|
388
|
+
unless money.nil?
|
389
|
+
xml.tag! :TxnDetails do
|
390
|
+
xml.tag! :amount, amount(money)
|
391
|
+
end
|
392
|
+
end
|
393
|
+
end
|
394
|
+
end
|
395
|
+
xml.target!
|
396
|
+
end
|
397
|
+
|
398
|
+
# Create the xml document for a full or partial refund with
|
399
|
+
#
|
400
|
+
# Final XML should look like:
|
401
|
+
#
|
402
|
+
# <Request>
|
403
|
+
# <Authentication>
|
404
|
+
# <client>99000001</client>
|
405
|
+
# <password>*****</password>
|
406
|
+
# </Authentication>
|
407
|
+
# <Transaction>
|
408
|
+
# <CardTxn>
|
409
|
+
# <Card>
|
410
|
+
# <pan>633300*********1</pan>
|
411
|
+
# <expirydate>04/06</expirydate>
|
412
|
+
# <startdate>01/04</startdate>
|
413
|
+
# </Card>
|
414
|
+
# <method>refund</method>
|
415
|
+
# </CardTxn>
|
416
|
+
# <TxnDetails>
|
417
|
+
# <merchantreference>1000001</merchantreference>
|
418
|
+
# <amount currency="GBP">95.99</amount>
|
419
|
+
# </TxnDetails>
|
420
|
+
# </Transaction>
|
421
|
+
# </Request>
|
422
|
+
def build_refund_request(money, credit_card, options)
|
423
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
424
|
+
xml.instruct!
|
425
|
+
xml.tag! :Request do
|
426
|
+
add_authentication(xml)
|
427
|
+
xml.tag! :Transaction do
|
428
|
+
xml.tag! :CardTxn do
|
429
|
+
xml.tag! :method, REFUND_TYPE
|
430
|
+
add_credit_card(xml, credit_card, options[:billing_address])
|
431
|
+
end
|
432
|
+
xml.tag! :TxnDetails do
|
433
|
+
xml.tag! :merchantreference, format_reference_number(options[:order_id])
|
434
|
+
xml.tag! :amount, amount(money)
|
435
|
+
end
|
436
|
+
end
|
437
|
+
end
|
438
|
+
xml.target!
|
439
|
+
end
|
440
|
+
|
441
|
+
|
442
|
+
# Adds the authentication element to the passed builder xml doc
|
443
|
+
#
|
444
|
+
# Parameters:
|
445
|
+
# -xml: Builder document that is being built up
|
446
|
+
#
|
447
|
+
# Returns:
|
448
|
+
# -none: The results is stored in the passed xml document
|
449
|
+
#
|
450
|
+
def add_authentication(xml)
|
451
|
+
xml.tag! :Authentication do
|
452
|
+
xml.tag! :client, @options[:login]
|
453
|
+
xml.tag! :password, @options[:password]
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
# Add credit_card detals to the passed XML Builder doc
|
458
|
+
#
|
459
|
+
# Parameters:
|
460
|
+
# -xml: Builder document that is being built up
|
461
|
+
# -credit_card: ActiveMerchant::Billing::CreditCard object
|
462
|
+
# -billing_address: Hash containing all of the billing address details
|
463
|
+
#
|
464
|
+
# Returns:
|
465
|
+
# -none: The results is stored in the passed xml document
|
466
|
+
#
|
467
|
+
def add_credit_card(xml, credit_card, address)
|
468
|
+
|
469
|
+
xml.tag! :Card do
|
470
|
+
|
471
|
+
# DataCash calls the CC number 'pan'
|
472
|
+
xml.tag! :pan, credit_card.number
|
473
|
+
xml.tag! :expirydate, format_date(credit_card.month, credit_card.year)
|
474
|
+
|
475
|
+
# optional values - for Solo etc
|
476
|
+
if [ 'switch', 'solo' ].include?(card_brand(credit_card).to_s)
|
477
|
+
|
478
|
+
xml.tag! :issuenumber, credit_card.issue_number unless credit_card.issue_number.blank?
|
479
|
+
|
480
|
+
if !credit_card.start_month.blank? && !credit_card.start_year.blank?
|
481
|
+
xml.tag! :startdate, format_date(credit_card.start_month, credit_card.start_year)
|
482
|
+
end
|
483
|
+
end
|
484
|
+
|
485
|
+
xml.tag! :Cv2Avs do
|
486
|
+
xml.tag! :cv2, credit_card.verification_value if credit_card.verification_value?
|
487
|
+
if address
|
488
|
+
xml.tag! :street_address1, address[:address1] unless address[:address1].blank?
|
489
|
+
xml.tag! :street_address2, address[:address2] unless address[:address2].blank?
|
490
|
+
xml.tag! :street_address3, address[:address3] unless address[:address3].blank?
|
491
|
+
xml.tag! :street_address4, address[:address4] unless address[:address4].blank?
|
492
|
+
xml.tag! :postcode, address[:zip] unless address[:zip].blank?
|
493
|
+
end
|
494
|
+
|
495
|
+
# The ExtendedPolicy defines what to do when the passed data
|
496
|
+
# matches, or not...
|
497
|
+
#
|
498
|
+
# All of the following elements MUST be present for the
|
499
|
+
# xml to be valid (or can drop the ExtendedPolicy and use
|
500
|
+
# a predefined one
|
501
|
+
xml.tag! :ExtendedPolicy do
|
502
|
+
xml.tag! :cv2_policy,
|
503
|
+
:notprovided => POLICY_REJECT,
|
504
|
+
:notchecked => POLICY_REJECT,
|
505
|
+
:matched => POLICY_ACCEPT,
|
506
|
+
:notmatched => POLICY_REJECT,
|
507
|
+
:partialmatch => POLICY_REJECT
|
508
|
+
xml.tag! :postcode_policy,
|
509
|
+
:notprovided => POLICY_ACCEPT,
|
510
|
+
:notchecked => POLICY_ACCEPT,
|
511
|
+
:matched => POLICY_ACCEPT,
|
512
|
+
:notmatched => POLICY_REJECT,
|
513
|
+
:partialmatch => POLICY_ACCEPT
|
514
|
+
xml.tag! :address_policy,
|
515
|
+
:notprovided => POLICY_ACCEPT,
|
516
|
+
:notchecked => POLICY_ACCEPT,
|
517
|
+
:matched => POLICY_ACCEPT,
|
518
|
+
:notmatched => POLICY_REJECT,
|
519
|
+
:partialmatch => POLICY_ACCEPT
|
520
|
+
end
|
521
|
+
end
|
522
|
+
end
|
523
|
+
end
|
524
|
+
|
525
|
+
# Send the passed data to DataCash for processing
|
526
|
+
#
|
527
|
+
# Parameters:
|
528
|
+
# -request: The XML data that is to be sent to Datacash
|
529
|
+
#
|
530
|
+
# Returns:
|
531
|
+
# - ActiveMerchant::Billing::Response object
|
532
|
+
#
|
533
|
+
def commit(request)
|
534
|
+
response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, request))
|
535
|
+
|
536
|
+
Response.new(response[:status] == DATACASH_SUCCESS, response[:reason], response,
|
537
|
+
:test => test?,
|
538
|
+
:authorization => "#{response[:datacash_reference]};#{response[:authcode]};#{response[:ca_reference]}"
|
539
|
+
)
|
540
|
+
end
|
541
|
+
|
542
|
+
# Returns a date string in the format Datacash expects
|
543
|
+
#
|
544
|
+
# Parameters:
|
545
|
+
# -month: integer, the month
|
546
|
+
# -year: integer, the year
|
547
|
+
#
|
548
|
+
# Returns:
|
549
|
+
# -String: date in MM/YY format
|
550
|
+
#
|
551
|
+
def format_date(month, year)
|
552
|
+
"#{format(month,:two_digits)}/#{format(year, :two_digits)}"
|
553
|
+
end
|
554
|
+
|
555
|
+
# Parse the datacash response and create a Response object
|
556
|
+
#
|
557
|
+
# Parameters:
|
558
|
+
# -body: The XML returned from Datacash
|
559
|
+
#
|
560
|
+
# Returns:
|
561
|
+
# -a hash with all of the values returned in the Datacash XML response
|
562
|
+
#
|
563
|
+
def parse(body)
|
564
|
+
|
565
|
+
response = {}
|
566
|
+
xml = REXML::Document.new(body)
|
567
|
+
root = REXML::XPath.first(xml, "//Response")
|
568
|
+
|
569
|
+
root.elements.to_a.each do |node|
|
570
|
+
parse_element(response, node)
|
571
|
+
end
|
572
|
+
|
573
|
+
response
|
574
|
+
end
|
575
|
+
|
576
|
+
# Parse an xml element
|
577
|
+
#
|
578
|
+
# Parameters:
|
579
|
+
# -response: The hash that the values are being returned in
|
580
|
+
# -node: The node that is currently being read
|
581
|
+
#
|
582
|
+
# Returns:
|
583
|
+
# - none (results are stored in the passed hash)
|
584
|
+
def parse_element(response, node)
|
585
|
+
if node.has_elements?
|
586
|
+
node.elements.each{|e| parse_element(response, e) }
|
587
|
+
else
|
588
|
+
response[node.name.underscore.to_sym] = node.text
|
589
|
+
end
|
590
|
+
end
|
591
|
+
|
592
|
+
def format_reference_number(number)
|
593
|
+
number.to_s.gsub(/[^A-Za-z0-9]/, '').rjust(6, "0").first(30)
|
594
|
+
end
|
595
|
+
end
|
596
|
+
end
|
597
|
+
end
|