lib/active_merchant/billing/gateways/paysafe.rb in activemerchant-1.125.0 vs lib/active_merchant/billing/gateways/paysafe.rb in activemerchant-1.126.0

- old
+ new

@@ -93,11 +93,11 @@ commit(:post, 'profiles', post, options) end def unstore(pm_profile_id) - commit_for_unstore(:delete, "profiles/#{pm_profile_id}", nil, nil) + commit(:delete, "profiles/#{get_id_from_store_auth(pm_profile_id)}", nil, nil) end def supports_scrubbing? true end @@ -177,11 +177,11 @@ end def add_payment(post, payment) if payment.is_a?(String) post[:card] = {} - post[:card][:paymentToken] = payment + post[:card][:paymentToken] = get_pm_from_store_auth(payment) else post[:card] = { cardExpiry: {} } post[:card][:cardNum] = payment.number post[:card][:cardExpiry][:month] = payment.month post[:card][:cardExpiry][:year] = payment.year @@ -297,11 +297,11 @@ when false post[:storedCredential][:occurrence] = 'SUBSEQUENT' end case options[:stored_credential][:reason_type] - when 'recurring' || 'installment' + when 'recurring', 'installment' post[:storedCredential][:type] = 'RECURRING' when 'unscheduled' if options[:stored_credential][:initiator] == 'merchant' post[:storedCredential][:type] = 'TOPUP' elsif options[:stored_credential][:initiator] == 'cardholder' @@ -319,10 +319,12 @@ payment.brand == 'master' end def parse(body) + return {} if body.empty? + JSON.parse(body) end def commit(method, action, parameters, options) url = url(action) @@ -340,21 +342,10 @@ test: test?, error_code: success ? nil : error_code_from(response) ) end - def commit_for_unstore(method, action, parameters, options) - url = url(action) - response = raw_ssl_request(method, url, post_data(parameters, options), headers) - success = true if response.code == '200' - - Response.new( - success, - message: response.message - ) - end - def headers { 'Content-Type' => 'application/json', 'Authorization' => 'Basic ' + Base64.strict_encode64("#{@options[:username]}:#{@options[:password]}") } @@ -382,13 +373,22 @@ "Error(s)- code:#{response['error']['code']}, message:#{response['error']['message']}" end def authorization_from(action, response) if action == 'profiles' - response['cards'].first['paymentToken'] + pm = response['cards'].first['paymentToken'] + "#{pm}|#{response['id']}" else response['id'] end + end + + def get_pm_from_store_auth(authorization) + authorization.split('|')[0] + end + + def get_id_from_store_auth(authorization) + authorization.split('|')[1] end def post_data(parameters = {}, options = {}) return unless parameters.present?