如何在1张付款QUICKBOOKS API中支付多张发票

时间:2017-07-19 10:00:59

标签: php api quickbooks quickbooks-online

美好的一天!

我目前正在处理QUICKBOOKS API付款并使用他们的DevKit https://github.com/consolibyte/quickbooks-php工作正常,我可以检索发票并单独付款。现在,我想创建一个可以在一次付款中支付多张发票的功能。我现在想的是做一个循环,直到所有选定的发票单独付款,但我想这不是正确的方法..

这是我从DevKit获得的代码

$PaymentService = new QuickBooks_IPP_Service_Payment();

// Create payment object
$Payment = new QuickBooks_IPP_Object_Payment();

$Payment->setPaymentRefNum('WEB123');
$Payment->setTxnDate('2014-02-11');
$Payment->setTotalAmt(10);

// Create line for payment (this details what it's applied to)
$Line = new QuickBooks_IPP_Object_Line();
$Line->setAmount(10);

// The line has a LinkedTxn node which links to the actual invoice
$LinkedTxn = new QuickBooks_IPP_Object_LinkedTxn();
$LinkedTxn->setTxnId('{-84}');
$LinkedTxn->setTxnType('Invoice');

$Line->setLinkedTxn($LinkedTxn);

$Payment->addLine($Line);

$Payment->setCustomerRef('{-67}');

// Send payment to QBO 
if ($resp = $PaymentService->add($Context, $realm, $Payment))
{
    print('Our new Payment ID is: [' . $resp . ']');
}
else
{
    print($PaymentService->lastError());
}

如果我把它们放在一个循环中,我相信它们都会得到报酬,而且它也会产生多次付款。

还有其他更好的方法吗?请帮忙。谢谢!

2 个答案:

答案 0 :(得分:1)

不止一次做这件事:

// The line has a LinkedTxn node which links to the actual invoice
$LinkedTxn = new QuickBooks_IPP_Object_LinkedTxn();
$LinkedTxn->setTxnId('{-84}');
$LinkedTxn->setTxnType('Invoice');

$Line->setLinkedTxn($LinkedTxn);

$Payment->addLine($Line);

例如:

foreach ($invoices as $invoice_id)
{
    // The line has a LinkedTxn node which links to the actual invoice
    $LinkedTxn = new QuickBooks_IPP_Object_LinkedTxn();
    $LinkedTxn->setTxnId($invoice_id);
    $LinkedTxn->setTxnType('Invoice');

    $Line->setLinkedTxn($LinkedTxn);

    $Payment->addLine($Line);
}

答案 1 :(得分:0)

我使用此代码

$c = 0;
foreach ($invoice_ids as $i) {
    $Line = new QuickBooks_IPP_Object_Line();
    $Line->setAmount($i_line_amount[$c]); //amount per line
    $LinkedTxn = new QuickBooks_IPP_Object_LinkedTxn();
    $LinkedTxn->setTxnId($i);
    $LinkedTxn->setTxnType('Invoice');
    $Line->setLinkedTxn($LinkedTxn);
    $Payment->addLine($Line);
    $c++;
  }
相关问题