calcinai / xero-php

A php library for the Xero API, with a cleaner OAuth interface and ORM-like abstraction.
MIT License
360 stars 257 forks source link

Making Payment on Invoice #233

Closed kieranheadley closed 7 years ago

kieranheadley commented 7 years ago

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

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?

calcinai commented 7 years ago

Good question! I'm not actually sure on this specific functionality - perhaps @amochohan could shed some light on this?

From what I can see there's a facade for the payment in there..

kieranheadley commented 7 years ago

Not had a response from Amo Chohan, how would you complete this using your library?

williamrenfrew commented 7 years ago

Here's how we push a payment against a Xero invoice using the xero-php library. ` $invoice_obj = new \XeroPHP\Models\Accounting\Invoice($xero->getInstance()); $invoice_obj->setInvoiceID($invoice_guid);

        $newPayment = new \XeroPHP\Models\Accounting\Payment();
        $newPayment
            ->setInvoice($invoice_obj)
            ->setAccount($currency)
            ->setDate($date_time_obj)
            ->setAmount($amount)
            ->setIsReconciled(true)
            ->setReference('Payment '.$payment->reference);
        $posted_payment = $xero->save($newPayment);`

I've toned down some of our values but hopefully this gives you the gist?

kieranheadley commented 7 years ago

That worked perfectly, thank you so much @williamrenfrew

calcinai commented 7 years ago

Thanks @williamrenfrew for clarifying that. Maybe it's time for some more docs! as in #86...