activemerchant 1.9.1 → 1.9.2

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/CHANGELOG CHANGED
@@ -1,5 +1,11 @@
1
1
  = ActiveMerchant CHANGELOG
2
2
 
3
+ == Version 1.9.2 (December 9, 2010)
4
+
5
+ * Add support for PayPal mobile payments [Adrian Irving-Beer]
6
+ * Add ePay gateway [ePay, Jonathan Rudenberg]
7
+ * Allow access to the raw HTTP response [Jonathan Rudenberg]
8
+
3
9
  == Version 1.9.1 (November 24, 2010)
4
10
 
5
11
  * PayPal Express and PayPal Pro: Send JPY currency correctly without decimals [Soleone]
@@ -167,4 +167,9 @@ SagePay Form Offsite Gateway (October 14, 2010)
167
167
 
168
168
  DirecPay Gateway (October 14, 2010)
169
169
 
170
- * Soleone
170
+ * Soleone
171
+
172
+ ePay Gateway (November 23, 2010)
173
+
174
+ * Original code by ePay (epay.dk)
175
+ * Refactored by Jonathan Rudenberg
@@ -20,6 +20,7 @@ The {ActiveMerchant Wiki}[http://github.com/Shopify/active_merchant/wikis] conta
20
20
  * {DataCash}[http://www.datacash.com/] - GB
21
21
  * {Efsnet}[http://www.concordefsnet.com/] - US
22
22
  * {Elavon MyVirtualMerchant}[http://www.elavon.com] - US, CA
23
+ * {ePay}[http://www.epay.dk/] - DK
23
24
  * {eWAY}[http://www.eway.com.au/] - AU
24
25
  * {E-xact}[http://www.e-xact.com] - CA, US
25
26
  * {FirstPay}[http://www.first-pay.com] - US
@@ -0,0 +1,263 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class EpayGateway < Gateway
4
+ API_HOST = 'ssl.ditonlinebetalingssystem.dk'
5
+ SOAP_URL = 'https://' + API_HOST + '/remote/payment'
6
+
7
+ self.default_currency = 'DKK'
8
+ self.money_format = :cents
9
+ self.supported_cardtypes = [:dankort, :forbrugsforeningen, :visa, :master,
10
+ :american_express, :diners_club, :jcb, :maestro]
11
+ self.supported_countries = ['DK']
12
+ self.homepage_url = 'http://epay.dk/'
13
+ self.display_name = 'ePay'
14
+
15
+ CURRENCY_CODES = {
16
+ :ADP => '020', :AED => '784', :AFA => '004', :ALL => '008', :AMD => '051',
17
+ :ANG => '532', :AOA => '973', :ARS => '032', :AUD => '036', :AWG => '533',
18
+ :AZM => '031', :BAM => '977', :BBD => '052', :BDT => '050', :BGL => '100',
19
+ :BGN => '975', :BHD => '048', :BIF => '108', :BMD => '060', :BND => '096',
20
+ :BOB => '068', :BOV => '984', :BRL => '986', :BSD => '044', :BTN => '064',
21
+ :BWP => '072', :BYR => '974', :BZD => '084', :CAD => '124', :CDF => '976',
22
+ :CHF => '756', :CLF => '990', :CLP => '152', :CNY => '156', :COP => '170',
23
+ :CRC => '188', :CUP => '192', :CVE => '132', :CYP => '196', :CZK => '203',
24
+ :DJF => '262', :DKK => '208', :DOP => '214', :DZD => '012', :ECS => '218',
25
+ :ECV => '983', :EEK => '233', :EGP => '818', :ERN => '232', :ETB => '230',
26
+ :EUR => '978', :FJD => '242', :FKP => '238', :GBP => '826', :GEL => '981',
27
+ :GHC => '288', :GIP => '292', :GMD => '270', :GNF => '324', :GTQ => '320',
28
+ :GWP => '624', :GYD => '328', :HKD => '344', :HNL => '340', :HRK => '191',
29
+ :HTG => '332', :HUF => '348', :IDR => '360', :ILS => '376', :INR => '356',
30
+ :IQD => '368', :IRR => '364', :ISK => '352', :JMD => '388', :JOD => '400',
31
+ :JPY => '392', :KES => '404', :KGS => '417', :KHR => '116', :KMF => '174',
32
+ :KPW => '408', :KRW => '410', :KWD => '414', :KYD => '136', :KZT => '398',
33
+ :LAK => '418', :LBP => '422', :LKR => '144', :LRD => '430', :LSL => '426',
34
+ :LTL => '440', :LVL => '428', :LYD => '434', :MAD => '504', :MDL => '498',
35
+ :MGF => '450', :MKD => '807', :MMK => '104', :MNT => '496', :MOP => '446',
36
+ :MRO => '478', :MTL => '470', :MUR => '480', :MVR => '462', :MWK => '454',
37
+ :MXN => '484', :MXV => '979', :MYR => '458', :MZM => '508', :NAD => '516',
38
+ :NGN => '566', :NIO => '558', :NOK => '578', :NPR => '524', :NZD => '554',
39
+ :OMR => '512', :PAB => '590', :PEN => '604', :PGK => '598', :PHP => '608',
40
+ :PKR => '586', :PLN => '985', :PYG => '600', :QAR => '634', :ROL => '642',
41
+ :RUB => '643', :RUR => '810', :RWF => '646', :SAR => '682', :SBD => '090',
42
+ :SCR => '690', :SDD => '736', :SEK => '752', :SGD => '702', :SHP => '654',
43
+ :SIT => '705', :SKK => '703', :SLL => '694', :SOS => '706', :SRG => '740',
44
+ :STD => '678', :SVC => '222', :SYP => '760', :SZL => '748', :THB => '764',
45
+ :TJS => '972', :TMM => '795', :TND => '788', :TOP => '776', :TPE => '626',
46
+ :TRL => '792', :TRY => '949', :TTD => '780', :TWD => '901', :TZS => '834',
47
+ :UAH => '980', :UGX => '800', :USD => '840', :UYU => '858', :UZS => '860',
48
+ :VEB => '862', :VND => '704', :VUV => '548', :XAF => '950', :XCD => '951',
49
+ :XOF => '952', :XPF => '953', :YER => '886', :YUM => '891', :ZAR => '710',
50
+ :ZMK => '894', :ZWD => '716'
51
+ }
52
+
53
+ # login: merchant number
54
+ # password: referrer url (for authorize authentication)
55
+ def initialize(options = {})
56
+ requires!(options, :login, :password)
57
+ @options = options
58
+ super
59
+ end
60
+
61
+ def authorize(money, credit_card_or_reference, options = {})
62
+ post = {}
63
+
64
+ add_amount(post, money, options)
65
+ add_invoice(post)
66
+ add_creditcard_or_reference(post, credit_card_or_reference)
67
+ add_instant_capture(post, false)
68
+
69
+ commit(:authorize, post)
70
+ end
71
+
72
+ def purchase(money, credit_card_or_reference, options = {})
73
+ post = {}
74
+
75
+ add_amount(post, money, options)
76
+ add_creditcard_or_reference(post, credit_card_or_reference)
77
+ add_invoice(post)
78
+ add_instant_capture(post, true)
79
+
80
+ commit(:authorize, post)
81
+ end
82
+
83
+ def capture(money, authorization, options = {})
84
+ post = {}
85
+
86
+ add_reference(post, authorization)
87
+ add_amount_without_currency(post, money)
88
+
89
+ commit(:capture, post)
90
+ end
91
+
92
+ def void(identification, options = {})
93
+ post = {}
94
+
95
+ add_reference(post, identification)
96
+
97
+ commit(:void, post)
98
+ end
99
+
100
+ def credit(money, identification, options = {})
101
+ post = {}
102
+
103
+ add_amount_without_currency(post, money)
104
+ add_reference(post, identification)
105
+
106
+ commit(:credit, post)
107
+ end
108
+
109
+
110
+ private
111
+
112
+ def add_amount(post, money, options)
113
+ post[:amount] = amount(money)
114
+ post[:currency] = CURRENCY_CODES[(options[:currency] || currency(money)).to_sym]
115
+ end
116
+
117
+ def add_amount_without_currency(post, money)
118
+ post[:amount] = amount(money)
119
+ end
120
+
121
+ def add_reference(post, identification)
122
+ post[:transaction] = identification
123
+ end
124
+
125
+ def add_invoice(post)
126
+ post[:orderid] = format_order_number(options[:order_id])
127
+ end
128
+
129
+ def add_creditcard(post, credit_card)
130
+ post[:cardno] = credit_card.number
131
+ post[:cvc] = credit_card.verification_value
132
+ post[:expmonth] = credit_card.month
133
+ post[:expyear] = credit_card.year
134
+ end
135
+
136
+ def add_creditcard_or_reference(post, credit_card_or_reference)
137
+ if credit_card_or_reference.is_a?(CreditCard)
138
+ add_creditcard(post, credit_card_or_reference)
139
+ else
140
+ add_reference(post, credit_card_or_reference.to_s)
141
+ end
142
+ end
143
+
144
+ def add_instant_capture(post, option)
145
+ post[:instantcapture] = option ? 1 : 0
146
+ end
147
+
148
+ def commit(action, params)
149
+ response = send("do_#{action}", params)
150
+
151
+ if action == :authorize
152
+ Response.new response['accept'].to_i == 1,
153
+ response['errortext'],
154
+ response,
155
+ :test => test?,
156
+ :authorization => response['tid']
157
+ else
158
+ Response.new response['result'] == 'true',
159
+ messages(response['epay'], response['pbs']),
160
+ response,
161
+ :test => test?,
162
+ :authorization => params[:transaction]
163
+ end
164
+ end
165
+
166
+ def messages(epay, pbs = nil)
167
+ response = "ePay: #{epay}"
168
+ response << " PBS: #{pbs}" if pbs
169
+ return response
170
+ end
171
+
172
+ def soap_post(method, params)
173
+ data = xml_builder(params, method)
174
+ headers = make_headers(data, method)
175
+ REXML::Document.new(ssl_post('https://' + API_HOST + '/remote/payment.asmx', data, headers))
176
+ end
177
+
178
+ def do_authorize(params)
179
+ headers = {
180
+ 'Referer' => options[:password]
181
+ }
182
+
183
+ response = raw_ssl_request(:post, 'https://' + API_HOST + '/auth/default.aspx', authorize_post_data(params), headers)
184
+
185
+ # Authorize gives the response back by redirecting with the values in
186
+ # the URL query
187
+ query = CGI::parse(URI.parse(response['Location'].gsub(' ', '%20')).query)
188
+
189
+ result = {}
190
+ query.each_pair do |k,v|
191
+ result[k] = v.is_a?(Array) && v.size == 1 ? v[0] : v # make values like ['v'] into 'v'
192
+ end
193
+ result
194
+ end
195
+
196
+ def do_capture(params)
197
+ response = soap_post('capture', params)
198
+ {
199
+ 'result' => response.elements['//captureResponse/captureResult'].text,
200
+ 'pbs' => response.elements['//captureResponse/pbsResponse'].text,
201
+ 'epay' => response.elements['//captureResponse/epayresponse'].text
202
+ }
203
+ end
204
+
205
+ def do_credit(params)
206
+ response = soap_post('credit', params)
207
+ {
208
+ 'result' => response.elements['//creditResponse/creditResult'].text,
209
+ 'pbs' => response.elements['//creditResponse/pbsresponse'].text,
210
+ 'epay' => response.elements['//creditResponse/epayresponse'].text
211
+ }
212
+ end
213
+
214
+ def do_void(params)
215
+ response = soap_post('delete', params)
216
+ {
217
+ 'result' => response.elements['//deleteResponse/deleteResult'].text,
218
+ 'epay' => response.elements['//deleteResponse/epayresponse'].text
219
+ }
220
+ end
221
+
222
+ def make_headers(data, soap_call)
223
+ {
224
+ 'Content-Type' => 'text/xml; charset=utf-8',
225
+ 'Host' => API_HOST,
226
+ 'Content-Length' => data.size.to_s,
227
+ 'SOAPAction' => SOAP_URL + '/' + soap_call
228
+ }
229
+ end
230
+
231
+ def xml_builder(params, soap_call)
232
+ xml = Builder::XmlMarkup.new(:indent => 2)
233
+ xml.instruct!
234
+ xml.tag! 'soap:Envelope', { 'xmlns:xsi' => 'http://schemas.xmlsoap.org/soap/envelope/',
235
+ 'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
236
+ 'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/' } do
237
+ xml.tag! 'soap:Body' do
238
+ xml.tag! soap_call, { 'xmlns' => SOAP_URL } do
239
+ xml.tag! 'merchantnumber', @options[:login]
240
+ xml.tag! 'transactionid', params[:transaction]
241
+ xml.tag! 'amount', params[:amount].to_s if soap_call != 'delete'
242
+ end
243
+ end
244
+ end
245
+ xml.target!
246
+ end
247
+
248
+ def authorize_post_data(params = {})
249
+ params[:language] = '2'
250
+ params[:accepturl] = 'https://ssl.ditonlinebetalingssystem.dk/auth/default.aspx?accept=1'
251
+ params[:declineurl] = 'https://ssl.ditonlinebetalingssystem.dk/auth/default.aspx?decline=1'
252
+ params[:merchantnumber] = @options[:login]
253
+
254
+ params.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
255
+ end
256
+
257
+ # Limited to 20 digits max
258
+ def format_order_number(number)
259
+ number.to_s.gsub(/[^\w_]/, '').rjust(4, "0")[0...20]
260
+ end
261
+ end
262
+ end
263
+ end
@@ -8,7 +8,7 @@ module ActiveMerchant #:nodoc:
8
8
  include PayflowCommonAPI
9
9
  include PaypalExpressCommon
10
10
 
11
- self.test_redirect_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='
11
+ self.test_redirect_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr'
12
12
  self.homepage_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=xpt/merchant/ExpressCheckoutIntro-outside'
13
13
  self.display_name = 'PayPal Express Checkout'
14
14
 
@@ -8,7 +8,7 @@ module ActiveMerchant #:nodoc:
8
8
  include PaypalCommonAPI
9
9
  include PaypalExpressCommon
10
10
 
11
- self.test_redirect_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='
11
+ self.test_redirect_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr'
12
12
  self.supported_countries = ['US']
13
13
  self.homepage_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=xpt/merchant/ExpressCheckoutIntro-outside'
14
14
  self.display_name = 'PayPal Express Checkout'
@@ -4,7 +4,7 @@ module ActiveMerchant
4
4
  def self.included(base)
5
5
  base.cattr_accessor :test_redirect_url
6
6
  base.cattr_accessor :live_redirect_url
7
- base.live_redirect_url = 'https://www.paypal.com/cgibin/webscr?cmd=_express-checkout&token='
7
+ base.live_redirect_url = 'https://www.paypal.com/cgibin/webscr'
8
8
  end
9
9
 
10
10
  def redirect_url
@@ -12,8 +12,13 @@ module ActiveMerchant
12
12
  end
13
13
 
14
14
  def redirect_url_for(token, options = {})
15
- options = {:review => true}.update(options)
16
- options[:review] ? "#{redirect_url}#{token}" : "#{redirect_url}#{token}&useraction=commit"
15
+ options = {:review => true, :mobile => false}.update(options)
16
+
17
+ cmd = options[:mobile] ? '_express-checkout-mobile' : '_express-checkout'
18
+ url = "#{redirect_url}?cmd=#{cmd}&token=#{token}"
19
+ url += '&useraction=commit' unless options[:review]
20
+
21
+ url
17
22
  end
18
23
  end
19
24
  end
@@ -134,7 +134,7 @@ module ActiveMerchant #:nodoc:
134
134
  fields = {}
135
135
  for line in body.split('&')
136
136
  key, value = *line.scan( %r{^(\w+)\=(.*)$} ).flatten
137
- fields[key] = CGI.unescape(value)
137
+ fields[key] = CGI.unescape(value.to_s)
138
138
  end
139
139
 
140
140
  {
@@ -71,9 +71,8 @@ module ActiveMerchant
71
71
  end
72
72
 
73
73
  info "--> %d %s (%d %.4fs)" % [result.code, result.message, result.body ? result.body.length : 0, realtime], tag
74
- response = handle_response(result)
75
- debug response
76
- response
74
+ debug result.body
75
+ result
77
76
  rescue EOFError => e
78
77
  raise ConnectionError, "The remote server dropped the connection"
79
78
  rescue Errno::ECONNRESET => e
@@ -147,15 +146,6 @@ module ActiveMerchant
147
146
  end
148
147
  end
149
148
 
150
- def handle_response(response)
151
- case response.code.to_i
152
- when 200...300
153
- response.body
154
- else
155
- raise ResponseError.new(response)
156
- end
157
- end
158
-
159
149
  def debug(message, tag = nil)
160
150
  log(:debug, message, tag)
161
151
  end
@@ -169,4 +159,4 @@ module ActiveMerchant
169
159
  logger.send(level, message) if logger
170
160
  end
171
161
  end
172
- end
162
+ end
@@ -25,9 +25,12 @@ module ActiveMerchant #:nodoc:
25
25
  def ssl_post(endpoint, data, headers = {})
26
26
  ssl_request(:post, endpoint, data, headers)
27
27
  end
28
-
29
- private
30
- def ssl_request(method, endpoint, data, headers = {})
28
+
29
+ def ssl_request(method, endpoint, data, headers)
30
+ handle_response(raw_ssl_request(method, endpoint, data, headers))
31
+ end
32
+
33
+ def raw_ssl_request(method, endpoint, data, headers = {})
31
34
  connection = Connection.new(endpoint)
32
35
  connection.open_timeout = open_timeout
33
36
  connection.read_timeout = read_timeout
@@ -42,6 +45,17 @@ module ActiveMerchant #:nodoc:
42
45
 
43
46
  connection.request(method, data, headers)
44
47
  end
48
+
49
+ private
50
+
51
+ def handle_response(response)
52
+ case response.code.to_i
53
+ when 200...300
54
+ response.body
55
+ else
56
+ raise ResponseError.new(response)
57
+ end
58
+ end
45
59
 
46
60
  end
47
- end
61
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveMerchant
2
- VERSION = "1.9.1"
2
+ VERSION = "1.9.2"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemerchant
3
3
  version: !ruby/object:Gem::Version
4
- hash: 49
4
+ hash: 55
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 9
9
- - 1
10
- version: 1.9.1
9
+ - 2
10
+ version: 1.9.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tobias Luetke
@@ -36,7 +36,7 @@ cert_chain:
36
36
  hPaSTyVU0yCSnw==
37
37
  -----END CERTIFICATE-----
38
38
 
39
- date: 2010-11-24 00:00:00 -05:00
39
+ date: 2010-12-09 00:00:00 -05:00
40
40
  default_executable:
41
41
  dependencies:
42
42
  - !ruby/object:Gem::Dependency
@@ -125,6 +125,7 @@ files:
125
125
  - lib/active_merchant/billing/gateways/data_cash.rb
126
126
  - lib/active_merchant/billing/gateways/efsnet.rb
127
127
  - lib/active_merchant/billing/gateways/elavon.rb
128
+ - lib/active_merchant/billing/gateways/epay.rb
128
129
  - lib/active_merchant/billing/gateways/eway.rb
129
130
  - lib/active_merchant/billing/gateways/exact.rb
130
131
  - lib/active_merchant/billing/gateways/first_pay.rb
metadata.gz.sig CHANGED
Binary file