quickbooks online sdk创建发票

时间:2014-05-02 23:32:16

标签: sdk quickbooks invoice

我正在使用quickbooks sdk连接quickbook在线帐户。我可以毫无问题地连接客户和发票等获取数据。但是我无法使用sdk创建发票。这是我的代码:

$token = unserialize($_SESSION['token']);
    $requestValidator = new OAuthRequestValidator(
        $token['oauth_token'], $token['oauth_token_secret'], OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET);
    $realmId = $_SESSION['realmId'];
    $serviceType = $_SESSION['dataSource'];
    $serviceContext = new ServiceContext($realmId, $serviceType, $requestValidator);

    $dataService = new DataService($serviceContext);

    //create an invoice
    $invoiceObj = new IPPInvoice();
    $invoiceObj->CustomerRef = 5;
    $invoiceObj->Amount = 12.00;
    $invoiceObj->DocNumber = 9999;
    $invoiceObj->TaxnDate = "2014-05-01";
    $Line = new IPPline();
    $Line->DetailType ='SalesItemLineDetail';
    //$Line->Amount = 10;
    $Line->setDescription = 'Test description goes here.';
    $saleItemLineDetail = new IPPSalesItemLineDetail();
    $saleItemLineDetail->ItemRef = 1;
    $saleItemLineDetail->Quantity = 1;
    $saleItemLineDetail->UnitPrice = 10.00;
    $line->SalesItemLineDetail = $saleItemLineDetail;
    $invoiceObj->Line = $line;
    $resultingInvoiceObj = $dataService->Add($invoiceObj);

运行时,发票未创建,我收到此错误:

Fatal error: Uncaught IdsException: [0]: 2014-05-02 17:26:08 - /home/randy/test_apps/v3-php-sdk-2.0.4/DataService/DataService.php - 340 - CheckNullResponseAndThrowException - Response Null or Empty thrown in /home/randy/test_apps/v3-php-sdk-2.0.4/Core/CoreHelper.php on line 95

我认为Line数据无法正确添加。如何正确添加行数据还是其他内容?

由于

1 个答案:

答案 0 :(得分:0)

您必须将客户ID传递为字符串,如下所示

$invoiceObj->CustomerRef = 5;

以下是工作示例代码

Sample Code