【问题标题】:How to pay multiple invoice in 1 payment QUICKBOOKS API如何在 1 个付款 QUICKBOOKS API 中支付多张发票
【发布时间】:2017-07-19 10:00:59
【问题描述】:

美好的一天!

我目前正在处理 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());
}

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

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

【问题讨论】:

    标签: php api quickbooks quickbooks-online


    【解决方案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);
    }
    

    【讨论】:

    • 感谢您回答先生.. 我不应该包括“$Line = new QuickBooks_IPP_Object_Line(); $Line->setAmount(10);”设置每行的金额?
    【解决方案2】:

    我用这段代码让它工作

    $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++;
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多