yetanothernguyen-activemerchant 1.16.0 → 1.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. data/CHANGELOG +95 -0
  2. data/CONTRIBUTORS +29 -0
  3. data/lib/active_merchant/billing/credit_card.rb +105 -19
  4. data/lib/active_merchant/billing/credit_card_methods.rb +5 -1
  5. data/lib/active_merchant/billing/gateway.rb +1 -1
  6. data/lib/active_merchant/billing/gateways/authorize_net.rb +24 -2
  7. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +104 -18
  8. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +110 -4
  9. data/lib/active_merchant/billing/gateways/beanstream.rb +29 -1
  10. data/lib/active_merchant/billing/gateways/braintree_blue.rb +9 -4
  11. data/lib/active_merchant/billing/gateways/braintree_orange.rb +4 -0
  12. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  13. data/lib/active_merchant/billing/gateways/certo_direct.rb +279 -0
  14. data/lib/active_merchant/billing/gateways/efsnet.rb +9 -9
  15. data/lib/active_merchant/billing/gateways/elavon.rb +2 -1
  16. data/lib/active_merchant/billing/gateways/epay.rb +12 -6
  17. data/lib/active_merchant/billing/gateways/eway_managed.rb +46 -12
  18. data/lib/active_merchant/billing/gateways/exact.rb +5 -0
  19. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +3 -3
  20. data/lib/active_merchant/billing/gateways/ipay88.rb +157 -0
  21. data/lib/active_merchant/billing/gateways/iridium.rb +3 -3
  22. data/lib/active_merchant/billing/gateways/itransact.rb +450 -0
  23. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +1 -0
  24. data/lib/active_merchant/billing/gateways/moneris.rb +4 -0
  25. data/lib/active_merchant/billing/gateways/nab_transact.rb +244 -0
  26. data/lib/active_merchant/billing/gateways/ogone.rb +94 -56
  27. data/lib/active_merchant/billing/gateways/optimal_payment.rb +277 -0
  28. data/lib/active_merchant/billing/gateways/orbital.rb +57 -34
  29. data/lib/active_merchant/billing/gateways/pay_junction.rb +6 -1
  30. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +1 -0
  31. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +2 -2
  32. data/lib/active_merchant/billing/gateways/payflow.rb +10 -2
  33. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +8 -5
  34. data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +43 -0
  35. data/lib/active_merchant/billing/gateways/paypal_express.rb +93 -40
  36. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +8 -3
  37. data/lib/active_merchant/billing/gateways/qbms.rb +4 -0
  38. data/lib/active_merchant/billing/gateways/quickpay.rb +97 -22
  39. data/lib/active_merchant/billing/gateways/realex.rb +5 -1
  40. data/lib/active_merchant/billing/gateways/samurai.rb +121 -0
  41. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +136 -49
  42. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +1 -1
  43. data/lib/active_merchant/billing/gateways/skip_jack.rb +7 -2
  44. data/lib/active_merchant/billing/gateways/stripe.rb +51 -19
  45. data/lib/active_merchant/billing/gateways/usa_epay.rb +13 -184
  46. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1496 -0
  47. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +206 -0
  48. data/lib/active_merchant/billing/gateways/verifi.rb +2 -2
  49. data/lib/active_merchant/billing/gateways/viaklix.rb +1 -1
  50. data/lib/active_merchant/billing/gateways/worldpay.rb +1 -1
  51. data/lib/active_merchant/billing/integrations/action_view_helper.rb +6 -2
  52. data/lib/active_merchant/billing/integrations/authorize_net_sim/helper.rb +228 -0
  53. data/lib/active_merchant/billing/integrations/authorize_net_sim/notification.rb +340 -0
  54. data/lib/active_merchant/billing/integrations/authorize_net_sim.rb +38 -0
  55. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +4 -4
  56. data/lib/active_merchant/billing/integrations/dwolla/helper.rb +31 -0
  57. data/lib/active_merchant/billing/integrations/dwolla/notification.rb +55 -0
  58. data/lib/active_merchant/billing/integrations/dwolla/return.rb +38 -0
  59. data/lib/active_merchant/billing/integrations/dwolla.rb +30 -0
  60. data/lib/active_merchant/billing/integrations/helper.rb +19 -2
  61. data/lib/active_merchant/billing/integrations/ipay88/helper.rb +120 -0
  62. data/lib/active_merchant/billing/integrations/ipay88/return.rb +121 -0
  63. data/lib/active_merchant/billing/integrations/ipay88.rb +40 -0
  64. data/lib/active_merchant/billing/integrations/nochex.rb +1 -1
  65. data/lib/active_merchant/billing/integrations/payflow_link/helper.rb +100 -0
  66. data/lib/active_merchant/billing/integrations/payflow_link/notification.rb +78 -0
  67. data/lib/active_merchant/billing/integrations/payflow_link.rb +21 -0
  68. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +4 -4
  69. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +18 -2
  70. data/lib/active_merchant/billing/integrations/two_checkout.rb +1 -2
  71. data/lib/active_merchant/railtie.rb +7 -7
  72. data/lib/active_merchant/railtie.rb.orig +19 -0
  73. data/lib/active_merchant/version.rb +1 -1
  74. data/lib/active_merchant.rb +23 -10
  75. data/lib/active_merchant.rb.orig +78 -0
  76. metadata +147 -63
  77. data/lib/active_merchant/common/connection.rb +0 -177
  78. data/lib/active_merchant/common/country.rb +0 -328
  79. data/lib/active_merchant/common/error.rb +0 -26
  80. data/lib/active_merchant/common/post_data.rb +0 -24
  81. data/lib/active_merchant/common/posts_data.rb +0 -63
  82. data/lib/active_merchant/common/requires_parameters.rb +0 -16
  83. data/lib/active_merchant/common/utils.rb +0 -22
  84. data/lib/active_merchant/common/validateable.rb +0 -81
  85. data/lib/active_merchant/common.rb +0 -14
  86. data/lib/certs/cacert.pem +0 -7815
@@ -0,0 +1,244 @@
1
+ require 'rexml/document'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ # The National Australia Bank provide a payment gateway that seems to
6
+ # be a rebadged Securepay Australia service, though some differences exist.
7
+ class NabTransactGateway < Gateway
8
+ API_VERSION = 'xml-4.2'
9
+ PERIODIC_API_VERSION = "spxml-4.2"
10
+
11
+ TEST_URL = 'https://transact.nab.com.au/test/xmlapi/payment'
12
+ LIVE_URL = 'https://transact.nab.com.au/live/xmlapi/payment'
13
+ TEST_PERIODIC_URL = "https://transact.nab.com.au/xmlapidemo/periodic"
14
+ LIVE_PERIODIC_URL = "https://transact.nab.com.au/xmlapi/periodic"
15
+
16
+ self.supported_countries = ['AU']
17
+
18
+ # The card types supported by the payment gateway
19
+ # Note that support for Diners, Amex, and JCB require extra
20
+ # steps in setting up your account, as detailed in the NAB Transact API
21
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :jcb]
22
+
23
+ self.homepage_url = 'http://transact.nab.com.au'
24
+ self.display_name = 'NAB Transact'
25
+
26
+ cattr_accessor :request_timeout
27
+ self.request_timeout = 60
28
+
29
+ self.money_format = :cents
30
+ self.default_currency = 'AUD'
31
+
32
+ #Transactions currently accepted by NAB Transact XML API
33
+ TRANSACTIONS = {
34
+ :purchase => 0, #Standard Payment
35
+ :credit => 4, #Refund
36
+ :void => 6, #Client Reversal (Void)
37
+ :authorization => 10, #Preauthorise
38
+ :capture => 11 #Preauthorise Complete (Advice)
39
+ }
40
+
41
+ PERIODIC_TYPES = {
42
+ :addcrn => 5,
43
+ :editcrn => 5,
44
+ :deletecrn => 5,
45
+ :trigger => 8
46
+ }
47
+
48
+ SUCCESS_CODES = [ '00', '08', '11', '16', '77' ]
49
+
50
+
51
+ def initialize(options = {})
52
+ requires!(options, :login, :password)
53
+ @options = options
54
+ super
55
+ end
56
+
57
+ def test?
58
+ @options[:test] || super
59
+ end
60
+
61
+ def purchase(money, credit_card_or_stored_id, options = {})
62
+ if credit_card_or_stored_id.is_a?(ActiveMerchant::Billing::CreditCard)
63
+ #Credit card for instant payment
64
+ commit :purchase, build_purchase_request(money, credit_card_or_stored_id, options)
65
+ else
66
+ #Triggered payment for an existing stored credit card
67
+ options[:billing_id] = credit_card_or_stored_id.to_s
68
+ commit_periodic build_periodic_item(:trigger, money, nil, options)
69
+ end
70
+ end
71
+
72
+ def store(creditcard, options = {})
73
+ requires!(options, :billing_id, :amount)
74
+ commit_periodic(build_periodic_item(:addcrn, options[:amount], creditcard, options))
75
+ end
76
+
77
+ def unstore(identification, options = {})
78
+ options[:billing_id] = identification
79
+ commit_periodic(build_periodic_item(:deletecrn, options[:amount], nil, options))
80
+ end
81
+
82
+ private
83
+
84
+ def build_purchase_request(money, credit_card, options)
85
+ xml = Builder::XmlMarkup.new
86
+ xml.tag! 'amount', amount(money)
87
+ xml.tag! 'currency', options[:currency] || currency(money)
88
+ xml.tag! 'purchaseOrderNo', options[:order_id].to_s.gsub(/[ ']/, '')
89
+
90
+ xml.tag! 'CreditCardInfo' do
91
+ xml.tag! 'cardNumber', credit_card.number
92
+ xml.tag! 'expiryDate', expdate(credit_card)
93
+ xml.tag! 'cvv', credit_card.verification_value if credit_card.verification_value?
94
+ end
95
+
96
+ xml.target!
97
+ end
98
+
99
+ #Generate payment request XML
100
+ # - API is set to allow multiple Txn's but currentlu only allows one
101
+ # - txnSource = 23 - (XML)
102
+
103
+ def build_request(action, body)
104
+ xml = Builder::XmlMarkup.new
105
+ xml.instruct!
106
+ xml.tag! 'NABTransactMessage' do
107
+ xml.tag! 'MessageInfo' do
108
+ xml.tag! 'messageID', Utils.generate_unique_id.slice(0, 30)
109
+ xml.tag! 'messageTimestamp', generate_timestamp
110
+ xml.tag! 'timeoutValue', request_timeout
111
+ xml.tag! 'apiVersion', API_VERSION
112
+ end
113
+
114
+ xml.tag! 'MerchantInfo' do
115
+ xml.tag! 'merchantID', @options[:login]
116
+ xml.tag! 'password', @options[:password]
117
+ end
118
+
119
+ xml.tag! 'RequestType', 'Payment'
120
+ xml.tag! 'Payment' do
121
+ xml.tag! 'TxnList', "count" => 1 do
122
+ xml.tag! 'Txn', "ID" => 1 do
123
+ xml.tag! 'txnType', TRANSACTIONS[action]
124
+ xml.tag! 'txnSource', 23
125
+ xml << body
126
+ end
127
+ end
128
+ end
129
+ end
130
+
131
+ xml.target!
132
+ end
133
+
134
+ def build_periodic_item(action, money, credit_card, options)
135
+ xml = Builder::XmlMarkup.new
136
+
137
+ xml.tag! 'actionType', action.to_s
138
+ xml.tag! 'periodicType', PERIODIC_TYPES[action] if PERIODIC_TYPES[action]
139
+ xml.tag! 'currency', options[:currency] || currency(money)
140
+ xml.tag! 'crn', options[:billing_id]
141
+
142
+ if credit_card
143
+ xml.tag! 'CreditCardInfo' do
144
+ xml.tag! 'cardNumber', credit_card.number
145
+ xml.tag! 'expiryDate', expdate(credit_card)
146
+ xml.tag! 'cvv', credit_card.verification_value if credit_card.verification_value?
147
+ end
148
+ end
149
+ xml.tag! 'amount', amount(money)
150
+
151
+ xml.target!
152
+ end
153
+
154
+ def build_periodic_request(body)
155
+ xml = Builder::XmlMarkup.new
156
+ xml.instruct!
157
+ xml.tag! 'NABTransactMessage' do
158
+ xml.tag! 'MessageInfo' do
159
+ xml.tag! 'messageID', ActiveMerchant::Utils.generate_unique_id.slice(0, 30)
160
+ xml.tag! 'messageTimestamp', generate_timestamp
161
+ xml.tag! 'timeoutValue', request_timeout
162
+ xml.tag! 'apiVersion', PERIODIC_API_VERSION
163
+ end
164
+
165
+ xml.tag! 'MerchantInfo' do
166
+ xml.tag! 'merchantID', @options[:login]
167
+ xml.tag! 'password', @options[:password]
168
+ end
169
+
170
+ xml.tag! 'RequestType', 'Periodic'
171
+ xml.tag! 'Periodic' do
172
+ xml.tag! 'PeriodicList', "count" => 1 do
173
+ xml.tag! 'PeriodicItem', "ID" => 1 do
174
+ xml << body
175
+ end
176
+ end
177
+ end
178
+ end
179
+
180
+ xml.target!
181
+ end
182
+
183
+ def commit(action, request)
184
+ response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, build_request(action, request)))
185
+
186
+ Response.new(success?(response), message_from(response), response,
187
+ :test => test?,
188
+ :authorization => authorization_from(response)
189
+ )
190
+ end
191
+
192
+ def commit_periodic(request)
193
+ response = parse(ssl_post(test? ? TEST_PERIODIC_URL : LIVE_PERIODIC_URL, build_periodic_request(request)))
194
+ Response.new(success?(response), message_from(response), response,
195
+ :test => test?,
196
+ :authorization => authorization_from(response)
197
+ )
198
+ end
199
+
200
+ def success?(response)
201
+ SUCCESS_CODES.include?(response[:response_code])
202
+ end
203
+
204
+ def authorization_from(response)
205
+ response[:txn_id]
206
+ end
207
+
208
+ def message_from(response)
209
+ response[:response_text] || response[:status_description]
210
+ end
211
+
212
+ def expdate(credit_card)
213
+ "#{format(credit_card.month, :two_digits)}/#{format(credit_card.year, :two_digits)}"
214
+ end
215
+
216
+ def parse(body)
217
+ xml = REXML::Document.new(body)
218
+
219
+ response = {}
220
+
221
+ xml.root.elements.to_a.each do |node|
222
+ parse_element(response, node)
223
+ end
224
+
225
+ response
226
+ end
227
+
228
+ def parse_element(response, node)
229
+ if node.has_elements?
230
+ node.elements.each{|element| parse_element(response, element) }
231
+ else
232
+ response[node.name.underscore.to_sym] = node.text
233
+ end
234
+ end
235
+
236
+ # YYYYDDMMHHNNSSKKK000sOOO
237
+ def generate_timestamp
238
+ time = Time.now.utc
239
+ time.strftime("%Y%d%m%H%M%S#{time.usec}+000")
240
+ end
241
+
242
+ end
243
+ end
244
+ end
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  require 'rexml/document'
2
3
 
3
4
  module ActiveMerchant #:nodoc:
@@ -8,27 +9,32 @@ module ActiveMerchant #:nodoc:
8
9
  # communication between Ogone systems and your e-commerce website.
9
10
  #
10
11
  # This implementation follows the specification provided in the DirectLink integration
11
- # guide version 2.4 (December 2008), available here:
12
+ # guide version 4.2.0 (26 October 2011), available here:
12
13
  # https://secure.ogone.com/ncol/Ogone_DirectLink_EN.pdf
13
14
  #
14
15
  # 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
+ # the Alias Manager Option guide version 3.2.0 (26 October 2011) available here:
16
17
  # https://secure.ogone.com/ncol/Ogone_Alias_EN.pdf
17
18
  #
18
- # It was last tested on Release 04.79 of Ogone e-Commerce (dated 11/02/2009).
19
+ # It was last tested on Release 4.89 of Ogone DirectLink + AliasManager (26 October 2011).
19
20
  #
20
- # For any questions or comments, please contact Nicolas Jacobeus (nj@belighted.com).
21
+ # For any questions or comments, please contact one of the following:
22
+ # - Nicolas Jacobeus (nj@belighted.com),
23
+ # - Sébastien Grosjean (public@zencocoon.com),
24
+ # - Rémy Coutable (remy@jilion.com).
21
25
  #
22
- # == Example use:
26
+ # == Usage
23
27
  #
24
28
  # 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
+ # :login => "my_ogone_psp_id",
30
+ # :user => "my_ogone_user_id",
31
+ # :password => "my_ogone_pswd",
32
+ # :signature => "my_ogone_sha_signature", # Only if you configured your Ogone environment so.
33
+ # :signature_encryptor => "sha512", # Can be "sha1" (default), "sha256" or "sha512".
34
+ # # Must be the same as the one configured in your Ogone account.
29
35
  # )
30
36
  #
31
- # # set up credit card obj as in main ActiveMerchant example
37
+ # # set up credit card object as in main ActiveMerchant example
32
38
  # creditcard = ActiveMerchant::Billing::CreditCard.new(
33
39
  # :type => 'visa',
34
40
  # :number => '4242424242424242',
@@ -47,18 +53,21 @@ module ActiveMerchant #:nodoc:
47
53
  # puts response.message # Retrieve the message returned by Ogone
48
54
  # puts response.authorization # Retrieve the unique transaction ID returned by Ogone
49
55
  #
50
- # To use the alias feature, simply add :alias in the options hash:
56
+ # == Alias feature
51
57
  #
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
58
+ # To use the alias feature, simply add :store in the options hash:
59
+ #
60
+ # # Associate the alias to that credit card
61
+ # gateway.purchase(1000, creditcard, :order_id => "1", :store => "myawesomecustomer")
62
+ #
63
+ # # You can use the alias instead of the credit card for subsequent orders
64
+ # gateway.purchase(2000, "myawesomecustomer", :order_id => "2")
54
65
  #
55
66
  class OgoneGateway < Gateway
56
67
 
57
68
  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' }
69
+ :order => 'https://secure.ogone.com/ncol/%s/orderdirect.asp',
70
+ :maintenance => 'https://secure.ogone.com/ncol/%s/maintenancedirect.asp'
62
71
  }
63
72
 
64
73
  CVV_MAPPING = { 'OK' => 'M',
@@ -68,8 +77,12 @@ module ActiveMerchant #:nodoc:
68
77
  AVS_MAPPING = { 'OK' => 'M',
69
78
  'KO' => 'N',
70
79
  'NO' => 'R' }
80
+
71
81
  SUCCESS_MESSAGE = "The transaction was successful"
72
82
 
83
+ OGONE_NO_SIGNATURE_DEPRECATION_MESSAGE = "Signature usage will be required from a future release of ActiveMerchant's Ogone Gateway. Please update your Ogone account to use it."
84
+ OGONE_LOW_ENCRYPTION_DEPRECATION_MESSAGE = "SHA512 signature encryptor will be required from a future release of ActiveMerchant's Ogone Gateway. Please update your Ogone account to use it."
85
+
73
86
  self.supported_countries = ['BE', 'DE', 'FR', 'NL', 'AT', 'CH']
74
87
  # also supports Airplus and UATP
75
88
  self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :discover, :jcb, :maestro]
@@ -108,7 +121,7 @@ module ActiveMerchant #:nodoc:
108
121
 
109
122
  # Complete a previously authorized transaction.
110
123
  def capture(money, authorization, options = {})
