Good Day!
I am currently working on a QUICKBOOKS API payment and is using their DevKit https://github.com/consolibyte/quickbooks-php its working just fine, I can retrieve invoices and pay them individually. Now, I want to create a functionality that can pay multiple invoices in 1 payment. What I could think right now is doing a loop until all selected invoices gets paid individually but I guess its not the correct approach..
this is the code I got from the 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());
}
If I put them inside a loop, I am sure they will all get paid and also it will create multiple payments as well.
Is there any other much better ways to do this? please help. Thanks!
I made it work with this code
$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++;
}