0
votes

I am using the quickbooks sdk to connect with a quickbook online account. I am able to connect a get data like customers and invoice without a problem. But I am unable to create an invoice using the sdk. Here is my code:

$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);

When a run this an invoice isn't created and I get this error:

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

I don't think the Line data is getting added correctly. How do I correctly add line data or is it something else?

Thanks

1

1 Answers

0
votes

You have to pass customer id as string as follows

$invoiceObj->CustomerRef = 5;

Below is working sample code

Sample Code