lib/active_merchant/billing/gateways/mundipagg.rb in activemerchant-1.121.0 vs lib/active_merchant/billing/gateways/mundipagg.rb in activemerchant-1.123.0

- old
+ new

@@ -38,11 +38,11 @@ add_invoice(post, money, options) add_customer_data(post, options) unless payment.is_a?(String) add_shipping_address(post, options) add_payment(post, payment, options) add_submerchant(post, options) - + add_auth_key(post, options) commit('sale', post) end def authorize(money, payment, options = {}) post = {} @@ -50,10 +50,11 @@ add_customer_data(post, options) unless payment.is_a?(String) add_shipping_address(post, options) add_payment(post, payment, options) add_capture_flag(post, payment) add_submerchant(post, options) + add_auth_key(post, options) commit('authonly', post) end def capture(money, authorization, options = {}) post = {} @@ -227,13 +228,20 @@ post[:SubMerchant][:Address][:Country] = submerchant[:address][:country] if submerchant.dig(:address, :country) post[:SubMerchant][:Address][:Zip_Code] = submerchant[:address][:zip_code] if submerchant.dig(:address, :zip_code) end end - def headers + def add_auth_key(post, options) + if authorization_secret_key = options[:authorization_secret_key] + post[:authorization_secret_key] = authorization_secret_key + end + end + + def headers(authorization_secret_key = nil) + basic_token = authorization_secret_key || @options[:api_key] { - 'Authorization' => 'Basic ' + Base64.strict_encode64("#{@options[:api_key]}:"), + 'Authorization' => 'Basic ' + Base64.strict_encode64("#{basic_token}:"), 'Content-Type' => 'application/json', 'Accept' => 'application/json' } end @@ -257,14 +265,15 @@ end end def commit(action, parameters, auth = nil) url = url_for(action, auth) + authorization_secret_key = parameters[:authorization_secret_key] if parameters parameters.merge!(parameters[:payment][:credit_card].delete(:card)).delete(:payment) if action == 'store' response = if %w[refund void].include? action - parse(ssl_request(:delete, url, post_data(parameters), headers)) + parse(ssl_request(:delete, url, post_data(parameters), headers(authorization_secret_key))) else - parse(ssl_post(url, post_data(parameters), headers)) + parse(ssl_post(url, post_data(parameters), headers(authorization_secret_key))) end Response.new( success_from(response), message_from(response),