使用 PHP DevKit 为 QuickBooks Online 设置支付

Setting up Payment for QuickBooks Online using PHP DevKit

我正在尝试设置将发票添加到我们的 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,这就是问题所在,但我不确定如何解决这个问题。任何帮助表示赞赏。谢谢!

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

因此,如果您在此处查看您的代码:

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

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

$InvoiceService returns 发票 Id 值,所以只需将您的代码更改为:

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

一切就绪。