当我使用Quickbook rails gem(quickbooks-ruby)创建发票时,我收到此错误
Quickbooks::IntuitRequestException (Required param missing, need to supply the required value for the API:
Required parameter Line.DetailType is missing in the request):
app/controllers/users_controller.rb:42:in `oauth_callback'
我的控制器
class UsersController < ApplicationController
def index
upload_service = Quickbooks::Service::Upload.new
# result = upload_service.upload("tmp/monkey.jpg", "image/jpeg", attachable_metadata)
end
def authenticate
callback = users_oauth_callback_url
token = QB_OAUTH_CONSUMER.get_request_token(:oauth_callback => callback)
session[:qb_request_token] = Marshal.dump(token)
redirect_to("https://appcenter.intuit.com/Connect/Begin?oauth_token=#{token.token}") and return
end
def oauth_callback
at = Marshal.load(session[:qb_request_token]).get_access_token(:oauth_verifier => params[:oauth_verifier])
session[:token] = at.token
session[:secret] = at.secret
session[:realm_id] = params['realmId']
end
def create_invoice
access_token = OAuth::AccessToken.new(QB_OAUTH_CONSUMER, session[:token], session[:secret] )
invoice = Quickbooks::Model::Invoice.new
invoice.customer_id = 123
invoice.txn_date = Date.civil(2013, 11, 20)
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 = session[:realm_id]
service.access_token = access_token
created_invoice = service.create(invoice)
puts created_invoice.id
redirect_to root_url
end
end
配置/初始化/ quickeebooks.rb
OAUTH_CONSUMER_KEY = "xxxxxxxxxxxxxxxxxxxxxxx"
OAUTH_CONSUMER_SECRET = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
::QB_OAUTH_CONSUMER = OAuth::Consumer.new(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, {
:site => "https://oauth.intuit.com",
:request_token_path => "/oauth/v1/get_request_token",
:authorize_url => "https://appcenter.intuit.com/Connect/Begin",
:access_token_path => "/oauth/v1/get_access_token"
})
答案 0 :(得分:0)
错误是:
请求
中缺少必需参数Line.DetailType
您是否在请求中指定了DetailType
。它看起来不像:
line_item = Quickbooks::Model::InvoiceLineItem.new
line_item.amount = 50
line_item.description = "Plush Baby Doll"
请参阅文档:
表示:
DetailType:
*required*
LineDetailTypeEnum
Set to SalesItemLineDetail for this type of line.