lib/active_merchant/billing/gateways/ogone.rb in activemerchant-1.52.0 vs lib/active_merchant/billing/gateways/ogone.rb in activemerchant-1.53.0
- old
+ new
@@ -149,16 +149,17 @@
end
# Verify and reserve the specified amount on the account, without actually doing the transaction.
def authorize(money, payment_source, options = {})
post = {}
+ action = (payment_source.brand == "mastercard") ? "PAU" : "RES"
add_invoice(post, options)
add_payment_source(post, payment_source, options)
add_address(post, payment_source, options)
add_customer_data(post, options)
add_money(post, money, options)
- commit('RES', post)
+ commit(action, post)
end
# Verify and transfer the specified amount.
def purchase(money, payment_source, options = {})
post = {}
@@ -211,10 +212,22 @@
response = authorize(@options[:store_amount] || 1, payment_source, options)
void(response.authorization) if response.success?
response
end
+ def supports_scrubbing?
+ true
+ end
+
+ def scrub(transcript)
+ transcript.
+ gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
+ gsub(%r((&?cardno=)[^&]*)i, '\1[FILTERED]').
+ gsub(%r((&?cvc=)[^&]*)i, '\1[FILTERED]').
+ gsub(%r((&?pswd=)[^&]*)i, '\1[FILTERED]')
+ end
+
private
def reference_from(authorization)
authorization.split(";").first
end
@@ -270,10 +283,12 @@
add_pair post, 'HTTP_ACCEPT', options[:http_accept] || "*/*"
add_pair post, 'HTTP_USER_AGENT', options[:http_user_agent] if options[:http_user_agent]
add_pair post, 'ACCEPTURL', options[:accept_url] if options[:accept_url]
add_pair post, 'DECLINEURL', options[:decline_url] if options[:decline_url]
add_pair post, 'EXCEPTIONURL', options[:exception_url] if options[:exception_url]
+ add_pair post, 'CANCELURL', options[:cancel_url] if options[:cancel_url]
+ add_pair post, 'PARAMVAR', options[:paramvar] if options[:paramvar]
add_pair post, 'PARAMPLUS', options[:paramplus] if options[:paramplus]
add_pair post, 'COMPLUS', options[:complus] if options[:complus]
add_pair post, 'LANGUAGE', options[:language] if options[:language]
end
@@ -389,26 +404,46 @@
if @options[:signature].blank?
ActiveMerchant.deprecated(OGONE_NO_SIGNATURE_DEPRECATION_MESSAGE) unless(@options[:signature_encryptor] == "none")
return
end
- sha_encryptor = case @options[:signature_encryptor]
- when 'sha256'
- Digest::SHA256
- when 'sha512'
- Digest::SHA512
- else
- Digest::SHA1
- end
+ add_pair parameters, 'SHASign', calculate_signature(parameters, @options[:signature_encryptor], @options[:signature])
+ end
- string_to_digest = if @options[:signature_encryptor]
- parameters.sort { |a, b| a[0].upcase <=> b[0].upcase }.map { |k, v| "#{k.upcase}=#{v}" }.join(@options[:signature])
+ def calculate_signature(signed_parameters, algorithm, secret)
+ return legacy_calculate_signature(signed_parameters, secret) unless algorithm
+
+ sha_encryptor = case algorithm
+ when 'sha256'
+ Digest::SHA256
+ when 'sha512'
+ Digest::SHA512
+ when 'sha1'
+ Digest::SHA1
else
- %w[orderID amount currency CARDNO PSPID Operation ALIAS].map { |key| parameters[key] }.join
+ raise "Unknown signature algorithm #{algorithm}"
end
- string_to_digest << @options[:signature]
- add_pair parameters, 'SHASign', sha_encryptor.hexdigest(string_to_digest).upcase
+ sha_encryptor.hexdigest(
+ signed_parameters.sort_by{|k,v| k.upcase}.map{|k, v| "#{k.upcase}=#{v}#{secret}"}.join("")
+ ).upcase
+ end
+
+ def legacy_calculate_signature(parameters, secret)
+ Digest::SHA1.hexdigest(
+ (
+ %w(
+ orderID
+ amount
+ currency
+ CARDNO
+ PSPID
+ Operation
+ ALIAS
+ ).map{|key| parameters[key]} +
+ [secret]
+ ).join("")
+ ).upcase
end
def add_pair(post, key, value)
post[key] = value if !value.blank?
end