2016-10-04 98 views
1

當我使用的QuickBook軌寶石(QuickBooks的-紅寶石)的QuickBook創建軌道

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

錯誤是:

所需的參數Line.DetailType在reques

缺少你在你的請求中指定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. 
+0

感謝,但我做一些小錯誤就是錯誤出現的原因。 – vipin