我可以按照以下代码成功创建发票
$invoice = new Invoice;
$invoice->setReference('Ref-' . $this->getRandNum())
->setDate(new DateTime(CarbonCarbon::parse($payment->created_at)->format('Y-m-d')))
->setDueDate(new DateTime(CarbonCarbon::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(CarbonCarbon::parse($payment->created_at)->format('Y-m-dTH:i:s'));
return $this->accountingApi->createInvoices($this->getTenantId(), $invoice);
发票状态设置为等待付款,即使我已经使用了该功能
->setFullyPaidOnDate(CarbonCarbon::parse($payment->created_at)->format('Y-m-dTH: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