如何在 1 笔付款中支付多张发票 QUICKBOOKS API
How to pay multiple invoice in 1 payment QUICKBOOKS API
美好的一天!
我目前正在处理 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());
}
如果我把它们放在一个循环中,我相信它们都会得到报酬,而且还会产生多次支付。
还有其他更好的方法吗?请帮忙。谢谢!
只需多次执行此操作:
// 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);
}
我用这段代码让它工作
$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++;
}
美好的一天!
我目前正在处理 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());
}
如果我把它们放在一个循环中,我相信它们都会得到报酬,而且还会产生多次支付。
还有其他更好的方法吗?请帮忙。谢谢!
只需多次执行此操作:
// 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);
}
我用这段代码让它工作
$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++;
}