如何使用XERO API更新发票?

时间:2020-01-27 18:00:00

标签: laravel api xero-api

我正在使用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;
    }

1 个答案:

答案 0 :(得分:0)

我们有一个示例应用程序,该示例应用程序显示了对诸如createInvoice之类的一些示例调用。但是,值得注意的是,最近更新了API的较新版本,以支持对发票创建和更新的批量调用:

旧方式

$result = $apiInstance->updateInvoice($xeroTenantId, $guid, $invoice); 

新方法

-> updateOrCreateInvoices是最新的方法。建议您查看一下功能已更改的正在运行的软件包的版本。

https://github.com/XeroAPI/xero-php-oauth2-app/blob/4bf74e915df1b0fee66f954ffcbdc331e762a06a/example.php#L1222

但是-通常,在具有发票ID和新编号的现有发票上进行POST,将使您能够对其进行更新。

{
  "InvoiceID": "292532ba-xxxx-xxxx-xxxx-60e7c39c4360",
  "InvoiceNumber": "INV-im-a-new-number"
}

enter image description here 希望这能解除您的封锁!

相关问题