-1

I am trying to update an Invoice in XERO by using the XERO-API. I am able to save the invoice as 'Draft' which is an outstanding amount that the customer to pay. When the payment is done, I want to send a request to the Xero and want to change the status to 'PAID'; amountDue = '$ 0.00' and AmountPaid = '$XX.xx'. I am not able to update this info and I am working on PHP. There is not much discussion/ research on this either.

$refXero  = 'INV-123456';
$invoices =  $xero->loadByGUID('Accounting\\Invoice', $refXero );

    **//I am getting errors from here onwards:-** 

$invoices->setAmountDue('0');
$invoices->setAmountPaid('50.00');
$invoices->setStatus('PAID');
$invoices->setDate('2019-10-15');
$invoices->save();

The error I am getting is 'Call to undefined method XeroPHP\Models\Accounting\Invoice::setAmountDue()'

How can I send this info and update this.

Thanks

Kunal Parekh
  • 380
  • 6
  • 24

2 Answers2

0

To make a Xero invoice as PAID, you'll need to create a payment for the appropriate amount using the /payments endpoint. Once the sum of the payments against an invoice matches the total of the invoice, it'll be set to PAID.

Documentation of the /payments endpoint is here:

https://developer.xero.com/documentation/api/payments#PUT

...but it probably already exists in the SDK you're using. Note you'll need to have set the invoice to be AUTHORISED before you can successfully make payments.

rustyskates
  • 856
  • 4
  • 10
0

My Invoice ref number is: 97661-Z (Saved in my Database and XERO)

$currRefNumber = $request->input('update_payment_refNumber'); //**Z**
$refXero = $bookingID.'-'.$currRefNumber; //(**97661-Z**)

This Invoice Number 97661-Z is saved as Draft in the XERO.

So basically, when the Invoice is saved as a draft, it first needs to be updated as Authorised as below:-

$invoices = XeroPrivate::loadByGUID('Accounting\\Invoice', $refXero);
$invoices->setStatus(\XeroPHP\Models\Accounting\Invoice::INVOICE_STATUS_AUTHORISED);
$invoices->save();

The above will update the Invoice status from Draft to Awaiting Payment

Now get the account code:-

$account = XeroPrivate::loadByGUID('Accounting\\Account', '880');
$dateInstance = new \DateTime();
$newPayment = new \XeroPHP\Models\Accounting\Payment();
              $newPayment
                        ->setInvoice($invoices)
                        ->setAccount($account)
                        ->setDate($dateInstance)
                        ->setAmount(600)
                        ->setIsReconciled(true)
                        ->setReference('Payment Received');

XeroPrivate::save($newPayment);

This will now change the status = Paid and will update the information AccountDue = $0.00 and AccountPaid = $600.00

I hope this will help others if needed.

Kunal Parekh
  • 380
  • 6
  • 24