【发布时间】: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);
【问题讨论】: