0

Using the new SDK using this code in the sandbox:

$payment = new \XeroAPI\XeroPHP\Models\Accounting\Payment([
        'code' => '001',
        'invoice_number' => $inv_num,
        'amount' => $amount
            ]);
$this->accounting_api->createPayment($this->getSingleTenant(), $payment);

I get the following exception

  "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"
        }
      ]
    }
  ]

Do I really have a problem with my inputs, am I missing something required that is triggering this or is the API tanking on this?

1 Answers1

0

In the end the answer was to ignore the account_number and code properties and their getters and setters instead using empty Invoice and Account objects with just the code and invoice_number properties set:

    public function RegisterPayment($amount, $inv_num, $account_code){
    $payment = new \XeroAPI\XeroPHP\Models\Accounting\Payment([
        'account' => new \XeroAPI\XeroPHP\Models\Accounting\Account(['code' => $account_code]),
        'invoice' => new \XeroAPI\XeroPHP\Models\Accounting\Invoice(['invoice_number' => $inv_num]),
        'amount' => $amount,
        'date' => date('Y-m-d')
            ]);
    try{
        $this->accounting_api->createPayment($this->getSingleTenant(), $payment);
    } catch (\XeroAPI\XeroPHP\ApiException $ex) {
        //var_dump($ex->getResponseBody());
    }
}