Skip to content

Instantly share code, notes, and snippets.

@cupnoodle
Created April 17, 2018 07:26
Show Gist options
  • Save cupnoodle/fdde7207b2acf4ddddabde6d998c013e to your computer and use it in GitHub Desktop.
Save cupnoodle/fdde7207b2acf4ddddabde6d998c013e to your computer and use it in GitHub Desktop.
Quickbooks error
require 'quickbooks-ruby'
require 'oauth2'
require 'dotenv'
Quickbooks.sandbox_mode = true
OAUTH_CONSUMER_KEY = ENV['OAUTH_CLIENT_ID']
OAUTH_CONSUMER_SECRET = ENV['OAUTH_CLIENT_SECRET']
qb_access_token = ENV['TOKEN']
qb_refresh_token = ENV['REFRESH_TOKEN']
realm_id = ENV['REALM_ID']
oauth_params = {
:site => "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"
}
client = OAuth2::Client.new(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, oauth_params)
access_token = OAuth2::AccessToken.new(client, qb_access_token, {refresh_token: qb_refresh_token})
access_token = access_token.refresh!
# generate invoice
invoice = Quickbooks::Model::Invoice.new
invoice.customer_id = 1
invoice.txn_date = DateTime.now.to_date
# invoice.doc_number = "1001" # my custom Invoice # - can leave blank to have Intuit auto-generate it
line_item = Quickbooks::Model::InvoiceLineItem.new
line_item.amount = 50
line_item.description = "Plush Baby Doll"
line_item.sales_item! do |detail|
detail.unit_price = 50
detail.quantity = 1
detail.item_id = 500 # Item ID here
end
invoice.line_items << line_item
service = Quickbooks::Service::Invoice.new
service.company_id = "123"
service.access_token = access_token
service.realm_id = realm_id
# error occur here
created_invoice = service.create(invoice)
puts created_invoice.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment