XERO PHP SDK createPayment Validation Exception



在沙箱中使用以下代码使用新的SDK:

$payment = new XeroAPIXeroPHPModelsAccountingPayment([
'code' => '001',
'invoice_number' => $inv_num,
'amount' => $amount
]);
$this->accounting_api->createPayment($this->getSingleTenant(), $payment);

我得到以下异常

"ErrorNumber": 10,
"Type": "ValidationException",
"Message": "A validation exception occurred",
"Elements": [
{
"Date": "/Date(1604880000000+0000)/",
"Amount": 1.74,
"Status": "AUTHORISED",
"HasAccount": false,
"HasValidationErrors": true,
"ValidationErrors": [
{
"Message": "You must specify either an Invoice ID or Invoice Number or CreditNote ID or CreditNote Number or Prepayment ID or Overpayment ID for the payment"
},
{
"Message": "You must specify and Account code or Account ID for the payment"
},
{
"Message": "You must specify an Overpayment ID for the payment"
}
]
}
]

我的输入真的有问题吗?我是错过了触发这个问题所需的东西,还是API在这个问题上失败了?

最终,答案是忽略account_number和code属性及其getter和setter,而使用空的Invoice和account对象,只设置code和Invoice_number属性:

public function RegisterPayment($amount, $inv_num, $account_code){
$payment = new XeroAPIXeroPHPModelsAccountingPayment([
'account' => new XeroAPIXeroPHPModelsAccountingAccount(['code' => $account_code]),
'invoice' => new XeroAPIXeroPHPModelsAccountingInvoice(['invoice_number' => $inv_num]),
'amount' => $amount,
'date' => date('Y-m-d')
]);
try{
$this->accounting_api->createPayment($this->getSingleTenant(), $payment);
} catch (XeroAPIXeroPHPApiException $ex) {
//var_dump($ex->getResponseBody());
}
}

相关内容

  • 没有找到相关文章

最新更新