Update qbo.rb

This commit is contained in:
2020-01-04 12:14:05 -05:00
committed by GitHub
parent 87de865c00
commit 9b80485915

View File

@@ -20,13 +20,14 @@ class Qbo < ActiveRecord::Base
authorize_url: "https://appcenter.intuit.com/connect/oauth2", authorize_url: "https://appcenter.intuit.com/connect/oauth2",
token_url: "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer" token_url: "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer"
} }
oauth2_client = OAuth2::Client.new(ENV['OAUTH_CLIENT_ID'], ENV['OAUTH_CLIENT_SECRET'], oauth_params)
# Configure quickbooks-ruby-base to access our database # Configure quickbooks-ruby-base to access our database
Quickbooks::Base.configure do |c| #Quickbooks::Base.configure do |c|
c.persistent_token = 'qb_token' # c.persistent_token = 'qb_token'
c.persistent_secret = 'qb_secret' # c.persistent_secret = 'qb_secret'
c.persistent_company_id = 'company_id' # c.persistent_company_id = 'company_id'
end #end
def self.get_oauth_consumer def self.get_oauth_consumer
# Quickbooks Config Info # Quickbooks Config Info
@@ -36,7 +37,13 @@ class Qbo < ActiveRecord::Base
# Get a quickbooks base object for type # Get a quickbooks base object for type
# @params type of base # @params type of base
def self.get_base(type) def self.get_base(type)
Quickbooks::Base.new(first, type) access_token = OAuth2::AccessToken.new(oauth2_client, qb_secret, refresh_token: qb_secret)
#get a new refesh token if the current one is too old
new_access_token_object = access_token.refresh! if refresh_token_expires_at.to_date.past?
service = Quickbooks::Base.new(first, type)
service.company_id = company_id # also known as RealmID
service.access_token = access_token # the OAuth Access Token you have from above
return service
end end
# Get the QBO account # Get the QBO account