2017-07-19 175 views
1

美好的一天!如何在1笔付款中支付多个发票QUICKBOOKS API

我目前正在使用QUICKBOOKS API付款,并且正在使用DevKit https://github.com/consolibyte/quickbooks-php其工作正常,我可以检索发票并单独付款。现在,我想创建一项功能,可以支付1笔支付多个发票。我现在能想到的是做一个循环,直到所有选定的发票被单独付费,但我想它不是正确的方法..

这是我从的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()); 
} 

如果我把得到的代码他们在一个循环内,我相信他们都会得到报酬,同时也会创造多种付款方式。

有没有其他更好的方法来做到这一点?请帮忙。谢谢!

回答

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++; 
    } 
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); 
} 
+0

谢谢回答爵士..不应该我包含“$ Line = new QuickBooks_IPP_Object_Line(); $ Line-> setAmount(10);”设置每行的金额? – melvnberd