【问题标题】:Xero Api how to mark an invoice has been paidXero Api 如何标记发票已付款
【发布时间】:2020-06-30 04:05:15
【问题描述】:

我可以通过以下代码成功创建发票

$invoice = new Invoice;
        $invoice->setReference('Ref-' . $this->getRandNum())
            ->setDate(new DateTime(\Carbon\Carbon::parse($payment->created_at)->format('Y-m-d')))
            ->setDueDate(new DateTime(\Carbon\Carbon::parse($payment->created_at)->format('Y-m-d')))
            ->setContact($contact)
            ->setLineItems($lineitems)
            ->setStatus(Invoice::STATUS_AUTHORISED)
            ->setType(Invoice::TYPE_ACCREC)
            ->setLineAmountTypes(LineAmountTypes::INCLUSIVE)
            ->setAmountPaid($payment->total / 100)
            ->setInvoiceNumber($payment->stripe_id)
            ->setFullyPaidOnDate(\Carbon\Carbon::parse($payment->created_at)->format('Y-m-d\TH:i:s'));

        return $this->accountingApi->createInvoices($this->getTenantId(), $invoice);

发票状态设置为等待付款,即使我已经使用了该功能

->setFullyPaidOnDate(\Carbon\Carbon::parse($payment->created_at)->format('Y-m-d\TH:i:s'));

是否应该执行任何其他代码来将发票标记为已付款。

谢谢 丹尼

更新

按照建议,我已添加创建付款代码,但出现以下异常:

[400] Client error: `POST https://api.xero.com/api.xro/2.0/Payments` resulted in a `400 Bad Request` response:
{
  "ErrorNumber": 10,
  "Type": "ValidationException",
  "Message": "A validation exception occurred",
  "Elements" (truncated...)
 {"userId":1,"exception":"[object] (XeroAPI\\XeroPHP\\ApiException(code: 400): [400] Client error: `POST https://api.xero.com/api.xro/2.0/Payments` resulted in a `400 Bad Request` response:
{
  \"ErrorNumber\": 10,
  \"Type\": \"ValidationException\",
  \"Message\": \"A validation exception occurred\",
  \"Elements\" (truncated...)

错误消息被截断,无法知道问题所在。 Xero 端有控制台可以查看这些错误吗?

以下是我的代码:

$invoice = $this->createXeroInvoice($payment, $contact);
$newAcct = $this->getBankAccount();
$accountId = $newAcct->getAccounts()[0]->getAccountId();
$arr_payments = [];

$bankaccount = new Account;
$bankaccount->setAccountID($accountId);

$xero_payment = new Payment;
$xero_payment->setInvoice($invoice)
    ->setAccount($bankaccount)
    ->setAmount($payment->total / 100);

array_push($arr_payments, $xero_payment);
$xero_payments = new Payments;
$xero_payments->setPayments($arr_payments);

$result = $this->accountingApi->createPayment($this->getTenantId(), $xero_payments);

       

【问题讨论】:

    标签: invoice xero-api


    【解决方案1】:

    要将发票标记为已付款,您需要创建付款并将其应用于发票。 https://developer.xero.com/documentation/api/payments

    我不是 PHP 开发人员,所以恐怕我无法就如何在您的程序中执行此操作提供太多指导,但我认为您可以在此处找到如何执行此操作的示例:https://github.com/XeroAPI/xero-php-oauth2-app/blob/0d30486d3eda5f8cff9276fe507daf05541744ed/example.php#L1966

    【讨论】:

    • 感谢史蒂文的回复。当我添加付款代码时,不再创建发票,并且收到 400 Bad request 异常。请在我原来的问题中查看
    • 一切顺利,这是导致问题的重复发票 #
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-28
    • 1970-01-01
    • 2015-02-03
    • 2021-03-24
    • 2014-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多