aktivemerchant 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +1596 -0
- data/CONTRIBUTORS +511 -0
- data/MIT-LICENSE +20 -0
- data/README.md +18 -0
- data/lib/active_merchant.rb +108 -0
- data/lib/active_merchant/billing.rb +13 -0
- data/lib/active_merchant/billing/apple_pay_payment_token.rb +22 -0
- data/lib/active_merchant/billing/avs_result.rb +98 -0
- data/lib/active_merchant/billing/base.rb +72 -0
- data/lib/active_merchant/billing/check.rb +76 -0
- data/lib/active_merchant/billing/compatibility.rb +120 -0
- data/lib/active_merchant/billing/credit_card.rb +352 -0
- data/lib/active_merchant/billing/credit_card_formatting.rb +24 -0
- data/lib/active_merchant/billing/credit_card_methods.rb +160 -0
- data/lib/active_merchant/billing/cvv_result.rb +38 -0
- data/lib/active_merchant/billing/gateway.rb +268 -0
- data/lib/active_merchant/billing/gateways.rb +17 -0
- data/lib/active_merchant/billing/gateways/adyen.rb +209 -0
- data/lib/active_merchant/billing/gateways/alfabank.rb +117 -0
- data/lib/active_merchant/billing/gateways/app55.rb +176 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +419 -0
- data/lib/active_merchant/billing/gateways/authorize_net_arb.rb +417 -0
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +976 -0
- data/lib/active_merchant/billing/gateways/balanced.rb +256 -0
- data/lib/active_merchant/billing/gateways/bank_frick.rb +225 -0
- data/lib/active_merchant/billing/gateways/banwire.rb +105 -0
- data/lib/active_merchant/billing/gateways/barclays_epdq.rb +314 -0
- data/lib/active_merchant/billing/gateways/barclays_epdq_extra_plus.rb +15 -0
- data/lib/active_merchant/billing/gateways/be2bill.rb +131 -0
- data/lib/active_merchant/billing/gateways/beanstream.rb +188 -0
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +393 -0
- data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
- data/lib/active_merchant/billing/gateways/blue_pay.rb +506 -0
- data/lib/active_merchant/billing/gateways/bogus.rb +140 -0
- data/lib/active_merchant/billing/gateways/borgun.rb +210 -0
- data/lib/active_merchant/billing/gateways/braintree.rb +19 -0
- data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
- data/lib/active_merchant/billing/gateways/braintree_blue.rb +515 -0
- data/lib/active_merchant/billing/gateways/braintree_orange.rb +20 -0
- data/lib/active_merchant/billing/gateways/bridge_pay.rb +189 -0
- data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
- data/lib/active_merchant/billing/gateways/card_stream.rb +220 -0
- data/lib/active_merchant/billing/gateways/cashnet.rb +191 -0
- data/lib/active_merchant/billing/gateways/cc5.rb +201 -0
- data/lib/active_merchant/billing/gateways/cecabank.rb +229 -0
- data/lib/active_merchant/billing/gateways/certo_direct.rb +278 -0
- data/lib/active_merchant/billing/gateways/checkout.rb +213 -0
- data/lib/active_merchant/billing/gateways/commercegate.rb +143 -0
- data/lib/active_merchant/billing/gateways/conekta.rb +209 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +709 -0
- data/lib/active_merchant/billing/gateways/data_cash.rb +600 -0
- data/lib/active_merchant/billing/gateways/efsnet.rb +219 -0
- data/lib/active_merchant/billing/gateways/elavon.rb +348 -0
- data/lib/active_merchant/billing/gateways/epay.rb +275 -0
- data/lib/active_merchant/billing/gateways/evo_ca.rb +308 -0
- data/lib/active_merchant/billing/gateways/eway.rb +214 -0
- data/lib/active_merchant/billing/gateways/eway_managed.rb +291 -0
- data/lib/active_merchant/billing/gateways/eway_rapid.rb +524 -0
- data/lib/active_merchant/billing/gateways/exact.rb +218 -0
- data/lib/active_merchant/billing/gateways/fat_zebra.rb +173 -0
- data/lib/active_merchant/billing/gateways/federated_canada.rb +160 -0
- data/lib/active_merchant/billing/gateways/finansbank.rb +23 -0
- data/lib/active_merchant/billing/gateways/first_giving.rb +143 -0
- data/lib/active_merchant/billing/gateways/first_pay.rb +160 -0
- data/lib/active_merchant/billing/gateways/firstdata_e4.rb +355 -0
- data/lib/active_merchant/billing/gateways/garanti.rb +257 -0
- data/lib/active_merchant/billing/gateways/global_transport.rb +183 -0
- data/lib/active_merchant/billing/gateways/hdfc.rb +207 -0
- data/lib/active_merchant/billing/gateways/hps.rb +288 -0
- data/lib/active_merchant/billing/gateways/iats_payments.rb +251 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +246 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
- data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +66 -0
- data/lib/active_merchant/billing/gateways/inspire.rb +213 -0
- data/lib/active_merchant/billing/gateways/instapay.rb +163 -0
- data/lib/active_merchant/billing/gateways/iridium.rb +457 -0
- data/lib/active_merchant/billing/gateways/itransact.rb +448 -0
- data/lib/active_merchant/billing/gateways/jetpay.rb +275 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +438 -0
- data/lib/active_merchant/billing/gateways/litle.rb +346 -0
- data/lib/active_merchant/billing/gateways/maxipago.rb +197 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +170 -0
- data/lib/active_merchant/billing/gateways/merchant_one.rb +114 -0
- data/lib/active_merchant/billing/gateways/merchant_ware.rb +319 -0
- data/lib/active_merchant/billing/gateways/merchant_ware_version_four.rb +268 -0
- data/lib/active_merchant/billing/gateways/merchant_warrior.rb +195 -0
- data/lib/active_merchant/billing/gateways/mercury.rb +333 -0
- data/lib/active_merchant/billing/gateways/metrics_global.rb +303 -0
- data/lib/active_merchant/billing/gateways/migs.rb +265 -0
- data/lib/active_merchant/billing/gateways/migs/migs_codes.rb +100 -0
- data/lib/active_merchant/billing/gateways/modern_payments.rb +37 -0
- data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +219 -0
- data/lib/active_merchant/billing/gateways/moneris.rb +309 -0
- data/lib/active_merchant/billing/gateways/moneris_us.rb +291 -0
- data/lib/active_merchant/billing/gateways/money_movers.rb +152 -0
- data/lib/active_merchant/billing/gateways/nab_transact.rb +280 -0
- data/lib/active_merchant/billing/gateways/net_registry.rb +198 -0
- data/lib/active_merchant/billing/gateways/netaxept.rb +181 -0
- data/lib/active_merchant/billing/gateways/netbilling.rb +190 -0
- data/lib/active_merchant/billing/gateways/netpay.rb +223 -0
- data/lib/active_merchant/billing/gateways/network_merchants.rb +242 -0
- data/lib/active_merchant/billing/gateways/nmi.rb +256 -0
- data/lib/active_merchant/billing/gateways/ogone.rb +435 -0
- data/lib/active_merchant/billing/gateways/openpay.rb +194 -0
- data/lib/active_merchant/billing/gateways/optimal_payment.rb +313 -0
- data/lib/active_merchant/billing/gateways/orbital.rb +803 -0
- data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +47 -0
- data/lib/active_merchant/billing/gateways/pac_net_raven.rb +207 -0
- data/lib/active_merchant/billing/gateways/pago_facil.rb +122 -0
- data/lib/active_merchant/billing/gateways/pay_gate_xml.rb +261 -0
- data/lib/active_merchant/billing/gateways/pay_junction.rb +390 -0
- data/lib/active_merchant/billing/gateways/pay_secure.rb +112 -0
- data/lib/active_merchant/billing/gateways/pay_u_latam.rb +462 -0
- data/lib/active_merchant/billing/gateways/paybox_direct.rb +188 -0
- data/lib/active_merchant/billing/gateways/payex.rb +412 -0
- data/lib/active_merchant/billing/gateways/payflow.rb +304 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +209 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
- data/lib/active_merchant/billing/gateways/payflow_express.rb +224 -0
- data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
- data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
- data/lib/active_merchant/billing/gateways/payment_express.rb +353 -0
- data/lib/active_merchant/billing/gateways/paymill.rb +281 -0
- data/lib/active_merchant/billing/gateways/paypal.rb +117 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +670 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +65 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_recurring_api.rb +262 -0
- data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
- data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +44 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +264 -0
- data/lib/active_merchant/billing/gateways/paypal_express_common.rb +30 -0
- data/lib/active_merchant/billing/gateways/payscout.rb +162 -0
- data/lib/active_merchant/billing/gateways/paystation.rb +199 -0
- data/lib/active_merchant/billing/gateways/payway.rb +207 -0
- data/lib/active_merchant/billing/gateways/pin.rb +197 -0
- data/lib/active_merchant/billing/gateways/plugnpay.rb +283 -0
- data/lib/active_merchant/billing/gateways/psigate.rb +216 -0
- data/lib/active_merchant/billing/gateways/psl_card.rb +303 -0
- data/lib/active_merchant/billing/gateways/qbms.rb +292 -0
- data/lib/active_merchant/billing/gateways/quantum.rb +276 -0
- data/lib/active_merchant/billing/gateways/quickpay.rb +367 -0
- data/lib/active_merchant/billing/gateways/realex.rb +298 -0
- data/lib/active_merchant/billing/gateways/redsys.rb +391 -0
- data/lib/active_merchant/billing/gateways/sage.rb +175 -0
- data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +87 -0
- data/lib/active_merchant/billing/gateways/sage/sage_core.rb +114 -0
- data/lib/active_merchant/billing/gateways/sage/sage_vault.rb +149 -0
- data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +102 -0
- data/lib/active_merchant/billing/gateways/sage_pay.rb +398 -0
- data/lib/active_merchant/billing/gateways/sallie_mae.rb +143 -0
- data/lib/active_merchant/billing/gateways/secure_net.rb +252 -0
- data/lib/active_merchant/billing/gateways/secure_pay.rb +201 -0
- data/lib/active_merchant/billing/gateways/secure_pay_au.rb +281 -0
- data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +105 -0
- data/lib/active_merchant/billing/gateways/skip_jack.rb +452 -0
- data/lib/active_merchant/billing/gateways/smart_ps.rb +283 -0
- data/lib/active_merchant/billing/gateways/so_easy_pay.rb +194 -0
- data/lib/active_merchant/billing/gateways/spreedly_core.rb +247 -0
- data/lib/active_merchant/billing/gateways/stripe.rb +411 -0
- data/lib/active_merchant/billing/gateways/swipe_checkout.rb +157 -0
- data/lib/active_merchant/billing/gateways/tns.rb +227 -0
- data/lib/active_merchant/billing/gateways/trans_first.rb +126 -0
- data/lib/active_merchant/billing/gateways/transax.rb +23 -0
- data/lib/active_merchant/billing/gateways/transnational.rb +10 -0
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +416 -0
- data/lib/active_merchant/billing/gateways/usa_epay.rb +25 -0
- data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1516 -0
- data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +254 -0
- data/lib/active_merchant/billing/gateways/verifi.rb +225 -0
- data/lib/active_merchant/billing/gateways/viaklix.rb +183 -0
- data/lib/active_merchant/billing/gateways/vindicia.rb +385 -0
- data/lib/active_merchant/billing/gateways/webpay.rb +97 -0
- data/lib/active_merchant/billing/gateways/wepay.rb +189 -0
- data/lib/active_merchant/billing/gateways/wirecard.rb +421 -0
- data/lib/active_merchant/billing/gateways/worldpay.rb +331 -0
- data/lib/active_merchant/billing/gateways/worldpay_us.rb +181 -0
- data/lib/active_merchant/billing/model.rb +30 -0
- data/lib/active_merchant/billing/payment_token.rb +21 -0
- data/lib/active_merchant/billing/rails.rb +3 -0
- data/lib/active_merchant/billing/response.rb +91 -0
- data/lib/active_merchant/country.rb +332 -0
- data/lib/active_merchant/empty.rb +20 -0
- data/lib/active_merchant/errors.rb +29 -0
- data/lib/active_merchant/offsite_payments_shim.rb +19 -0
- data/lib/active_merchant/version.rb +3 -0
- data/lib/activemerchant.rb +1 -0
- data/lib/support/gateway_support.rb +71 -0
- data/lib/support/outbound_hosts.rb +25 -0
- data/lib/support/ssl_verify.rb +93 -0
- metadata +400 -0
@@ -0,0 +1,281 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
module ActiveMerchant #:nodoc:
|
4
|
+
module Billing #:nodoc:
|
5
|
+
class SecurePayAuGateway < Gateway
|
6
|
+
API_VERSION = 'xml-4.2'
|
7
|
+
PERIODIC_API_VERSION = 'spxml-3.0'
|
8
|
+
|
9
|
+
class_attribute :test_periodic_url, :live_periodic_url
|
10
|
+
|
11
|
+
self.test_url = 'https://www.securepay.com.au/test/payment'
|
12
|
+
self.live_url = 'https://www.securepay.com.au/xmlapi/payment'
|
13
|
+
|
14
|
+
self.test_periodic_url = 'https://test.securepay.com.au/xmlapi/periodic'
|
15
|
+
self.live_periodic_url = 'https://api.securepay.com.au/xmlapi/periodic'
|
16
|
+
|
17
|
+
self.supported_countries = ['AU']
|
18
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :jcb]
|
19
|
+
|
20
|
+
# The homepage URL of the gateway
|
21
|
+
self.homepage_url = 'http://securepay.com.au'
|
22
|
+
|
23
|
+
# The name of the gateway
|
24
|
+
self.display_name = 'SecurePay'
|
25
|
+
|
26
|
+
class_attribute :request_timeout
|
27
|
+
self.request_timeout = 60
|
28
|
+
|
29
|
+
self.money_format = :cents
|
30
|
+
self.default_currency = 'AUD'
|
31
|
+
|
32
|
+
# 0 Standard Payment
|
33
|
+
# 4 Refund
|
34
|
+
# 6 Client Reversal (Void)
|
35
|
+
# 10 Preauthorise
|
36
|
+
# 11 Preauth Complete (Advice)
|
37
|
+
TRANSACTIONS = {
|
38
|
+
:purchase => 0,
|
39
|
+
:authorization => 10,
|
40
|
+
:capture => 11,
|
41
|
+
:void => 6,
|
42
|
+
:refund => 4
|
43
|
+
}
|
44
|
+
|
45
|
+
PERIODIC_ACTIONS = {
|
46
|
+
:add_triggered => "add",
|
47
|
+
:remove_triggered => "delete",
|
48
|
+
:trigger => "trigger"
|
49
|
+
}
|
50
|
+
|
51
|
+
PERIODIC_TYPES = {
|
52
|
+
:add_triggered => 4,
|
53
|
+
:remove_triggered => nil,
|
54
|
+
:trigger => nil
|
55
|
+
}
|
56
|
+
|
57
|
+
SUCCESS_CODES = [ '00', '08', '11', '16', '77' ]
|
58
|
+
|
59
|
+
def initialize(options = {})
|
60
|
+
requires!(options, :login, :password)
|
61
|
+
super
|
62
|
+
end
|
63
|
+
|
64
|
+
def purchase(money, credit_card_or_stored_id, options = {})
|
65
|
+
if credit_card_or_stored_id.respond_to?(:number)
|
66
|
+
requires!(options, :order_id)
|
67
|
+
commit :purchase, build_purchase_request(money, credit_card_or_stored_id, options)
|
68
|
+
else
|
69
|
+
options[:billing_id] = credit_card_or_stored_id.to_s
|
70
|
+
commit_periodic(build_periodic_item(:trigger, money, nil, options))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def authorize(money, credit_card, options = {})
|
75
|
+
requires!(options, :order_id)
|
76
|
+
commit :authorization, build_purchase_request(money, credit_card, options)
|
77
|
+
end
|
78
|
+
|
79
|
+
def capture(money, reference, options = {})
|
80
|
+
commit :capture, build_reference_request(money, reference)
|
81
|
+
end
|
82
|
+
|
83
|
+
def refund(money, reference, options = {})
|
84
|
+
commit :refund, build_reference_request(money, reference)
|
85
|
+
end
|
86
|
+
|
87
|
+
def credit(money, reference, options = {})
|
88
|
+
ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
|
89
|
+
refund(money, reference)
|
90
|
+
end
|
91
|
+
|
92
|
+
def void(reference, options = {})
|
93
|
+
commit :void, build_reference_request(nil, reference)
|
94
|
+
end
|
95
|
+
|
96
|
+
def store(creditcard, options = {})
|
97
|
+
requires!(options, :billing_id, :amount)
|
98
|
+
commit_periodic(build_periodic_item(:add_triggered, options[:amount], creditcard, options))
|
99
|
+
end
|
100
|
+
|
101
|
+
def unstore(identification, options = {})
|
102
|
+
options[:billing_id] = identification
|
103
|
+
commit_periodic(build_periodic_item(:remove_triggered, options[:amount], nil, options))
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def build_purchase_request(money, credit_card, options)
|
109
|
+
xml = Builder::XmlMarkup.new
|
110
|
+
|
111
|
+
currency = options[:currency] || currency(money)
|
112
|
+
|
113
|
+
xml.tag! 'amount', localized_amount(money, currency)
|
114
|
+
xml.tag! 'currency', currency
|
115
|
+
xml.tag! 'purchaseOrderNo', options[:order_id].to_s.gsub(/[ ']/, '')
|
116
|
+
|
117
|
+
xml.tag! 'CreditCardInfo' do
|
118
|
+
xml.tag! 'cardNumber', credit_card.number
|
119
|
+
xml.tag! 'expiryDate', expdate(credit_card)
|
120
|
+
xml.tag! 'cvv', credit_card.verification_value if credit_card.verification_value?
|
121
|
+
end
|
122
|
+
|
123
|
+
xml.target!
|
124
|
+
end
|
125
|
+
|
126
|
+
def build_reference_request(money, reference)
|
127
|
+
xml = Builder::XmlMarkup.new
|
128
|
+
|
129
|
+
transaction_id, order_id, preauth_id, original_amount = reference.split('*')
|
130
|
+
|
131
|
+
xml.tag! 'amount', (money ? amount(money) : original_amount)
|
132
|
+
xml.tag! 'currency', options[:currency] || currency(money)
|
133
|
+
xml.tag! 'txnID', transaction_id
|
134
|
+
xml.tag! 'purchaseOrderNo', order_id
|
135
|
+
xml.tag! 'preauthID', preauth_id
|
136
|
+
|
137
|
+
xml.target!
|
138
|
+
end
|
139
|
+
|
140
|
+
def build_request(action, body)
|
141
|
+
xml = Builder::XmlMarkup.new
|
142
|
+
xml.instruct!
|
143
|
+
xml.tag! 'SecurePayMessage' do
|
144
|
+
xml.tag! 'MessageInfo' do
|
145
|
+
xml.tag! 'messageID', SecureRandom.hex(15)
|
146
|
+
xml.tag! 'messageTimestamp', generate_timestamp
|
147
|
+
xml.tag! 'timeoutValue', request_timeout
|
148
|
+
xml.tag! 'apiVersion', API_VERSION
|
149
|
+
end
|
150
|
+
|
151
|
+
xml.tag! 'MerchantInfo' do
|
152
|
+
xml.tag! 'merchantID', @options[:login]
|
153
|
+
xml.tag! 'password', @options[:password]
|
154
|
+
end
|
155
|
+
|
156
|
+
xml.tag! 'RequestType', 'Payment'
|
157
|
+
xml.tag! 'Payment' do
|
158
|
+
xml.tag! 'TxnList', "count" => 1 do
|
159
|
+
xml.tag! 'Txn', "ID" => 1 do
|
160
|
+
xml.tag! 'txnType', TRANSACTIONS[action]
|
161
|
+
xml.tag! 'txnSource', 23
|
162
|
+
xml << body
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
xml.target!
|
169
|
+
end
|
170
|
+
|
171
|
+
def commit(action, request)
|
172
|
+
response = parse(ssl_post(test? ? self.test_url : self.live_url, build_request(action, request)))
|
173
|
+
|
174
|
+
Response.new(success?(response), message_from(response), response,
|
175
|
+
:test => test?,
|
176
|
+
:authorization => authorization_from(response)
|
177
|
+
)
|
178
|
+
end
|
179
|
+
|
180
|
+
def build_periodic_item(action, money, credit_card, options)
|
181
|
+
xml = Builder::XmlMarkup.new
|
182
|
+
|
183
|
+
xml.tag! 'actionType', PERIODIC_ACTIONS[action]
|
184
|
+
xml.tag! 'clientID', options[:billing_id].to_s
|
185
|
+
|
186
|
+
if credit_card
|
187
|
+
xml.tag! 'CreditCardInfo' do
|
188
|
+
xml.tag! 'cardNumber', credit_card.number
|
189
|
+
xml.tag! 'expiryDate', expdate(credit_card)
|
190
|
+
xml.tag! 'cvv', credit_card.verification_value if credit_card.verification_value?
|
191
|
+
end
|
192
|
+
end
|
193
|
+
xml.tag! 'amount', amount(money)
|
194
|
+
xml.tag! 'periodicType', PERIODIC_TYPES[action] if PERIODIC_TYPES[action]
|
195
|
+
|
196
|
+
xml.target!
|
197
|
+
end
|
198
|
+
|
199
|
+
def build_periodic_request(body)
|
200
|
+
xml = Builder::XmlMarkup.new
|
201
|
+
xml.instruct!
|
202
|
+
xml.tag! 'SecurePayMessage' do
|
203
|
+
xml.tag! 'MessageInfo' do
|
204
|
+
xml.tag! 'messageID', SecureRandom.hex(15)
|
205
|
+
xml.tag! 'messageTimestamp', generate_timestamp
|
206
|
+
xml.tag! 'timeoutValue', request_timeout
|
207
|
+
xml.tag! 'apiVersion', PERIODIC_API_VERSION
|
208
|
+
end
|
209
|
+
|
210
|
+
xml.tag! 'MerchantInfo' do
|
211
|
+
xml.tag! 'merchantID', @options[:login]
|
212
|
+
xml.tag! 'password', @options[:password]
|
213
|
+
end
|
214
|
+
|
215
|
+
xml.tag! 'RequestType', 'Periodic'
|
216
|
+
xml.tag! 'Periodic' do
|
217
|
+
xml.tag! 'PeriodicList', "count" => 1 do
|
218
|
+
xml.tag! 'PeriodicItem', "ID" => 1 do
|
219
|
+
xml << body
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
xml.target!
|
225
|
+
end
|
226
|
+
|
227
|
+
def commit_periodic(request)
|
228
|
+
my_request = build_periodic_request(request)
|
229
|
+
#puts my_request
|
230
|
+
response = parse(ssl_post(test? ? self.test_periodic_url : self.live_periodic_url, my_request))
|
231
|
+
|
232
|
+
Response.new(success?(response), message_from(response), response,
|
233
|
+
:test => test?,
|
234
|
+
:authorization => authorization_from(response)
|
235
|
+
)
|
236
|
+
end
|
237
|
+
|
238
|
+
def success?(response)
|
239
|
+
SUCCESS_CODES.include?(response[:response_code])
|
240
|
+
end
|
241
|
+
|
242
|
+
def authorization_from(response)
|
243
|
+
[response[:txn_id], response[:purchase_order_no], response[:preauth_id], response[:amount]].join('*')
|
244
|
+
end
|
245
|
+
|
246
|
+
def message_from(response)
|
247
|
+
response[:response_text] || response[:status_description]
|
248
|
+
end
|
249
|
+
|
250
|
+
def expdate(credit_card)
|
251
|
+
"#{format(credit_card.month, :two_digits)}/#{format(credit_card.year, :two_digits)}"
|
252
|
+
end
|
253
|
+
|
254
|
+
def parse(body)
|
255
|
+
xml = REXML::Document.new(body)
|
256
|
+
|
257
|
+
response = {}
|
258
|
+
|
259
|
+
xml.root.elements.to_a.each do |node|
|
260
|
+
parse_element(response, node)
|
261
|
+
end
|
262
|
+
|
263
|
+
response
|
264
|
+
end
|
265
|
+
|
266
|
+
def parse_element(response, node)
|
267
|
+
if node.has_elements?
|
268
|
+
node.elements.each{|element| parse_element(response, element) }
|
269
|
+
else
|
270
|
+
response[node.name.underscore.to_sym] = node.text
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
# YYYYDDMMHHNNSSKKK000sOOO
|
275
|
+
def generate_timestamp
|
276
|
+
time = Time.now.utc
|
277
|
+
time.strftime("%Y%d%m%H%M%S#{time.usec}+000")
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class SecurePayTechGateway < Gateway
|
4
|
+
class SecurePayTechPostData < PostData
|
5
|
+
self.required_fields = [ :OrderReference, :CardNumber, :CardExpiry, :CardHolderName, :CardType, :MerchantID, :MerchantKey, :Amount, :Currency ]
|
6
|
+
end
|
7
|
+
|
8
|
+
self.live_url = self.test_url = 'https://tx.securepaytech.com/web/HttpPostPurchase'
|
9
|
+
|
10
|
+
PAYMENT_GATEWAY_RESPONSES = {
|
11
|
+
1 => "Transaction OK",
|
12
|
+
2 => "Insufficient funds",
|
13
|
+
3 => "Card expired",
|
14
|
+
4 => "Card declined",
|
15
|
+
5 => "Server error",
|
16
|
+
6 => "Communications error",
|
17
|
+
7 => "Unsupported transaction type",
|
18
|
+
8 => "Bad or malformed request",
|
19
|
+
9 => "Invalid card number"
|
20
|
+
}
|
21
|
+
|
22
|
+
self.default_currency = 'NZD'
|
23
|
+
self.supported_countries = ['NZ']
|
24
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :diners_club]
|
25
|
+
self.homepage_url = 'http://www.securepaytech.com/'
|
26
|
+
self.display_name = 'SecurePayTech'
|
27
|
+
|
28
|
+
def initialize(options = {})
|
29
|
+
requires!(options, :login, :password)
|
30
|
+
super
|
31
|
+
end
|
32
|
+
|
33
|
+
def purchase(money, creditcard, options = {})
|
34
|
+
post = SecurePayTechPostData.new
|
35
|
+
|
36
|
+
add_invoice(post, money, options)
|
37
|
+
add_creditcard(post, creditcard)
|
38
|
+
|
39
|
+
commit(:purchase, post)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def add_invoice(post, money, options)
|
45
|
+
post[:Amount] = amount(money)
|
46
|
+
post[:Currency] = options[:currency] || currency(money)
|
47
|
+
|
48
|
+
post[:OrderReference] = options[:order_id]
|
49
|
+
end
|
50
|
+
|
51
|
+
def add_creditcard(post, creditcard)
|
52
|
+
post[:CardNumber] = creditcard.number
|
53
|
+
post[:CardExpiry] = expdate(creditcard)
|
54
|
+
post[:CardHolderName] = creditcard.name
|
55
|
+
|
56
|
+
if creditcard.verification_value?
|
57
|
+
post[:EnableCSC] = true
|
58
|
+
post[:CSC] = creditcard.verification_value
|
59
|
+
end
|
60
|
+
|
61
|
+
# SPT will autodetect this
|
62
|
+
post[:CardType] = 0
|
63
|
+
end
|
64
|
+
|
65
|
+
def parse(body)
|
66
|
+
response = CGI.unescape(body).split(',')
|
67
|
+
|
68
|
+
result = {}
|
69
|
+
result[:result_code] = response[0].to_i
|
70
|
+
|
71
|
+
if response.length == 2
|
72
|
+
result[:fail_reason] = response[1]
|
73
|
+
else
|
74
|
+
result[:merchant_transaction_reference] = response[1]
|
75
|
+
result[:receipt_number] = response[2]
|
76
|
+
result[:transaction_number] = response[3]
|
77
|
+
result[:authorisation_id] = response[4]
|
78
|
+
result[:batch_number] = response[5]
|
79
|
+
end
|
80
|
+
|
81
|
+
result
|
82
|
+
end
|
83
|
+
|
84
|
+
def commit(action, post)
|
85
|
+
response = parse( ssl_post(self.live_url, post_data(action, post) ) )
|
86
|
+
|
87
|
+
Response.new(response[:result_code] == 1, message_from(response), response,
|
88
|
+
:test => test?,
|
89
|
+
:authorization => response[:merchant_transaction_reference]
|
90
|
+
)
|
91
|
+
end
|
92
|
+
|
93
|
+
def message_from(result)
|
94
|
+
PAYMENT_GATEWAY_RESPONSES[result[:result_code]]
|
95
|
+
end
|
96
|
+
|
97
|
+
def post_data(action, post)
|
98
|
+
post[:MerchantID] = @options[:login]
|
99
|
+
post[:MerchantKey] = @options[:password]
|
100
|
+
post.to_s
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
@@ -0,0 +1,452 @@
|
|
1
|
+
#!ruby19
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
module ActiveMerchant #:nodoc:
|
5
|
+
module Billing #:nodoc:
|
6
|
+
class SkipJackGateway < Gateway
|
7
|
+
API_VERSION = '?.?'
|
8
|
+
|
9
|
+
self.live_url = "https://www.skipjackic.com"
|
10
|
+
self.test_url = "https://developer.skipjackic.com"
|
11
|
+
|
12
|
+
BASIC_PATH = "/scripts/evolvcc.dll"
|
13
|
+
ADVANCED_PATH = "/evolvcc/evolvcc.aspx"
|
14
|
+
|
15
|
+
ACTIONS = {
|
16
|
+
:authorization => 'AuthorizeAPI',
|
17
|
+
:change_status => 'SJAPI_TransactionChangeStatusRequest',
|
18
|
+
:get_status => 'SJAPI_TransactionStatusRequest'
|
19
|
+
}
|
20
|
+
|
21
|
+
SUCCESS_MESSAGE = 'The transaction was successful.'
|
22
|
+
|
23
|
+
MONETARY_CHANGE_STATUSES = ['SETTLE', 'AUTHORIZE', 'AUTHORIZE ADDITIONAL', 'CREDIT', 'SPLITSETTLE']
|
24
|
+
|
25
|
+
CARD_CODE_ERRORS = %w( N S "" )
|
26
|
+
|
27
|
+
CARD_CODE_MESSAGES = {
|
28
|
+
"M" => "Card verification number matched",
|
29
|
+
"N" => "Card verification number didn't match",
|
30
|
+
"P" => "Card verification number was not processed",
|
31
|
+
"S" => "Card verification number should be on card but was not indicated",
|
32
|
+
"U" => "Issuer was not certified for card verification",
|
33
|
+
"" => "Transaction failed because incorrect card verification number was entered or no number was entered"
|
34
|
+
}
|
35
|
+
|
36
|
+
AVS_ERRORS = %w( A B C E I N O P R W Z )
|
37
|
+
|
38
|
+
AVS_MESSAGES = {
|
39
|
+
"A" => "Street address matches billing information, zip/postal code does not",
|
40
|
+
"B" => "Street address match for international transaction. Postal code not verified due to incompatible formats",
|
41
|
+
"C" => "Street address and postal code not verified for internation transaction due to incompatible formats",
|
42
|
+
"D" => "Street address and postal code match for international transaction",
|
43
|
+
"E" => "Address verification service error",
|
44
|
+
"I" => "Address information not verified by international issuer",
|
45
|
+
"M" => "Street address and postal code match for international transaction",
|
46
|
+
"N" => "Neither street address nor zip/postal match billing information",
|
47
|
+
"O" => "Non-US issuer does not participate",
|
48
|
+
"P" => "Postal codes match for international transaction but street address not verified due to incompatible formats",
|
49
|
+
"P" => "Address verification not applicable for this transaction",
|
50
|
+
"R" => "Payment gateway was unavailable or timed out",
|
51
|
+
"S" => "Address verification service not supported by issuer",
|
52
|
+
"U" => "Address information is unavailable",
|
53
|
+
"W" => "9-digit zip/postal code matches billing information, street address does not",
|
54
|
+
"X" => "Street address and 9-digit zip/postal code matches billing information",
|
55
|
+
"Y" => "Street address and 5-digit zip/postal code matches billing information",
|
56
|
+
"Z" => "5-digit zip/postal code matches billing information, street address does not",
|
57
|
+
}
|
58
|
+
|
59
|
+
CHANGE_STATUS_ERROR_MESSAGES = {
|
60
|
+
'0' => 'Success',
|
61
|
+
'-1' => 'Invalid Command',
|
62
|
+
'-2' => 'Parameter Missing',
|
63
|
+
'-3' => 'Failed retrieving response',
|
64
|
+
'-4' => 'Invalid Status',
|
65
|
+
'-5' => 'Failed reading security flags',
|
66
|
+
'-6' => 'Developer serial number not found',
|
67
|
+
'-7' => 'Invalid Serial Number'
|
68
|
+
}
|
69
|
+
|
70
|
+
TRANSACTION_CURRENT_STATUS = {
|
71
|
+
'0' => 'Idle',
|
72
|
+
'1' => 'Authorized',
|
73
|
+
'2' => 'Denied',
|
74
|
+
'3' => 'Settled',
|
75
|
+
'4' => 'Credited',
|
76
|
+
'5' => 'Deleted',
|
77
|
+
'6' => 'Archived',
|
78
|
+
'7' => 'Pre-Authorized',
|
79
|
+
'8' => 'Split Settled'
|
80
|
+
}
|
81
|
+
|
82
|
+
TRANSACTION_PENDING_STATUS = {
|
83
|
+
'0' => 'Idle',
|
84
|
+
'1' => 'Pending Credit',
|
85
|
+
'2' => 'Pending Settlement',
|
86
|
+
'3' => 'Pending Authorization',
|
87
|
+
'4' => 'Pending Manual Settlement',
|
88
|
+
'5' => 'Pending Recurring'
|
89
|
+
}
|
90
|
+
|
91
|
+
RETURN_CODE_MESSAGES = {
|
92
|
+
'-1' => 'Data was not by received intact by Skipjack Transaction Network.',
|
93
|
+
'0' => 'Communication Failure. Error in Request and Response at IP level.',
|
94
|
+
'1' => 'Valid Data. Authorization request was valid.',
|
95
|
+
'-35' => 'Invalid credit card number. Retry with correct credit card number.',
|
96
|
+
'-37' => 'Merchant Processor Unavailable. Skipjack is unable to communicate with payment Processor. Retry',
|
97
|
+
'-39' => 'Length or value of HTML Serial. Number Invalid serial number. Check HTML Serial Number length and that it is a correct/valid number. Confirm you are sending to the correct environment (Development or Production)',
|
98
|
+
'-51' => 'The value or length for billing zip code is incorrect.',
|
99
|
+
'-52' => 'The value or length for shipping zip code is incorrect.',
|
100
|
+
'-53' => 'The value or length for credit card expiration month is incorrect.',
|
101
|
+
'-54' => 'The value or length of the month or year of the credit card account number was incorrect.',
|
102
|
+
'-55' => 'The value or length or billing street address is incorrect.',
|
103
|
+
'-56' => 'The value or length of the shipping address is incorrect.',
|
104
|
+
'-57' => 'The length of the transaction amount must be at least 3 digits long (excluding the decimal place).',
|
105
|
+
'-58' => 'Length or value in Merchant Name Merchant Name associated with Skipjack account is misconfigured or invalid',
|
106
|
+
'-59' => 'Length or value in Merchant Address Merchant Address associated with Skipjack account is misconfigured or invalid',
|
107
|
+
'-60' => 'Length or value in Merchant State Merchant State associated with Skipjack account is misconfigured or invalid',
|
108
|
+
'-61' => 'The value or length for shipping state/province is empty.',
|
109
|
+
'-62' => 'The value for length orderstring is empty.',
|
110
|
+
'-64' => 'The value for the phone number is incorrect.',
|
111
|
+
'-65' => 'The value or length for billing name is empty.',
|
112
|
+
'-66' => 'The value or length for billing e-mail is empty.',
|
113
|
+
'-67' => 'The value or length for billing street address is empty.',
|
114
|
+
'-68' => 'The value or length for billing city is empty.',
|
115
|
+
'-69' => 'The value or length for billing state is empty.',
|
116
|
+
'-70' => 'Empty zipcode Zip Code field is empty.',
|
117
|
+
'-71' => 'Empty ordernumber Ordernumber field is empty.',
|
118
|
+
'-72' => 'Empty accountnumber Accountnumber field is empty',
|
119
|
+
'-73' => 'Empty month Month field is empty.',
|
120
|
+
'-74' => 'Empty year Year field is empty.',
|
121
|
+
'-75' => 'Empty serialnumber Serialnumber field is empty.',
|
122
|
+
'-76' => 'Empty transactionamount Transaction amount field is empty.',
|
123
|
+
'-77' => 'Empty orderstring Orderstring field is empty.',
|
124
|
+
'-78' => 'Empty shiptophone Shiptophone field is empty.',
|
125
|
+
'-79' => 'The value or length for billing name is empty.',
|
126
|
+
'-80' => 'Length shipto name Error in the length or value of shiptophone.',
|
127
|
+
'-81' => 'Length or value of Customer location',
|
128
|
+
'-82' => 'The value or length for billing state is empty.',
|
129
|
+
'-83' => 'The value or length for shipping phone is empty.',
|
130
|
+
'-84' => 'There is already an existing pending transaction in the register sharing the posted Order Number.',
|
131
|
+
'-85' => 'Airline leg info invalid Airline leg field value is invalid or empty.',
|
132
|
+
'-86' => 'Airline ticket info invalid Airline ticket info field is invalid or empty',
|
133
|
+
'-87' => 'Point of Sale check routing number must be 9 numeric digits Point of Sale check routing number is invalid or empty.',
|
134
|
+
'-88' => 'Point of Sale check account number missing or invalid Point of Sale check account number is invalid or empty.',
|
135
|
+
'-89' => 'Point of Sale check MICR missing or invalid Point of Sale check MICR invalid or empty.',
|
136
|
+
'-90' => 'Point of Sale check number missing or invalid Point of Sale check number invalid or empty.',
|
137
|
+
'-91' => 'CVV2 Invalid or empty "Make CVV a required field feature" enabled (New feature 01 April 2006) in the Merchant Account Setup interface but no CVV code was sent in the transaction data.',
|
138
|
+
'-92' => 'Approval Code Invalid Approval Code Invalid. Approval Code is a 6 digit code.',
|
139
|
+
'-93' => 'Blind Credits Request Refused "Allow Blind Credits" option must be enabled on the Skipjack Merchant Account.',
|
140
|
+
'-94' => 'Blind Credits Failed',
|
141
|
+
'-95' => 'Voice Authorization Request Refused Voice Authorization option must be enabled on the Skipjack Merchant Account.',
|
142
|
+
'-96' => 'Voice Authorizations Failed',
|
143
|
+
'-97' => 'Fraud Rejection Violates Velocity Settling.',
|
144
|
+
'-98' => 'Invalid Discount Amount',
|
145
|
+
'-99' => 'POS PIN Debit Pin Block Debit-specific',
|
146
|
+
'-100' => 'POS PIN Debit Invalid Key Serial Number Debit-specific',
|
147
|
+
'-101' => 'Invalid Authentication Data Data for Verified by Visa/MC Secure Code is invalid.',
|
148
|
+
'-102' => 'Authentication Data Not Allowed',
|
149
|
+
'-103' => 'POS Check Invalid Birth Date POS check dateofbirth variable contains a birth date in an incorrect format. Use MM/DD/YYYY format for this variable.',
|
150
|
+
'-104' => 'POS Check Invalid Identification Type POS check identificationtype variable contains a identification type value which is invalid. Use the single digit value where Social Security Number=1, Drivers License=2 for this variable.',
|
151
|
+
'-105' => 'Invalid trackdata Track Data is in invalid format.',
|
152
|
+
'-106' => 'POS Check Invalid Account Type',
|
153
|
+
'-107' => 'POS PIN Debit Invalid Sequence Number',
|
154
|
+
'-108' => 'Invalid Transaction ID',
|
155
|
+
'-109' => 'Invalid From Account Type',
|
156
|
+
'-110' => 'Pos Error Invalid To Account Type',
|
157
|
+
'-112' => 'Pos Error Invalid Auth Option',
|
158
|
+
'-113' => 'Pos Error Transaction Failed',
|
159
|
+
'-114' => 'Pos Error Invalid Incoming Eci',
|
160
|
+
'-115' => 'POS Check Invalid Check Type',
|
161
|
+
'-116' => 'POS Check Invalid Lane Number POS Check lane or cash register number is invalid. Use a valid lane or cash register number that has been configured in the Skipjack Merchant Account.',
|
162
|
+
'-117' => 'POS Check Invalid Cashier Number'
|
163
|
+
}
|
164
|
+
|
165
|
+
self.supported_countries = ['US', 'CA']
|
166
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :jcb, :discover, :diners_club]
|
167
|
+
self.homepage_url = 'http://www.skipjack.com/'
|
168
|
+
self.display_name = 'SkipJack'
|
169
|
+
|
170
|
+
# Creates a new SkipJackGateway
|
171
|
+
#
|
172
|
+
# The gateway requires that a valid login and password be passed
|
173
|
+
# in the +options+ hash.
|
174
|
+
#
|
175
|
+
# ==== Options
|
176
|
+
#
|
177
|
+
# * <tt>:login</tt> -- The SkipJack Merchant Serial Number.
|
178
|
+
# * <tt>:password</tt> -- The SkipJack Developer Serial Number.
|
179
|
+
# * <tt>:test => +true+ or +false+</tt> -- Use the test or live SkipJack url.
|
180
|
+
# * <tt>:advanced => +true+ or +false+</tt> -- Set to true if you're using an advanced processor
|
181
|
+
# See the SkipJack Integration Guide for details. (default: +false+)
|
182
|
+
def initialize(options = {})
|
183
|
+
requires!(options, :login, :password)
|
184
|
+
super
|
185
|
+
end
|
186
|
+
|
187
|
+
def authorize(money, creditcard, options = {})
|
188
|
+
requires!(options, :order_id, :email)
|
189
|
+
post = {}
|
190
|
+
add_invoice(post, options)
|
191
|
+
add_creditcard(post, creditcard)
|
192
|
+
add_address(post, options)
|
193
|
+
add_customer_data(post, options)
|
194
|
+
commit(:authorization, money, post)
|
195
|
+
end
|
196
|
+
|
197
|
+
def purchase(money, creditcard, options = {})
|
198
|
+
authorization = authorize(money, creditcard, options)
|
199
|
+
if authorization.success?
|
200
|
+
capture(money, authorization.authorization)
|
201
|
+
else
|
202
|
+
authorization
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
# Captures the funds from an authorized transaction.
|
207
|
+
#
|
208
|
+
# ==== Parameters
|
209
|
+
#
|
210
|
+
# * <tt>money</tt> -- The amount to be capture as an Integer in cents.
|
211
|
+
# * <tt>authorization</tt> -- The authorization returned from the previous authorize request.
|
212
|
+
# * <tt>options</tt> -- A hash of optional parameters.
|
213
|
+
#
|
214
|
+
# ==== Options
|
215
|
+
#
|
216
|
+
# * <tt>:force_settlement</tt> -- Force the settlement to occur as soon as possible. This option is not supported by other gateways. See the SkipJack API reference for more details
|
217
|
+
def capture(money, authorization, options = {})
|
218
|
+
post = { }
|
219
|
+
add_status_action(post, 'SETTLE')
|
220
|
+
add_forced_settlement(post, options)
|
221
|
+
add_transaction_id(post, authorization)
|
222
|
+
commit(:change_status, money, post)
|
223
|
+
end
|
224
|
+
|
225
|
+
def void(authorization, options = {})
|
226
|
+
post = {}
|
227
|
+
add_status_action(post, 'DELETE')
|
228
|
+
add_forced_settlement(post, options)
|
229
|
+
add_transaction_id(post, authorization)
|
230
|
+
commit(:change_status, nil, post)
|
231
|
+
end
|
232
|
+
|
233
|
+
def refund(money, identification, options = {})
|
234
|
+
post = {}
|
235
|
+
add_status_action(post, 'CREDIT')
|
236
|
+
add_forced_settlement(post, options)
|
237
|
+
add_transaction_id(post, identification)
|
238
|
+
commit(:change_status, money, post)
|
239
|
+
end
|
240
|
+
|
241
|
+
def credit(money, identification, options = {})
|
242
|
+
ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
|
243
|
+
refund(money, identification, options)
|
244
|
+
end
|
245
|
+
|
246
|
+
def status(order_id)
|
247
|
+
commit(:get_status, nil, :szOrderNumber => order_id)
|
248
|
+
end
|
249
|
+
|
250
|
+
private
|
251
|
+
|
252
|
+
def advanced?
|
253
|
+
@options[:advanced]
|
254
|
+
end
|
255
|
+
|
256
|
+
def add_forced_settlement(post, options)
|
257
|
+
post[:szForceSettlement] = options[:force_settlment] ? 1 : 0
|
258
|
+
end
|
259
|
+
|
260
|
+
def add_status_action(post, action)
|
261
|
+
post[:szDesiredStatus] = action
|
262
|
+
end
|
263
|
+
|
264
|
+
def commit(action, money, parameters)
|
265
|
+
response = parse( ssl_post( url_for(action), post_data(action, money, parameters) ), action )
|
266
|
+
|
267
|
+
# Pass along the original transaction id in the case an update transaction
|
268
|
+
Response.new(response[:success], message_from(response, action), response,
|
269
|
+
:test => test?,
|
270
|
+
:authorization => response[:szTransactionFileName] || parameters[:szTransactionId],
|
271
|
+
:avs_result => { :code => response[:szAVSResponseCode] },
|
272
|
+
:cvv_result => response[:szCVV2ResponseCode]
|
273
|
+
)
|
274
|
+
end
|
275
|
+
|
276
|
+
def url_for(action)
|
277
|
+
result = test? ? self.test_url : self.live_url
|
278
|
+
result += advanced? && action == :authorization ? ADVANCED_PATH : BASIC_PATH
|
279
|
+
result += "?#{ACTIONS[action]}"
|
280
|
+
end
|
281
|
+
|
282
|
+
def add_credentials(params, action)
|
283
|
+
if action == :authorization
|
284
|
+
params[:SerialNumber] = @options[:login]
|
285
|
+
params[:DeveloperSerialNumber] = @options[:password]
|
286
|
+
else
|
287
|
+
params[:szSerialNumber] = @options[:login]
|
288
|
+
params[:szDeveloperSerialNumber] = @options[:password]
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
def add_amount(params, action, money)
|
293
|
+
if action == :authorization
|
294
|
+
params[:TransactionAmount] = amount(money)
|
295
|
+
else
|
296
|
+
params[:szAmount] = amount(money) if MONETARY_CHANGE_STATUSES.include?(params[:szDesiredStatus])
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
def parse(body, action)
|
301
|
+
case action
|
302
|
+
when :authorization
|
303
|
+
parse_authorization_response(body)
|
304
|
+
when :get_status
|
305
|
+
parse_status_response(body, [ :SerialNumber, :TransactionAmount, :TransactionStatusCode, :TransactionStatusMessage, :OrderNumber, :TransactionDateTime, :TransactionID, :ApprovalCode, :BatchNumber ])
|
306
|
+
else
|
307
|
+
parse_status_response(body, [ :SerialNumber, :TransactionAmount, :DesiredStatus, :StatusResponse, :StatusResponseMessage, :OrderNumber, :AuditID ])
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
def split_lines(body)
|
312
|
+
body.split(/[\r\n]+/)
|
313
|
+
end
|
314
|
+
|
315
|
+
def split_line(line)
|
316
|
+
line.split(/","/).collect { |key| key.sub(/"*([^"]*)"*/, '\1').strip; }
|
317
|
+
end
|
318
|
+
|
319
|
+
def authorize_response_map(body)
|
320
|
+
lines = split_lines(body)
|
321
|
+
keys, values = split_line(lines[0]), split_line(lines[1])
|
322
|
+
Hash[*(keys.zip(values).flatten)].symbolize_keys
|
323
|
+
end
|
324
|
+
|
325
|
+
def parse_authorization_response(body)
|
326
|
+
result = authorize_response_map(body)
|
327
|
+
result[:success] = (result[:szIsApproved] == '1')
|
328
|
+
result
|
329
|
+
end
|
330
|
+
|
331
|
+
def parse_status_response(body, response_keys)
|
332
|
+
lines = split_lines(body)
|
333
|
+
|
334
|
+
keys = [ :szSerialNumber, :szErrorCode, :szNumberRecords]
|
335
|
+
values = split_line(lines[0])[0..2]
|
336
|
+
|
337
|
+
result = Hash[*(keys.zip(values).flatten)]
|
338
|
+
|
339
|
+
result[:szErrorMessage] = ''
|
340
|
+
result[:success] = (result[:szErrorCode] == '0')
|
341
|
+
|
342
|
+
if result[:success]
|
343
|
+
lines[1..-1].each do |line|
|
344
|
+
values = split_line(line)
|
345
|
+
response_keys.each_with_index do |key, index|
|
346
|
+
result[key] = values[index]
|
347
|
+
end
|
348
|
+
end
|
349
|
+
else
|
350
|
+
result[:szErrorMessage] = lines[1]
|
351
|
+
end
|
352
|
+
result
|
353
|
+
end
|
354
|
+
|
355
|
+
def post_data(action, money, params = {})
|
356
|
+
add_credentials(params, action)
|
357
|
+
add_amount(params, action, money)
|
358
|
+
sorted_params = params.to_a.sort{|a,b| a.to_s <=> b.to_s}.reverse
|
359
|
+
sorted_params.collect { |key, value| "#{key.to_s}=#{CGI.escape(value.to_s)}" }.join("&")
|
360
|
+
end
|
361
|
+
|
362
|
+
def add_transaction_id(post, transaction_id)
|
363
|
+
post[:szTransactionId] = transaction_id
|
364
|
+
end
|
365
|
+
|
366
|
+
def add_invoice(post, options)
|
367
|
+
post[:OrderNumber] = sanitize_order_id(options[:order_id])
|
368
|
+
post[:CustomerCode] = options[:customer].to_s.slice(0, 17)
|
369
|
+
post[:InvoiceNumber] = options[:invoice]
|
370
|
+
post[:OrderDescription] = options[:description]
|
371
|
+
|
372
|
+
if order_items = options[:items]
|
373
|
+
post[:OrderString] = order_items.collect { |item| "#{item[:sku]}~#{item[:description].tr('~','-')}~#{item[:declared_value]}~#{item[:quantity]}~#{item[:taxable]}~~~~~~~~#{item[:tax_rate]}~||"}.join
|
374
|
+
else
|
375
|
+
post[:OrderString] = '1~None~0.00~0~N~||'
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
def add_creditcard(post, creditcard)
|
380
|
+
post[:AccountNumber] = creditcard.number
|
381
|
+
post[:Month] = creditcard.month
|
382
|
+
post[:Year] = creditcard.year
|
383
|
+
post[:CVV2] = creditcard.verification_value if creditcard.verification_value?
|
384
|
+
post[:SJName] = creditcard.name
|
385
|
+
end
|
386
|
+
|
387
|
+
def add_customer_data(post, options)
|
388
|
+
post[:Email] = options[:email]
|
389
|
+
end
|
390
|
+
|
391
|
+
def add_address(post, options)
|
392
|
+
if address = options[:billing_address] || options[:address]
|
393
|
+
post[:StreetAddress] = address[:address1]
|
394
|
+
post[:StreetAddress2] = address[:address2]
|
395
|
+
post[:City] = address[:city]
|
396
|
+
post[:State] = address[:state] || 'XX'
|
397
|
+
post[:ZipCode] = address[:zip]
|
398
|
+
post[:Country] = address[:country]
|
399
|
+
post[:Phone] = address[:phone]
|
400
|
+
post[:Fax] = address[:fax]
|
401
|
+
end
|
402
|
+
|
403
|
+
if address = options[:shipping_address]
|
404
|
+
post[:ShipToName] = address[:name]
|
405
|
+
post[:ShipToStreetAddress] = address[:address1]
|
406
|
+
post[:ShipToStreetAddress2] = address[:address2]
|
407
|
+
post[:ShipToCity] = address[:city]
|
408
|
+
post[:ShipToState] = address[:state] || 'XX'
|
409
|
+
post[:ShipToZipCode] = address[:zip]
|
410
|
+
post[:ShipToCountry] = address[:country]
|
411
|
+
post[:ShipToPhone] = address[:phone]
|
412
|
+
post[:ShipToFax] = address[:fax]
|
413
|
+
end
|
414
|
+
|
415
|
+
# The phone number for the shipping address is required
|
416
|
+
# Use the billing address phone number if a shipping address
|
417
|
+
# phone number wasn't provided
|
418
|
+
post[:ShipToPhone] = post[:Phone] if post[:ShipToPhone].blank?
|
419
|
+
end
|
420
|
+
|
421
|
+
def message_from(response, action)
|
422
|
+
case action
|
423
|
+
when :authorization
|
424
|
+
message_from_authorization(response)
|
425
|
+
when :get_status
|
426
|
+
message_from_status(response)
|
427
|
+
else
|
428
|
+
message_from_status(response)
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
432
|
+
def message_from_authorization(response)
|
433
|
+
if response[:success]
|
434
|
+
return SUCCESS_MESSAGE
|
435
|
+
else
|
436
|
+
return CARD_CODE_MESSAGES[response[:szCVV2ResponseCode]] if CARD_CODE_ERRORS.include?(response[:szCVV2ResponseCode])
|
437
|
+
return AVS_MESSAGES[response[:szAVSResponseMessage]] if AVS_ERRORS.include?(response[:szAVSResponseCode])
|
438
|
+
return RETURN_CODE_MESSAGES[response[:szReturnCode]] if response[:szReturnCode] != '1'
|
439
|
+
return response[:szAuthorizationDeclinedMessage]
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
def message_from_status(response)
|
444
|
+
response[:success] ? SUCCESS_MESSAGE : response[:szErrorMessage]
|
445
|
+
end
|
446
|
+
|
447
|
+
def sanitize_order_id(value)
|
448
|
+
value.to_s.gsub(/[^\w.]/, '')
|
449
|
+
end
|
450
|
+
end
|
451
|
+
end
|
452
|
+
end
|