maedana-activemerchant 1.9.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +571 -0
- data/CONTRIBUTORS +170 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +150 -0
- data/gem-public_cert.pem +20 -0
- data/lib/active_merchant.rb +49 -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 +161 -0
- data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
- data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
- data/lib/active_merchant/billing/cvv_result.rb +38 -0
- data/lib/active_merchant/billing/expiry_date.rb +34 -0
- data/lib/active_merchant/billing/gateway.rb +169 -0
- data/lib/active_merchant/billing/gateways.rb +18 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +654 -0
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +736 -0
- data/lib/active_merchant/billing/gateways/beanstream.rb +102 -0
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +244 -0
- data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
- data/lib/active_merchant/billing/gateways/bogus.rb +102 -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 +210 -0
- data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
- data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +406 -0
- data/lib/active_merchant/billing/gateways/data_cash.rb +593 -0
- data/lib/active_merchant/billing/gateways/efsnet.rb +229 -0
- data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
- data/lib/active_merchant/billing/gateways/eway.rb +277 -0
- data/lib/active_merchant/billing/gateways/exact.rb +222 -0
- data/lib/active_merchant/billing/gateways/first_pay.rb +172 -0
- data/lib/active_merchant/billing/gateways/garanti.rb +222 -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 +253 -0
- data/lib/active_merchant/billing/gateways/jetpay.rb +270 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +449 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +154 -0
- data/lib/active_merchant/billing/gateways/merchant_ware.rb +283 -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 +205 -0
- data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
- data/lib/active_merchant/billing/gateways/netaxept.rb +234 -0
- data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
- data/lib/active_merchant/billing/gateways/ogone.rb +279 -0
- data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
- data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
- data/lib/active_merchant/billing/gateways/paybox_direct.rb +203 -0
- data/lib/active_merchant/billing/gateways/payflow.rb +236 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
- data/lib/active_merchant/billing/gateways/payflow_express.rb +138 -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 +230 -0
- data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +326 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +38 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_payment_details_response.rb +70 -0
- data/lib/active_merchant/billing/gateways/paypal_adaptive_payments.rb +298 -0
- data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +145 -0
- data/lib/active_merchant/billing/gateways/paypal_express_common.rb +20 -0
- data/lib/active_merchant/billing/gateways/paypal_express_recurring.rb +310 -0
- data/lib/active_merchant/billing/gateways/plugnpay.rb +292 -0
- data/lib/active_merchant/billing/gateways/psigate.rb +214 -0
- data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
- data/lib/active_merchant/billing/gateways/quickpay.rb +213 -0
- data/lib/active_merchant/billing/gateways/realex.rb +200 -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 +315 -0
- data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
- data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
- data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
- data/lib/active_merchant/billing/gateways/secure_pay_au.rb +157 -0
- data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
- data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
- data/lib/active_merchant/billing/gateways/smart_ps.rb +265 -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 +418 -0
- data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
- data/lib/active_merchant/billing/gateways/verifi.rb +228 -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/integrations.rb +17 -0
- data/lib/active_merchant/billing/integrations/action_view_helper.rb +68 -0
- data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
- data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
- data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
- data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
- data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
- data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
- data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
- data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +188 -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/gestpay.rb +25 -0
- data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
- data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
- data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
- data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/helper.rb +96 -0
- data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
- data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
- data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
- data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
- data/lib/active_merchant/billing/integrations/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/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 +17 -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 +37 -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 +109 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +204 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +27 -0
- data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
- data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
- data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
- data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
- data/lib/active_merchant/billing/response.rb +32 -0
- data/lib/active_merchant/common.rb +14 -0
- data/lib/active_merchant/common/connection.rb +172 -0
- data/lib/active_merchant/common/country.rb +328 -0
- data/lib/active_merchant/common/error.rb +26 -0
- data/lib/active_merchant/common/post_data.rb +24 -0
- data/lib/active_merchant/common/posts_data.rb +47 -0
- data/lib/active_merchant/common/requires_parameters.rb +16 -0
- data/lib/active_merchant/common/utils.rb +18 -0
- data/lib/active_merchant/common/validateable.rb +76 -0
- data/lib/active_merchant/version.rb +3 -0
- data/lib/certs/cacert.pem +7815 -0
- data/lib/maedana-activemerchant.rb +1 -0
- data/lib/support/gateway_support.rb +58 -0
- data/lib/support/outbound_hosts.rb +25 -0
- metadata +270 -0
@@ -0,0 +1,234 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
|
3
|
+
module ActiveMerchant #:nodoc:
|
4
|
+
module Billing #:nodoc:
|
5
|
+
class NetaxeptGateway < Gateway
|
6
|
+
TEST_URL = 'https://epayment-test.bbs.no/'
|
7
|
+
LIVE_URL = 'https://epayment.bbs.no/'
|
8
|
+
|
9
|
+
# The countries the gateway supports merchants from as 2 digit ISO country codes
|
10
|
+
self.supported_countries = ['NO', 'DK', 'SE', 'FI']
|
11
|
+
|
12
|
+
# The card types supported by the payment gateway
|
13
|
+
self.supported_cardtypes = [:visa, :master, :american_express]
|
14
|
+
|
15
|
+
# The homepage URL of the gateway
|
16
|
+
self.homepage_url = 'http://www.betalingsterminal.no/Netthandel-forside/'
|
17
|
+
|
18
|
+
# The name of the gateway
|
19
|
+
self.display_name = 'BBS Netaxept'
|
20
|
+
|
21
|
+
self.money_format = :cents
|
22
|
+
|
23
|
+
self.default_currency = 'NOK'
|
24
|
+
|
25
|
+
def initialize(options = {})
|
26
|
+
requires!(options, :login, :password)
|
27
|
+
@options = options
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
31
|
+
def purchase(money, creditcard, options = {})
|
32
|
+
requires!(options, :order_id)
|
33
|
+
|
34
|
+
post = {}
|
35
|
+
add_credentials(post, options)
|
36
|
+
add_transaction(post, options)
|
37
|
+
add_order(post, money, options)
|
38
|
+
add_creditcard(post, creditcard)
|
39
|
+
commit('Sale', post)
|
40
|
+
end
|
41
|
+
|
42
|
+
def authorize(money, creditcard, options = {})
|
43
|
+
requires!(options, :order_id)
|
44
|
+
|
45
|
+
post = {}
|
46
|
+
add_credentials(post, options)
|
47
|
+
add_transaction(post, options)
|
48
|
+
add_order(post, money, options)
|
49
|
+
add_creditcard(post, creditcard)
|
50
|
+
commit('Auth', post)
|
51
|
+
end
|
52
|
+
|
53
|
+
def capture(money, authorization, options = {})
|
54
|
+
post = {}
|
55
|
+
add_credentials(post, options)
|
56
|
+
add_authorization(post, authorization, money)
|
57
|
+
commit('Capture', post, false)
|
58
|
+
end
|
59
|
+
|
60
|
+
def credit(money, authorization, options = {})
|
61
|
+
post = {}
|
62
|
+
add_credentials(post, options)
|
63
|
+
add_authorization(post, authorization, money)
|
64
|
+
commit('Credit', post, false)
|
65
|
+
end
|
66
|
+
|
67
|
+
def void(authorization, options = {})
|
68
|
+
post = {}
|
69
|
+
add_credentials(post, options)
|
70
|
+
add_authorization(post, authorization)
|
71
|
+
commit('Annul', post, false)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test?
|
75
|
+
@options[:test] || Base.gateway_mode == :test
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def add_credentials(post, options)
|
82
|
+
post[:merchantId] = @options[:login]
|
83
|
+
post[:token] = @options[:password]
|
84
|
+
end
|
85
|
+
|
86
|
+
def add_authorization(post, authorization, money=nil)
|
87
|
+
post[:transactionId] = authorization
|
88
|
+
post[:transactionAmount] = amount(money) if money
|
89
|
+
end
|
90
|
+
|
91
|
+
def add_transaction(post, options)
|
92
|
+
post[:transactionId] = generate_transaction_id(options)
|
93
|
+
post[:serviceType] = 'C'
|
94
|
+
post[:redirectUrl] = 'http://example.com'
|
95
|
+
end
|
96
|
+
|
97
|
+
def add_order(post, money, options)
|
98
|
+
post[:orderNumber] = options[:order_id]
|
99
|
+
post[:amount] = amount(money)
|
100
|
+
post[:currencyCode] = (options[:currency] || currency(money))
|
101
|
+
end
|
102
|
+
|
103
|
+
CARD_TYPE_PREFIXES = {
|
104
|
+
'visa' => 'v',
|
105
|
+
'master' => 'm',
|
106
|
+
'american_express' => 'a',
|
107
|
+
}
|
108
|
+
def add_creditcard(post, creditcard)
|
109
|
+
brand = Gateway.card_brand(creditcard)
|
110
|
+
prefix = CARD_TYPE_PREFIXES[brand]
|
111
|
+
unless prefix
|
112
|
+
raise ArgumentError.new("Card type #{brand} not supported.")
|
113
|
+
end
|
114
|
+
|
115
|
+
post[:creditcard] = {}
|
116
|
+
post[:creditcard][:"#{prefix}a"] = creditcard.number
|
117
|
+
post[:creditcard][:"#{prefix}m"] = format(creditcard.month, :two_digits)
|
118
|
+
post[:creditcard][:"#{prefix}y"] = format(creditcard.year, :two_digits)
|
119
|
+
post[:creditcard][:"#{prefix}c"] = creditcard.verification_value
|
120
|
+
end
|
121
|
+
|
122
|
+
def commit(action, parameters, setup=true)
|
123
|
+
parameters[:action] = action
|
124
|
+
|
125
|
+
response = {:success => false}
|
126
|
+
|
127
|
+
catch(:exception) do
|
128
|
+
if setup
|
129
|
+
commit_transaction_setup(response, parameters)
|
130
|
+
commit_payment_details(response, parameters)
|
131
|
+
commit_process_setup(response, parameters)
|
132
|
+
end
|
133
|
+
commit_transaction(response, parameters)
|
134
|
+
response[:success] = true
|
135
|
+
end
|
136
|
+
|
137
|
+
Response.new(response[:success], response[:message], response, :test => test?, :authorization => response[:authorization])
|
138
|
+
end
|
139
|
+
|
140
|
+
def commit_transaction_setup(response, parameters)
|
141
|
+
response[:setup] = parse(ssl_get(build_url("REST/Setup.aspx", pick(parameters, :merchantId, :token, :serviceType, :amount, :currencyCode, :redirectUrl, :orderNumber, :transactionId))))
|
142
|
+
process(response, :setup)
|
143
|
+
end
|
144
|
+
|
145
|
+
def commit_payment_details(response, parameters)
|
146
|
+
data = encode(parameters[:creditcard].merge(:BBSePay_transaction => response[:setup]['SetupString']))
|
147
|
+
response[:paymentDetails] = parse(ssl_post(build_url("terminal/default.aspx"), data), false)
|
148
|
+
process(response, :paymentDetails)
|
149
|
+
end
|
150
|
+
|
151
|
+
def commit_process_setup(response, parameters)
|
152
|
+
result = ssl_get(build_url("REST/ProcessSetup.aspx", pick(parameters, :merchantId, :token, :transactionId).merge(:transactionString => response[:paymentDetails][:result])))
|
153
|
+
response[:processSetup] = parse(result)
|
154
|
+
process(response, :processSetup)
|
155
|
+
end
|
156
|
+
|
157
|
+
def commit_transaction(response, parameters)
|
158
|
+
result = ssl_get(build_url("REST/#{parameters[:action]}.aspx", pick(parameters, :merchantId, :token, :transactionId, :transactionAmount)))
|
159
|
+
response[:action] = parse(result)
|
160
|
+
process(response, :action)
|
161
|
+
end
|
162
|
+
|
163
|
+
def process(response, step)
|
164
|
+
if response[step][:container] =~ /Exception|Error/
|
165
|
+
response[:message] = response[step]['Message']
|
166
|
+
throw :exception
|
167
|
+
else
|
168
|
+
message = (response[step]['ResponseText'] || response[step]['ResponseCode'])
|
169
|
+
response[:message] = (message || response[:message])
|
170
|
+
|
171
|
+
response[:authorization] = response[step]['TransactionId']
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def parse(result, expects_xml=true)
|
176
|
+
if expects_xml || /^</ =~ result
|
177
|
+
doc = REXML::Document.new(result)
|
178
|
+
extract_xml(doc.root).merge(:container => doc.root.name)
|
179
|
+
else
|
180
|
+
{:result => result}
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def extract_xml(element)
|
185
|
+
if element.has_elements?
|
186
|
+
hash = {}
|
187
|
+
element.elements.each do |e|
|
188
|
+
hash[e.name] = extract_xml(e)
|
189
|
+
end
|
190
|
+
hash
|
191
|
+
else
|
192
|
+
element.text
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def url
|
197
|
+
(test? ? TEST_URL : LIVE_URL)
|
198
|
+
end
|
199
|
+
|
200
|
+
def generate_transaction_id(options)
|
201
|
+
Digest::MD5.hexdigest("#{options.inspect}+#{Time.now}+#{rand}")
|
202
|
+
end
|
203
|
+
|
204
|
+
def pick(hash, *keys)
|
205
|
+
keys.inject({}){|h,key| h[key] = hash[key] if hash[key]; h}
|
206
|
+
end
|
207
|
+
|
208
|
+
def build_url(base, parameters=nil)
|
209
|
+
url = "#{test? ? TEST_URL : LIVE_URL}"
|
210
|
+
url << base
|
211
|
+
if parameters
|
212
|
+
url << '?'
|
213
|
+
url << encode(parameters)
|
214
|
+
end
|
215
|
+
url
|
216
|
+
end
|
217
|
+
|
218
|
+
def encode(hash)
|
219
|
+
hash.collect{|(k,v)| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"}.join('&')
|
220
|
+
end
|
221
|
+
|
222
|
+
class Response < Billing::Response
|
223
|
+
attr_reader :error_detail
|
224
|
+
def initialize(success, message, raw, options)
|
225
|
+
super
|
226
|
+
unless success
|
227
|
+
@error_detail = raw[:processSetup]['Result']['ResponseText'] if raw[:processSetup] && raw[:processSetup]['Result']
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
@@ -0,0 +1,168 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class NetbillingGateway < Gateway
|
4
|
+
URL = 'https://secure.netbilling.com:1402/gw/sas/direct3.1'
|
5
|
+
|
6
|
+
TRANSACTIONS = {
|
7
|
+
:authorization => 'A',
|
8
|
+
:purchase => 'S',
|
9
|
+
:referenced_credit => 'R',
|
10
|
+
:unreferenced_credit => 'C',
|
11
|
+
:capture => 'D'
|
12
|
+
}
|
13
|
+
|
14
|
+
SUCCESS_CODES = [ '1', 'T' ]
|
15
|
+
SUCCESS_MESSAGE = 'The transaction was approved'
|
16
|
+
FAILURE_MESSAGE = 'The transaction failed'
|
17
|
+
TEST_LOGIN = '104901072025'
|
18
|
+
|
19
|
+
self.display_name = 'NETbilling'
|
20
|
+
self.homepage_url = 'http://www.netbilling.com'
|
21
|
+
self.supported_countries = ['US']
|
22
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :discover, :jcb, :diners_club]
|
23
|
+
|
24
|
+
def initialize(options = {})
|
25
|
+
requires!(options, :login)
|
26
|
+
@options = options
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
def authorize(money, credit_card, options = {})
|
31
|
+
post = {}
|
32
|
+
add_amount(post, money)
|
33
|
+
add_invoice(post, options)
|
34
|
+
add_credit_card(post, credit_card)
|
35
|
+
add_address(post, credit_card, options)
|
36
|
+
add_customer_data(post, options)
|
37
|
+
|
38
|
+
commit(:authorization, money, post)
|
39
|
+
end
|
40
|
+
|
41
|
+
def purchase(money, credit_card, options = {})
|
42
|
+
post = {}
|
43
|
+
add_amount(post, money)
|
44
|
+
add_invoice(post, options)
|
45
|
+
add_credit_card(post, credit_card)
|
46
|
+
add_address(post, credit_card, options)
|
47
|
+
add_customer_data(post, options)
|
48
|
+
|
49
|
+
commit(:purchase, money, post)
|
50
|
+
end
|
51
|
+
|
52
|
+
def capture(money, authorization, options = {})
|
53
|
+
post = {}
|
54
|
+
add_reference(post, authorization)
|
55
|
+
commit(:capture, money, post)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test?
|
59
|
+
@options[:login] == TEST_LOGIN || super
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
def add_amount(post, money)
|
64
|
+
post[:amount] = amount(money)
|
65
|
+
end
|
66
|
+
|
67
|
+
def add_reference(post, reference)
|
68
|
+
post[:orig_id] = reference
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_customer_data(post, options)
|
72
|
+
post[:cust_email] = options[:email]
|
73
|
+
post[:cust_ip] = options[:ip]
|
74
|
+
end
|
75
|
+
|
76
|
+
def add_address(post, credit_card, options)
|
77
|
+
if billing_address = options[:billing_address] || options[:address]
|
78
|
+
post[:bill_street] = billing_address[:address1]
|
79
|
+
post[:cust_phone] = billing_address[:phone]
|
80
|
+
post[:bill_zip] = billing_address[:zip]
|
81
|
+
post[:bill_city] = billing_address[:city]
|
82
|
+
post[:bill_country] = billing_address[:country]
|
83
|
+
post[:bill_state] = billing_address[:state]
|
84
|
+
end
|
85
|
+
|
86
|
+
if shipping_address = options[:shipping_address]
|
87
|
+
first_name, last_name = parse_first_and_last_name(shipping_address[:name])
|
88
|
+
|
89
|
+
post[:ship_name1] = first_name
|
90
|
+
post[:ship_name2] = last_name
|
91
|
+
post[:ship_street] = shipping_address[:address1]
|
92
|
+
post[:ship_zip] = shipping_address[:zip]
|
93
|
+
post[:ship_city] = shipping_address[:city]
|
94
|
+
post[:ship_country] = shipping_address[:country]
|
95
|
+
post[:ship_state] = shipping_address[:state]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def add_invoice(post, options)
|
100
|
+
post[:description] = options[:description]
|
101
|
+
end
|
102
|
+
|
103
|
+
def add_credit_card(post, credit_card)
|
104
|
+
post[:bill_name1] = credit_card.first_name
|
105
|
+
post[:bill_name2] = credit_card.last_name
|
106
|
+
post[:card_number] = credit_card.number
|
107
|
+
post[:card_expire] = expdate(credit_card)
|
108
|
+
post[:card_cvv2] = credit_card.verification_value
|
109
|
+
end
|
110
|
+
|
111
|
+
def parse(body)
|
112
|
+
results = {}
|
113
|
+
body.split(/&/).each do |pair|
|
114
|
+
key,val = pair.split(/=/)
|
115
|
+
results[key.to_sym] = CGI.unescape(val)
|
116
|
+
end
|
117
|
+
results
|
118
|
+
end
|
119
|
+
|
120
|
+
def commit(action, money, parameters)
|
121
|
+
response = parse(ssl_post(URL, post_data(action, parameters)))
|
122
|
+
|
123
|
+
Response.new(success?(response), message_from(response), response,
|
124
|
+
:test => test_response?(response),
|
125
|
+
:authorization => response[:trans_id],
|
126
|
+
:avs_result => { :code => response[:avs_code]},
|
127
|
+
:cvv_result => response[:cvv2_code]
|
128
|
+
)
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_response?(response)
|
132
|
+
!!(test? || response[:auth_msg] =~ /TEST/)
|
133
|
+
end
|
134
|
+
|
135
|
+
def success?(response)
|
136
|
+
SUCCESS_CODES.include?(response[:status_code])
|
137
|
+
end
|
138
|
+
|
139
|
+
def message_from(response)
|
140
|
+
success?(response) ? SUCCESS_MESSAGE : (response[:auth_msg] || FAILURE_MESSAGE)
|
141
|
+
end
|
142
|
+
|
143
|
+
def expdate(credit_card)
|
144
|
+
year = sprintf("%.4i", credit_card.year)
|
145
|
+
month = sprintf("%.2i", credit_card.month)
|
146
|
+
|
147
|
+
"#{month}#{year[-2..-1]}"
|
148
|
+
end
|
149
|
+
|
150
|
+
def post_data(action, parameters = {})
|
151
|
+
parameters[:account_id] = @options[:login]
|
152
|
+
parameters[:pay_type] = 'C'
|
153
|
+
parameters[:tran_type] = TRANSACTIONS[action]
|
154
|
+
|
155
|
+
parameters.reject{|k,v| v.blank?}.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
|
156
|
+
end
|
157
|
+
|
158
|
+
def parse_first_and_last_name(value)
|
159
|
+
name = value.to_s.split(' ')
|
160
|
+
|
161
|
+
last_name = name.pop || ''
|
162
|
+
first_name = name.join(' ')
|
163
|
+
[ first_name, last_name ]
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
@@ -0,0 +1,279 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
module ActiveMerchant #:nodoc:
|
4
|
+
module Billing #:nodoc:
|
5
|
+
# = Ogone DirectLink Gateway
|
6
|
+
#
|
7
|
+
# DirectLink is the API version of the Ogone Payment Platform. It allows server to server
|
8
|
+
# communication between Ogone systems and your e-commerce website.
|
9
|
+
#
|
10
|
+
# This implementation follows the specification provided in the DirectLink integration
|
11
|
+
# guide version 2.4 (December 2008), available here:
|
12
|
+
# https://secure.ogone.com/ncol/Ogone_DirectLink_EN.pdf
|
13
|
+
#
|
14
|
+
# It also features aliases, which allow to store/unstore credit cards, as specified in
|
15
|
+
# the Alias Manager Option guide version 2.2 available here:
|
16
|
+
# https://secure.ogone.com/ncol/Ogone_Alias_EN.pdf
|
17
|
+
#
|
18
|
+
# It was last tested on Release 04.79 of Ogone e-Commerce (dated 11/02/2009).
|
19
|
+
#
|
20
|
+
# For any questions or comments, please contact Nicolas Jacobeus (nj@belighted.com).
|
21
|
+
#
|
22
|
+
# == Example use:
|
23
|
+
#
|
24
|
+
# gateway = ActiveMerchant::Billing::OgoneGateway.new(
|
25
|
+
# :login => "my_ogone_psp_id",
|
26
|
+
# :user => "my_ogone_user_id",
|
27
|
+
# :password => "my_ogone_pswd",
|
28
|
+
# :signature => "my_ogone_sha1_signature" # extra security, only if you configured your Ogone environment so
|
29
|
+
# )
|
30
|
+
#
|
31
|
+
# # set up credit card obj as in main ActiveMerchant example
|
32
|
+
# creditcard = ActiveMerchant::Billing::CreditCard.new(
|
33
|
+
# :type => 'visa',
|
34
|
+
# :number => '4242424242424242',
|
35
|
+
# :month => 8,
|
36
|
+
# :year => 2009,
|
37
|
+
# :first_name => 'Bob',
|
38
|
+
# :last_name => 'Bobsen'
|
39
|
+
# )
|
40
|
+
#
|
41
|
+
# # run request
|
42
|
+
# response = gateway.purchase(1000, creditcard, :order_id => "1") # charge 10 EUR
|
43
|
+
#
|
44
|
+
# If you don't provide an :order_id, the gateway will generate a random one for you.
|
45
|
+
#
|
46
|
+
# puts response.success? # Check whether the transaction was successful
|
47
|
+
# puts response.message # Retrieve the message returned by Ogone
|
48
|
+
# puts response.authorization # Retrieve the unique transaction ID returned by Ogone
|
49
|
+
#
|
50
|
+
# To use the alias feature, simply add :alias in the options hash:
|
51
|
+
#
|
52
|
+
# gateway.purchase(1000, creditcard, :order_id => "1", :alias => "myawesomecustomer") # associates the alias to that creditcard
|
53
|
+
# gateway.purchase(2000, nil, :order_id => "2", :alias => "myawesomecustomer") # don't need to know the creditcard for subsequent orders
|
54
|
+
#
|
55
|
+
class OgoneGateway < Gateway
|
56
|
+
|
57
|
+
URLS = {
|
58
|
+
:test => { :order => 'https://secure.ogone.com/ncol/test/orderdirect.asp',
|
59
|
+
:maintenance => 'https://secure.ogone.com/ncol/test/maintenancedirect.asp' },
|
60
|
+
:production => { :order => 'https://secure.ogone.com/ncol/prod/orderdirect.asp',
|
61
|
+
:maintenance => 'https://secure.ogone.com/ncol/prod/maintenancedirect.asp' }
|
62
|
+
}
|
63
|
+
|
64
|
+
CVV_MAPPING = { 'OK' => 'M',
|
65
|
+
'KO' => 'N',
|
66
|
+
'NO' => 'P' }
|
67
|
+
|
68
|
+
AVS_MAPPING = { 'OK' => 'M',
|
69
|
+
'KO' => 'N',
|
70
|
+
'NO' => 'R' }
|
71
|
+
SUCCESS_MESSAGE = "The transaction was successful"
|
72
|
+
|
73
|
+
self.supported_countries = ['BE', 'DE', 'FR', 'NL', 'AT', 'CH']
|
74
|
+
# also supports Airplus and UATP
|
75
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :discover, :jcb, :maestro]
|
76
|
+
self.homepage_url = 'http://www.ogone.com/'
|
77
|
+
self.display_name = 'Ogone'
|
78
|
+
self.default_currency = 'EUR'
|
79
|
+
self.money_format = :cents
|
80
|
+
|
81
|
+
def initialize(options = {})
|
82
|
+
requires!(options, :login, :user, :password)
|
83
|
+
@options = options
|
84
|
+
super
|
85
|
+
end
|
86
|
+
|
87
|
+
# Verify and reserve the specified amount on the account, without actually doing the transaction.
|
88
|
+
def authorize(money, payment_source, options = {})
|
89
|
+
post = {}
|
90
|
+
add_invoice(post, options)
|
91
|
+
add_payment_source(post, payment_source, options)
|
92
|
+
add_address(post, payment_source, options)
|
93
|
+
add_customer_data(post, options)
|
94
|
+
add_money(post, money, options)
|
95
|
+
commit('RES', post)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Verify and transfer the specified amount.
|
99
|
+
def purchase(money, payment_source, options = {})
|
100
|
+
post = {}
|
101
|
+
add_invoice(post, options)
|
102
|
+
add_payment_source(post, payment_source, options)
|
103
|
+
add_address(post, payment_source, options)
|
104
|
+
add_customer_data(post, options)
|
105
|
+
add_money(post, money, options)
|
106
|
+
commit('SAL', post)
|
107
|
+
end
|
108
|
+
|
109
|
+
# Complete a previously authorized transaction.
|
110
|
+
def capture(money, authorization, options = {})
|
111
|
+
post = {}
|
112
|
+
add_authorization(post, reference_from(authorization))
|
113
|
+
add_invoice(post, options)
|
114
|
+
add_customer_data(post, options)
|
115
|
+
add_money(post, money, options)
|
116
|
+
commit('SAL', post)
|
117
|
+
end
|
118
|
+
|
119
|
+
# Cancels a previously authorized transaction.
|
120
|
+
def void(identification, options = {})
|
121
|
+
post = {}
|
122
|
+
add_authorization(post, reference_from(identification))
|
123
|
+
commit('DES', post)
|
124
|
+
end
|
125
|
+
|
126
|
+
# Credit the specified account by a specific amount.
|
127
|
+
def credit(money, identification_or_credit_card, options = {})
|
128
|
+
if reference_transaction?(identification_or_credit_card)
|
129
|
+
# Referenced credit: refund of a settled transaction
|
130
|
+
perform_reference_credit(money, identification_or_credit_card, options)
|
131
|
+
else # must be a credit card or card reference
|
132
|
+
perform_non_referenced_credit(money, identification_or_credit_card, options)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def test?
|
137
|
+
@options[:test] || super
|
138
|
+
end
|
139
|
+
|
140
|
+
private
|
141
|
+
def reference_from(authorization)
|
142
|
+
authorization.split(";").first
|
143
|
+
end
|
144
|
+
|
145
|
+
def reference_transaction?(identifier)
|
146
|
+
return false unless identifier.is_a?(String)
|
147
|
+
reference, action = identifier.split(";")
|
148
|
+
!action.nil?
|
149
|
+
end
|
150
|
+
|
151
|
+
def perform_reference_credit(money, payment_target, options = {})
|
152
|
+
post = {}
|
153
|
+
add_authorization(post, reference_from(payment_target))
|
154
|
+
add_money(post, money, options)
|
155
|
+
commit('RFD', post)
|
156
|
+
end
|
157
|
+
|
158
|
+
def perform_non_referenced_credit(money, payment_target, options = {})
|
159
|
+
# Non-referenced credit: acts like a reverse purchase
|
160
|
+
post = {}
|
161
|
+
add_invoice(post, options)
|
162
|
+
add_payment_source(post, payment_target, options)
|
163
|
+
add_address(post, payment_target, options)
|
164
|
+
add_customer_data(post, options)
|
165
|
+
add_money(post, money, options)
|
166
|
+
commit('RFD', post)
|
167
|
+
end
|
168
|
+
|
169
|
+
def add_payment_source(post, payment_source, options)
|
170
|
+
if payment_source.is_a?(String)
|
171
|
+
add_alias(post, payment_source)
|
172
|
+
add_eci(post, '9')
|
173
|
+
else
|
174
|
+
add_alias(post, options[:store])
|
175
|
+
add_creditcard(post, payment_source)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def add_eci(post, eci)
|
180
|
+
add_pair post, 'ECI', eci
|
181
|
+
end
|
182
|
+
|
183
|
+
def add_alias(post, _alias)
|
184
|
+
add_pair post, 'ALIAS', _alias
|
185
|
+
end
|
186
|
+
|
187
|
+
def add_authorization(post, authorization)
|
188
|
+
add_pair post, 'PAYID', authorization
|
189
|
+
end
|
190
|
+
|
191
|
+
def add_money(post, money, options)
|
192
|
+
add_pair post, 'currency', options[:currency] || currency(money)
|
193
|
+
add_pair post, 'amount', amount(money)
|
194
|
+
end
|
195
|
+
|
196
|
+
def add_customer_data(post, options)
|
197
|
+
add_pair post, 'EMAIL', options[:email]
|
198
|
+
add_pair post, 'REMOTE_ADDR', options[:ip]
|
199
|
+
end
|
200
|
+
|
201
|
+
def add_address(post, creditcard, options)
|
202
|
+
return unless options[:billing_address]
|
203
|
+
add_pair post, 'Owneraddress', options[:billing_address][:address1]
|
204
|
+
add_pair post, 'OwnerZip', options[:billing_address][:zip]
|
205
|
+
add_pair post, 'ownertown', options[:billing_address][:city]
|
206
|
+
add_pair post, 'ownercty', options[:billing_address][:country]
|
207
|
+
add_pair post, 'ownertelno', options[:billing_address][:phone]
|
208
|
+
end
|
209
|
+
|
210
|
+
def add_invoice(post, options)
|
211
|
+
add_pair post, 'orderID', options[:order_id] || generate_unique_id[0...30]
|
212
|
+
add_pair post, 'COM', options[:description]
|
213
|
+
end
|
214
|
+
|
215
|
+
def add_creditcard(post, creditcard)
|
216
|
+
add_pair post, 'CN', creditcard.name
|
217
|
+
add_pair post, 'CARDNO', creditcard.number
|
218
|
+
add_pair post, 'ED', "%02d%02s" % [creditcard.month, creditcard.year.to_s[-2..-1]]
|
219
|
+
add_pair post, 'CVC', creditcard.verification_value
|
220
|
+
end
|
221
|
+
|
222
|
+
def parse(body)
|
223
|
+
xml = REXML::Document.new(body)
|
224
|
+
xml.root.attributes
|
225
|
+
end
|
226
|
+
|
227
|
+
def commit(action, parameters)
|
228
|
+
add_pair parameters, 'PSPID', @options[:login]
|
229
|
+
add_pair parameters, 'USERID', @options[:user]
|
230
|
+
add_pair parameters, 'PSWD', @options[:password]
|
231
|
+
url = URLS[test? ? :test : :production][parameters['PAYID'] ? :maintenance : :order ]
|
232
|
+
response = parse(ssl_post(url, post_data(action, parameters)))
|
233
|
+
options = { :authorization => [response["PAYID"], action].join(";"),
|
234
|
+
:test => test?,
|
235
|
+
:avs_result => { :code => AVS_MAPPING[response["AAVCheck"]] },
|
236
|
+
:cvv_result => CVV_MAPPING[response["CVCCheck"]] }
|
237
|
+
Response.new(successful?(response), message_from(response), response, options)
|
238
|
+
end
|
239
|
+
|
240
|
+
def successful?(response)
|
241
|
+
response["NCERROR"] == "0"
|
242
|
+
end
|
243
|
+
|
244
|
+
def message_from(response)
|
245
|
+
if successful?(response)
|
246
|
+
SUCCESS_MESSAGE
|
247
|
+
else
|
248
|
+
format_error_message(response["NCERRORPLUS"])
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
def format_error_message(message)
|
253
|
+
raw_message = message.to_s.strip
|
254
|
+
case raw_message
|
255
|
+
when /\|/
|
256
|
+
raw_message.split("|").join(", ").capitalize
|
257
|
+
when /\//
|
258
|
+
raw_message.split("/").first.to_s.capitalize
|
259
|
+
else
|
260
|
+
raw_message.to_s.capitalize
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
def post_data(action, parameters = {})
|
265
|
+
add_pair parameters, 'Operation' , action
|
266
|
+
if @options[:signature] # the user wants a SHA-1 signature
|
267
|
+
string = ['orderID','amount','currency','CARDNO','PSPID','Operation','ALIAS'].map{|s|parameters[s]}.join + @options[:signature]
|
268
|
+
add_pair parameters, 'SHASign' , Digest::SHA1.hexdigest(string)
|
269
|
+
end
|
270
|
+
parameters.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
|
271
|
+
end
|
272
|
+
|
273
|
+
def add_pair(post, key, value, options = {})
|
274
|
+
post[key] = value if !value.blank? || options[:required]
|
275
|
+
end
|
276
|
+
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|