【问题标题】:How to update invoice using XERO API?如何使用 XERO API 更新发票?
【发布时间】:2020-01-27 18:00:00
【问题描述】:

我正在使用 xero api 将其与我的 web 应用程序集成以管理发票,目前我想通过发票 id 更新发票,我有一个帮助程序 xero.php 文件来处理 crud 操作。我有一个按发票 ID 获取发票的功能,我想更新 InvoiceNumber。更新发票的最佳方式是什么?

update_invoice_function

 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;
    }

【问题讨论】:

    标签: laravel api xero-api


    【解决方案1】:

    我们有一个示例应用程序,其中显示了对 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"
    }
    

    希望这不会阻止您!

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-09
    • 1970-01-01
    相关资源
    最近更新 更多