invoice - Xero Api 如何标记发票已付款
问题描述
我可以通过以下代码成功创建发票
$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
推荐阅读
- javascript - 为什么它不会将函数传递给 React Router 渲染的子 React 组件作为道具?
- assembly - 如何使用 avr-gcc 生成准确的列表文件?
- python - 如何 1. 将 4,550 个 dbf 文件转换为 csv 文件 2. 根据名称连接文件 3. 将所有 csv 连接成一个大数据 csv 进行分析?
- python - Tkinter 对象放入列表并变成不需要的元组
- java - 对于 DocumentSnapshot 类型,错误 foreach 不适用于类型意味着什么?
- gtk - GTK WIn7 的替代品
- algorithm - 什么方法适合根据接送地点对客户进行聚类
- mysql - 最大函数不起作用,它返回最小函数值
- ios - 使用 Storyboard 创建的 UIBarButtonItem 未触发,日志中没有错误
- ajax - 保存到超过 50kB 的数据库时损坏的 PDF