我正在使用xero api将其与Web应用程序集成以管理发票,当前我想通过发票ID更新发票,我有一个助手xero.php文件来处理原始操作。我有一个通过发票ID获取发票的功能,我想更新InvoiceNumber。更新发票的最佳方法是什么?
更新发票功能
public function update_invoice(){
$invoice_id = '******-***-****-****-************';
$updated_invoice = Xero::find_invoice_by_id($invoice_id);
$updated_invoice['response']->TotalDiscount = "1";
$updated_invoice['response']->Date = "2020-01-20";
$updated_invoice['response']->Status = "DRAFT";
$get_invoice_response = Xero::update_invoice_by_id($invoice_id,$updated_invoice['response']);
dd($get_invoice_response);
}
update_invoice_by_id函数
public static function update_invoice_by_id($invoice_id,$updated_invoice){
self::instanciate();
try{
$update = self::$xero->loadByGUID('Accounting\\Invoice',$invoice_id);
dd($update);
$update->jsonSerialize($updated_invoice);
$invoice_response = self::$xero->save($update);
$response = [
'error' => false,
'status' => 200,
'message' => 'Invoice updated successfully',
'response' => $invoice_response->getElements()
];
}
catch (Exception $e){
$response = [
'error' => true,
'status' => $e->getCode(),
'message' => $e->getMessage()
];
}
return $response;
}
答案 0 :(得分:0)
我们有一个示例应用程序,该示例应用程序显示了对诸如createInvoice之类的一些示例调用。但是,值得注意的是,最近更新了API的较新版本,以支持对发票创建和更新的批量调用:
$result = $apiInstance->updateInvoice($xeroTenantId, $guid, $invoice);
-> updateOrCreateInvoices
是最新的方法。建议您查看一下功能已更改的正在运行的软件包的版本。
但是-通常,在具有发票ID和新编号的现有发票上进行POST,将使您能够对其进行更新。
{
"InvoiceID": "292532ba-xxxx-xxxx-xxxx-60e7c39c4360",
"InvoiceNumber": "INV-im-a-new-number"
}