Class: ActiveMerchant::Billing::QuickbooksGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/quickbooks.rb

Constant Summary collapse

BASE =
'/quickbooks/v4/payments'
ENDPOINT =
"#{BASE}/charges"
VOID_ENDPOINT =
"#{BASE}/txn-requests"
REFRESH_URI =
'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer'
STANDARD_ERROR_CODE_MAPPING =
{
  # Fraud Warnings
  'PMT-1000' => STANDARD_ERROR_CODE[:processing_error],   # payment was accepted, but refund was unsuccessful
  'PMT-1001' => STANDARD_ERROR_CODE[:invalid_cvc],        # payment processed, but cvc was invalid
  'PMT-1002' => STANDARD_ERROR_CODE[:incorrect_address],  # payment processed, incorrect address info
  'PMT-1003' => STANDARD_ERROR_CODE[:processing_error],   # payment processed, address info couldn't be validated

  # Fraud Errors
  'PMT-2000' => STANDARD_ERROR_CODE[:incorrect_cvc],      # Incorrect CVC
  'PMT-2001' => STANDARD_ERROR_CODE[:invalid_cvc],        # CVC check unavaliable
  'PMT-2002' => STANDARD_ERROR_CODE[:incorrect_address],  # Incorrect address
  'PMT-2003' => STANDARD_ERROR_CODE[:incorrect_address],  # Address info unavailable

  'PMT-3000' => STANDARD_ERROR_CODE[:processing_error],   # Merchant account could not be validated

  # Invalid Request
  'PMT-4000' => STANDARD_ERROR_CODE[:processing_error],   # Object is invalid
  'PMT-4001' => STANDARD_ERROR_CODE[:processing_error],   # Object not found
  'PMT-4002' => STANDARD_ERROR_CODE[:processing_error],   # Object is required

  # 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.
}
FRAUD_WARNING_CODES =
['PMT-1000', 'PMT-1001', 'PMT-1002', 'PMT-1003']

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#add_field_to_post_if_present, #add_fields_to_post_if_present, card_brand, #card_brand, #generate_unique_id, inherited, supported_countries, #supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #test?

Methods included from CreditCardFormatting

#expdate, #format

Methods included from PostsData

included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request

Constructor Details

#initialize(options = {}) ⇒ QuickbooksGateway

Returns a new instance of QuickbooksGateway.



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/active_merchant/billing/gateways/quickbooks.rb', line 50

def initialize(options = {})
  # Quickbooks is deprecating OAuth 1.0 on December 17, 2019.
  # OAuth 2.0 requires a client_id, client_secret, access_token, and refresh_token
  # To maintain backwards compatibility, check for the presence of a refresh_token (only specified for OAuth 2.0)
  # When present, validate that all OAuth 2.0 options are present
  if options[:refresh_token]
    requires!(options, :client_id, :client_secret, :access_token, :refresh_token)
  else
    requires!(options, :consumer_key, :consumer_secret, :access_token, :token_secret, :realm)
  end
  @options = options
  super
end

Instance Method Details

#authorize(money, payment, options = {}) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/active_merchant/billing/gateways/quickbooks.rb', line 74

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, options)
end

#capture(money, authorization, options = {}) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/active_merchant/billing/gateways/quickbooks.rb', line 84

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, options)
end

#purchase(money, payment, options = {}) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/active_merchant/billing/gateways/quickbooks.rb', line 64

def purchase(money, payment, options = {})
  post = {}
  add_amount(post, money, options)
  add_charge_data(post, payment, options)
  post[:capture] = 'true'

  response = commit(ENDPOINT, post)
  check_token_response(response, ENDPOINT, post, options)
end

#refreshObject



115
116
117
118
# File 'lib/active_merchant/billing/gateways/quickbooks.rb', line 115

def refresh
  response = refresh_access_token
  response_object(response)
end

#refund(money, authorization, options = {}) ⇒ Object



94
95
96
97
98
99
100
101
102
# File 'lib/active_merchant/billing/gateways/quickbooks.rb', line 94

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, options)
end

#scrub(transcript) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/active_merchant/billing/gateways/quickbooks.rb', line 124

def scrub(transcript)
  transcript.
    gsub(%r((realm=\")\w+), '\1[FILTERED]').
    gsub(%r((oauth_consumer_key=\")\w+), '\1[FILTERED]').
    gsub(%r((oauth_nonce=\")\w+), '\1[FILTERED]').
    gsub(%r((oauth_signature=\")[a-zA-Z%0-9]+), '\1[FILTERED]').
    gsub(%r((oauth_token=\")\w+), '\1[FILTERED]').
    gsub(%r((number\D+)\d{16}), '\1[FILTERED]').
    gsub(%r((cvc\D+)\d{3}), '\1[FILTERED]').
    gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
    gsub(%r((access_token\\?":\\?")[\w\-\.]+)i, '\1[FILTERED]').
    gsub(%r((refresh_token\\?":\\?")\w+), '\1[FILTERED]').
    gsub(%r((refresh_token=)\w+), '\1[FILTERED]').
    gsub(%r((Authorization: Bearer )[\w\-\.]+)i, '\1[FILTERED]\2')
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/active_merchant/billing/gateways/quickbooks.rb', line 120

def supports_scrubbing?
  true
end

#verify(credit_card, options = {}) ⇒ Object



111
112
113
# File 'lib/active_merchant/billing/gateways/quickbooks.rb', line 111

def verify(credit_card, options = {})
  authorize(1.00, credit_card, options)
end

#void(authorization, options = {}) ⇒ Object



104
105
106
107
108
109
# File 'lib/active_merchant/billing/gateways/quickbooks.rb', line 104

def void(authorization, options = {})
  _, request_id = split_authorization(authorization)

  response = commit(void_uri(request_id))
  check_token_response(response, void_uri(request_id), {}, options)
end