2017-07-19 177 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