lib/active_merchant/billing/gateways/quickbooks.rb in activemerchant-1.101.0 vs lib/active_merchant/billing/gateways/quickbooks.rb in activemerchant-1.102.0

- old
+ new

@@ -9,11 +9,11 @@ self.supported_cardtypes = [:visa, :master, :american_express, :discover, :diners] self.homepage_url = 'http://payments.intuit.com' self.display_name = 'QuickBooks Payments' BASE = '/quickbooks/v4/payments' - ENDPOINT = "#{BASE}/charges" + ENDPOINT = "#{BASE}/charges" VOID_ENDPOINT = "#{BASE}/txn-requests" REFRESH_URI = 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer' # https://developer.intuit.com/docs/0150_payments/0300_developer_guides/error_handling @@ -40,11 +40,11 @@ # Transaction Declined 'PMT-5000' => STANDARD_ERROR_CODE[:card_declined], # Request was declined 'PMT-5001' => STANDARD_ERROR_CODE[:card_declined], # Merchant does not support given payment method # System Error - 'PMT-6000' => STANDARD_ERROR_CODE[:processing_error], # A temporary Issue prevented this request from being processed. + 'PMT-6000' => STANDARD_ERROR_CODE[:processing_error], # A temporary Issue prevented this request from being processed. } FRAUD_WARNING_CODES = ['PMT-1000', 'PMT-1001', 'PMT-1002', 'PMT-1003'] def initialize(options = {}) @@ -66,54 +66,59 @@ add_amount(post, money, options) add_charge_data(post, payment, options) post[:capture] = 'true' response = commit(ENDPOINT, post) - check_token_response(response, ENDPOINT, post) + check_token_response(response, ENDPOINT, post, options) end def authorize(money, payment, options = {}) post = {} add_amount(post, money, options) add_charge_data(post, payment, options) post[:capture] = 'false' response = commit(ENDPOINT, post) - check_token_response(response, ENDPOINT, post) + check_token_response(response, ENDPOINT, post, options) end def capture(money, authorization, options = {}) post = {} authorization, _ = split_authorization(authorization) post[:amount] = localized_amount(money, currency(money)) add_context(post, options) response = commit(capture_uri(authorization), post) - check_token_response(response, capture_uri(authorization), post) + check_token_response(response, capture_uri(authorization), post, options) end def refund(money, authorization, options = {}) post = {} post[:amount] = localized_amount(money, currency(money)) add_context(post, options) authorization, _ = split_authorization(authorization) response = commit(refund_uri(authorization), post) - check_token_response(response, refund_uri(authorization), post) + check_token_response(response, refund_uri(authorization), post, options) end def void(authorization, options = {}) _, request_id = split_authorization(authorization) response = commit(void_uri(request_id)) - check_token_response(response, void_uri(request_id)) + check_token_response(response, void_uri(request_id), {}, options) end def verify(credit_card, options = {}) authorize(1.00, credit_card, options) end + def refresh + response = refresh_access_token + response_object(response) + end + def supports_scrubbing? true end def scrub(transcript) @@ -274,12 +279,13 @@ 'Accept' => 'application/json', 'Authorization' => "Bearer #{@options[:access_token]}" } end - def check_token_response(response, endpoint, body = {}) + def check_token_response(response, endpoint, body = {}, options = {}) return response unless @options[:refresh_token] + return response unless options[:allow_refresh] return response unless response.params['code'] == 'AuthenticationFailed' refresh_access_token commit(endpoint, body) end @@ -295,14 +301,15 @@ 'Accept' => 'application/json', 'Authorization' => "Basic #{basic_auth}" } response = ssl_post(REFRESH_URI, data, headers) - response = JSON.parse(response) + json_response = JSON.parse(response) - @options[:access_token] = response['access_token'] if response['access_token'] - @options[:refresh_token] = response['refresh_token'] if response['refresh_token'] + @options[:access_token] = json_response['access_token'] if json_response['access_token'] + @options[:refresh_token] = json_response['refresh_token'] if json_response['refresh_token'] + response end def cvv_code_from(response) if response['errors'].present? FRAUD_WARNING_CODES.include?(response['errors'].first['code']) ? 'I' : '' @@ -312,10 +319,10 @@ end def success?(response) return FRAUD_WARNING_CODES.concat(['0']).include?(response['errors'].first['code']) if response['errors'] - !['DECLINED', 'CANCELLED'].include?(response['status']) + !['DECLINED', 'CANCELLED'].include?(response['status']) && !['AuthenticationFailed'].include?(response['code']) end def message_from(response) response['errors'].present? ? response['errors'].map { |error_hash| error_hash['message'] }.join(' ') : response['status'] end