111
- post = {}
124
+ post = {}
112
125
  add_authorization(post, reference_from(authorization))
113
126
  add_invoice(post, options)
114
127
  add_customer_data(post, options)
@@ -124,7 +137,7 @@ module ActiveMerchant #:nodoc:
124
137
  end
125
138
 
126
139
  # Credit the specified account by a specific amount.
127
- def credit(money, identification_or_credit_card, options = {})
140
+ def credit(money, identification_or_credit_card, options = {})
128
141
  if reference_transaction?(identification_or_credit_card)
129
142
  deprecated CREDIT_DEPRECATION_MESSAGE
130
143
  # Referenced credit: refund of a settled transaction
@@ -133,34 +146,35 @@ module ActiveMerchant #:nodoc:
133
146
  perform_non_referenced_credit(money, identification_or_credit_card, options)
134
147
  end
135
148
  end
136
-
149
+
137
150
  # Refund of a settled transaction
138
- def refund(money, reference, options = {})
151
+ def refund(money, reference, options = {})
139
152
  perform_reference_credit(money, reference, options)
140
153
  end
141
154
 
142
155
  def test?
143
156
  @options[:test] || super
144
157
  end
145
-
158
+
146
159
  private
160
+
147
161
  def reference_from(authorization)
148
162
  authorization.split(";").first
149
163
  end
150
-
164
+
151
165
  def reference_transaction?(identifier)
152
- return false unless identifier.is_a?(String)
166
+ return false unless identifier.is_a?(String)
153
167
  reference, action = identifier.split(";")
154
168
  !action.nil?
155
169
  end
156
-
170
+
157
171
  def perform_reference_credit(money, payment_target, options = {})
158
172
  post = {}
159
173
  add_authorization(post, reference_from(payment_target))
160
174
  add_money(post, money, options)
161
- commit('RFD', post)
175
+ commit('RFD', post)
162
176
  end
163
-
177
+
164
178
  def perform_non_referenced_credit(money, payment_target, options = {})
165
179
  # Non-referenced credit: acts like a reverse purchase
166
180
  post = {}
@@ -171,31 +185,32 @@ module ActiveMerchant #:nodoc:
171
185
  add_money(post, money, options)
172
186
  commit('RFD', post)
173
187
  end
174
-
188
+
175
189
  def add_payment_source(post, payment_source, options)
176
190
  if payment_source.is_a?(String)
177
191
  add_alias(post, payment_source)
178
- add_eci(post, '9')
192
+ add_eci(post, options[:eci] || '9')
179
193
  else
180
194
  add_alias(post, options[:store])
195
+ add_eci(post, options[:eci] || '7')
181
196
  add_creditcard(post, payment_source)
182
197
  end
183
- end
184
-
198
+ end
199
+
185
200
  def add_eci(post, eci)
186
- add_pair post, 'ECI', eci
201
+ add_pair post, 'ECI', eci.to_s
187
202
  end
188
-
203
+
189
204
  def add_alias(post, _alias)
190
- add_pair post, 'ALIAS', _alias
205
+ add_pair post, 'ALIAS', _alias
191
206
  end
192
207
 
193
208
  def add_authorization(post, authorization)
194
- add_pair post, 'PAYID', authorization
209
+ add_pair post, 'PAYID', authorization
195
210
  end
196
211
 
197
212
  def add_money(post, money, options)
198
- add_pair post, 'currency', options[:currency] || currency(money)
213
+ add_pair post, 'currency', options[:currency] || @options[:currency] || currency(money)
199
214
  add_pair post, 'amount', amount(money)
200
215
  end
201
216
 
@@ -226,35 +241,39 @@ module ActiveMerchant #:nodoc:
226
241
  end
227
242
 
228
243
  def parse(body)
229
- xml = REXML::Document.new(body)
230
- convert_attributes_to_hash(xml.root.attributes)
244
+ xml_root = REXML::Document.new(body).root
245
+ convert_attributes_to_hash(xml_root.attributes)
231
246
  end
232
247
 
233
248
  def commit(action, parameters)
234
- add_pair parameters, 'PSPID', @options[:login]
235
- add_pair parameters, 'USERID', @options[:user]
236
- add_pair parameters, 'PSWD', @options[:password]
237
- url = URLS[test? ? :test : :production][parameters['PAYID'] ? :maintenance : :order ]
249
+ add_pair parameters, 'PSPID', @options[:login]
250
+ add_pair parameters, 'USERID', @options[:user]
251
+ add_pair parameters, 'PSWD', @options[:password]
252
+
253
+ url = URLS[parameters['PAYID'] ? :maintenance : :order] % [test? ? "test" : "prod"]
238
254
  response = parse(ssl_post(url, post_data(action, parameters)))
239
- options = { :authorization => [response["PAYID"], action].join(";"),
240
- :test => test?,
241
- :avs_result => { :code => AVS_MAPPING[response["AAVCheck"]] },
242
- :cvv_result => CVV_MAPPING[response["CVCCheck"]] }
255
+
256
+ options = {
257
+ :authorization => [response["PAYID"], action].join(";"),
258
+ :test => test?,
259
+ :avs_result => { :code => AVS_MAPPING[response["AAVCheck"]] },
260
+ :cvv_result => CVV_MAPPING[response["CVCCheck"]]
261
+ }
243
262
  Response.new(successful?(response), message_from(response), response, options)
244
263
  end
245
-
264
+
246
265
  def successful?(response)
247
266
  response["NCERROR"] == "0"
248
267
  end
249
268
 
250
269
  def message_from(response)
251
- if successful?(response)
270
+ if successful?(response)
252
271
  SUCCESS_MESSAGE
253
272
  else
254
273
  format_error_message(response["NCERRORPLUS"])
255
274
  end
256
275
  end
257
-
276
+
258
277
  def format_error_message(message)
259
278
  raw_message = message.to_s.strip
260
279
  case raw_message
@@ -268,16 +287,35 @@ module ActiveMerchant #:nodoc:
268
287
  end
269
288
 
270
289
  def post_data(action, parameters = {})
271
- add_pair parameters, 'Operation' , action
272
- if @options[:signature] # the user wants a SHA-1 signature
273
- string = ['orderID','amount','currency','CARDNO','PSPID','Operation','ALIAS'].map{|s|parameters[s]}.join + @options[:signature]
274
- add_pair parameters, 'SHASign' , Digest::SHA1.hexdigest(string)
290
+ add_pair parameters, 'Operation', action
291
+ @options[:signature] ? add_signature(parameters) : deprecated(OGONE_NO_SIGNATURE_DEPRECATION_MESSAGE)
292
+ parameters.to_query
293
+ end
294
+
295
+ def add_signature(parameters)
296
+ deprecated(OGONE_LOW_ENCRYPTION_DEPRECATION_MESSAGE) unless @options[:signature_encryptor] == 'sha512'
297
+
298
+ sha_encryptor = case @options[:signature_encryptor]
299
+ when 'sha256'
300
+ Digest::SHA256
301
+ when 'sha512'
302
+ Digest::SHA512
303
+ else
304
+ Digest::SHA1
305
+ end
306
+
307
+ string_to_digest = if @options[:signature_encryptor]
308
+ parameters.sort { |a, b| a[0].upcase <=> b[0].upcase }.map { |k, v| "#{k.upcase}=#{v}" }.join(@options[:signature])
309
+ else
310
+ %w[orderID amount currency CARDNO PSPID Operation ALIAS].map { |key| parameters[key] }.join
275
311
  end
276
- parameters.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
312
+ string_to_digest << @options[:signature]
313
+
314
+ add_pair parameters, 'SHASign', sha_encryptor.hexdigest(string_to_digest).upcase
277
315
  end
278
316
 
279
- def add_pair(post, key, value, options = {})
280
- post[key] = value if !value.blank? || options[:required]
317
+ def add_pair(post, key, value)
318
+ post[key] = value if !value.blank?
281
319
  end
282
320
 
283
321
  def convert_attributes_to_hash(rexml_attributes)