Xero Api 如何标记发票已支付
Xero Api how to mark an invoice has been paid
我可以通过以下代码成功创建发票
$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);
要将发票标记为已付款,您需要创建付款并将其应用于发票。
https://developer.xero.com/documentation/api/payments
我不是 PHP 开发人员,所以恐怕我无法就如何在您的程序中执行此操作提供太多指导,但我认为您可以找到一个如何执行此操作的示例这里:https://github.com/XeroAPI/xero-php-oauth2-app/blob/0d30486d3eda5f8cff9276fe507daf05541744ed/example.php#L1966
我可以通过以下代码成功创建发票
$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);
要将发票标记为已付款,您需要创建付款并将其应用于发票。 https://developer.xero.com/documentation/api/payments
我不是 PHP 开发人员,所以恐怕我无法就如何在您的程序中执行此操作提供太多指导,但我认为您可以找到一个如何执行此操作的示例这里:https://github.com/XeroAPI/xero-php-oauth2-app/blob/0d30486d3eda5f8cff9276fe507daf05541744ed/example.php#L1966