使用PHP DevKit在线设置QuickBooks付款

时间:2015-06-15 17:47:13

标签: php quickbooks quickbooks-online

我正在尝试设置一个将发票添加到我们的Quickbooks帐户的流程,如果客户被标记为已付款,则会设置付款以显示该付款。发票设置按预期工作,但当我尝试将发票ID用于设置付款时,它似乎没有设置它。

以下是代码:

if(isset($companyName) && $companyName == $customerName) {
     $InvoiceService = new QuickBooks_IPP_Service_Invoice();

     $Invoice = new QuickBooks_IPP_Object_Invoice();

     $Invoice->setDocNumber(1000 + $transaction->salesHistoryId);
     $Invoice->setTxnDate($transaction->dateOrdered);

     $Line = new QuickBooks_IPP_Object_Line();
     $Line->setDescription('Annual Payment');
     $Line->setDetailType('SalesItemLineDetail');
     $Line->setAmount($transaction->contractPrice);

     $SalesItemLineDetail = new QuickBooks_IPP_Object_SalesItemLineDetail();
     $SalesItemLineDetail->setItemRef('7');
     $SalesItemLineDetail->setUnitPrice(money_format('%i',$transaction->contractPrice));
     $SalesItemLineDetail->setQty(1);

     $Line->addSalesItemLineDetail($SalesItemLineDetail);

     $Invoice->addLine($Line);

     $Invoice->setCustomerRef($customerId);
     $invoiceId = $Invoice->getId();
     echo ($invoiceId);
     $resp = $InvoiceService->add($Context, $realm, $Invoice);
 }

if($transaction->paid == '1'){

     $PaymentService = new QuickBooks_IPP_Service_Payment();
     $Payment = new QuickBooks_IPP_Object_Payment();

     $Payment->setPaymentRefNum('Invoice #'. (1000 + $transaction->salesHistoryId));
     $Payment->setTxnDate($transaction->dateOrdered);;
     $Payment->setTotalAmt($transaction->contractPrice);

     $Line = new QuickBooks_IPP_Object_Line();
     $Line->setAmount($transaction->contractPrice);

     $LinkedTxn = new QuickBooks_IPP_Object_LinkedTxn();
     $LinkedTxn->setTxnId($invoiceId);
     $LinkedTxn->setTxnType('Invoice');

     $Line->setLinkedTxn($LinkedTxn);
     $Payment->addLine($Line);
     $Payment->setCustomerRef($customerId);
     $resp = $PaymentService->add($Context, $realm, $Payment);
}

我的IPP-> lastRequest()的结果:

<Payment xmlns="http://schema.intuit.com/finance/v3">
<Line xmlns="http://schema.intuit.com/finance/v3">
    <Amount>1295</Amount>
    <LinkedTxn xmlns="http://schema.intuit.com/finance/v3">
        <TxnId></TxnId>
        <TxnType>Invoice</TxnType>
    </LinkedTxn>
</Line>
<PaymentRefNum>Invoice #3310</PaymentRefNum>
<TxnDate>2015-06-14 00:00:00</TxnDate>
<TotalAmt>1295</TotalAmt>
<CustomerRef>1930</CustomerRef>
</Payment>HTTP/1.1 400 Bad Request
Date: Mon, 15 Jun 2015 17:24:45 GMT
Content-Type: application/xml
Content-Length: 270
intuit_tid: 2b6330f0-3df5-4336-911d-0ed43acafdd0
Vary: Accept-Encoding
Via: 1.1 ipp-gateway-ap06
Content-Encoding: gzip
Connection: close

IPP-> lastResponse()的结果:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2015-06-15T10:24:41.206-07:00"><Fault type="ValidationFault"><Error code="2030" element="LinkedTxn.TxnId"><Message>Invalid ID</Message><Detail>Id should be a valid number. Supplied value:</Detail></Error></Fault></IntuitResponse><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

我猜是因为:

<LinkedTxn xmlns="http://schema.intuit.com/finance/v3">
    <TxnId></TxnId>
    <TxnType>Invoice</TxnType>
</LinkedTxn>

显示没有TxnId,这就是问题,但我不确定如何解决这个问题。任何帮助表示赞赏。谢谢!

1 个答案:

答案 0 :(得分:1)

新发票在创建后之前没有Id值。它就像SQL数据库中的任何正常自动增量id值一样。

所以如果你在这里查看你的代码:

 $invoiceId = $Invoice->getId();
 echo ($invoiceId);
 $resp = $InvoiceService->add($Context, $realm, $Invoice);

$invoiceId的值总是将是null,因为您还没有创建发票。你以后创建两行。所以,它还没有Id。它不能。它不存在。

$InvoiceService会返回发票Id值,因此只需将您的代码更改为:

 $invoiceId = $InvoiceService->add($Context, $realm, $Invoice);

你会全力以赴。