0

I am using the Xero Laravel wrapper (https://github.com/amochohan/xerolaravel) and want to record payments made against an invoice. I can get the invoice but cannot find how to record a payment using the Laravel Wrapper provided;

I have tried a couple of solutions but none seem to work;

// Load the Invoice (Working)
$invoice = XeroPrivate::loadByGUID('Accounting\\Invoice', 'RPT445-1');

$payment = \App::make('XeroPayment');
$payment->setInvoice($invoice);
$payment->setDate(Carbon::now());
$payment->setAmount(100);

$xero->save($payment);

The above returns the issue

Class XeroPayment does not exist

Can anyone help? I can find the Xero documentation but this doesn't help to how it could translate into Laravel. It may be that the wrapper doesn't have this functionality built in, if so how would I complete using https://github.com/calcinai/xero-php which the wrapper is based on?

Kieran Headley
  • 647
  • 1
  • 7
  • 21
  • Are both the wrapper and Xero in your composer? – apokryfos Mar 21 '17 at 16:46
  • Yes they are both in my composer file. – Kieran Headley Mar 21 '17 at 16:49
  • Also assuming you've registered the service provider and aliases try doing a `composer dump-autoload` and `php artisan cache:clear` also make sure you have `use XeroPrivate` if you're not in the root namespace. – apokryfos Mar 21 '17 at 16:52
  • I have completed the above but it still doesn't work, I have also changed `\App::make` to `XeroPrivate::make` and get the following `Call to undefined method XeroPHP\Application\PrivateApplication::make()` – Kieran Headley Mar 21 '17 at 16:54
  • have you added `'DrawMyAttention\XeroLaravel\Providers\XeroServiceProvider',` to your `config/app.php`? – Paras Mar 21 '17 at 17:14
  • Also, try replacing `$payment = \App::make('XeroPayment');` with `$payment = new \XeroPHP\Models\Accounting\Payment();` – Paras Mar 21 '17 at 17:16
  • Yes XeroServiceProvider is within my app.php, I have changed the line and I now get a bad request response. Which makes me think that it is getting talking to the API to some extent. – Kieran Headley Mar 21 '17 at 17:46

1 Answers1

0

With the help of the xero-php library I managed to completed this as below;

    $invoice = XeroPrivate::loadByGUID('Accounting\\Invoice', 'INV-0038');
    $account = XeroPrivate::loadByGUID('Accounting\\Account', 'BD9E85E0-0478-433D-AE9F-0B3C4F04BFE4');

    $dateInstance = new \DateTime();

    $newPayment = new \XeroPHP\Models\Accounting\Payment();
    $newPayment
        ->setInvoice($invoice)
        ->setAccount($account)
        ->setDate($dateInstance)
        ->setAmount(10)
        ->setIsReconciled(true)
        ->setReference('Payment 45678');

    $posted_payment = XeroPrivate::save($newPayment);
Kieran Headley
  • 647
  • 1
  • 7
  • 21