Coder Social home page Coder Social logo

xerolaravel's Introduction

Packagist

Xero Accounting API Laravel 5 Wrapper

A Laravel 5 wrapper for calcinai/xero-php (a custom API for integrating with Xero).

Installation via Composer

Require the package

composer require drawmyattention/xerolaravel "1.0.*"

Add the Service Provider to your config/app.php under providers

'DrawMyAttention\XeroLaravel\Providers\XeroServiceProvider',

**Register the Facades within config/app.php under aliases

'XeroPrivate'=> 'DrawMyAttention\XeroLaravel\Facades\XeroPrivate',

Publish the configuration file

php artisan vendor:publish

This will create a xero/config.php within your config directory. (Note: Ensure that you have generated the necessary tokens and have generated the RSA keys required by Xero for authentication.) Edit the relevant values in the config.php file.

Ensure that the location of the RSA keys matches the required format (file://absolutepath)

Dependencies and Requirements

This Service Provider current wraps the calcinai/xero-php version 1.1.* package.

Additionally, you must have PHP installed with the following extensions:

  • php_curl (7.30+)
  • php_openssl

Usage

There are two ways to use the classes: via the IoC container, or via a Facade. They both offer the same functionality, so use each depending on your preference.

Get all invoices

Facade

$invoices = XeroPrivate::load('Accounting\\Invoice')->execute();

IoC Container

// Create an instance of the class, resolved out of the IoC container
$xero = $this->app->make('XeroPrivate');
    
$invoices = $xero->load('Accounting\\Invoice')->execute();

Get a single invoice via GUID or invoice number

Facade

$invoice = XeroPrivate::loadByGUID('Accounting\\Invoice', 'inv-0004);

IoC Container

$xero = $this->app->make('XeroPrivate');

$invoice = $xero->loadByGUID('Accounting\\Invoice', 'inv-0004);

Update an existing invoice

Facade

$invoice = XeroPrivate::loadByGUID('Accounting\\Invoice', 'inv-0004);

$invoice->setStatus('Paid');

XeroPrivate::save($invoice);

IoC Container

$xero = $this->app->make('XeroPrivate');

$invoice = $xero->loadByGUID('Accounting\\Invoice', 'inv-0004);

$invoice->setStatus('Paid');

$xero->save($invoice);

Creating a new invoice

/* 
 * Resolve instances of Xero, XeroInvoice, XeroContact 
 * and XeroInvoiceLine out of the IoC container.
 */
 
$xero = $this->app->make('XeroPrivate');
$invoice = $this->app->make('XeroInvoice');
$contact = $this->app->make('XeroContact');
$line1 = $this->app->make('XeroInvoiceLine');
$line2 = $this->app->make('XeroInvoiceLine');

// Set up the invoice contact
$contact->setAccountNumber('DMA01');
$contact->setContactStatus('ACTIVE');
$contact->setName('Amo Chohan');
$contact->setFirstName('Amo');
$contact->setLastName('Chohan');
$contact->setEmailAddress('[email protected]');
$contact->setDefaultCurrency('GBP');

// Assign the contact to the invoice
$invoice->setContact($contact);

// Set the type of invoice being created (ACCREC / ACCPAY)
$invoice->setType('ACCREC');

$dateInstance = new DateTime();
$invoice->setDate($dateInstance);
$invoice->setDueDate($dateInstance);
$invoice->setInvoiceNumber('DMA-00001');
$invoice->setReference('DMA-00001');

// Provide an URL which can be linked to from Xero to view the full order
$invoice->setUrl('http://yourdomain/fullpathtotheorder');

$invoice->setCurrencyCode('GBP');
$invoice->setStatus('Draft');

// Create some order lines
$line1->setDescription('Blue tshirt');

$line1->setQuantity(1);
$line1->setUnitAmount(99.99);
$line1->setTaxAmount(0);
$line1->setLineAmount(99.99);
$line1->setDiscountRate(0); // Percentage

// Add the line to the order
$invoice->addLineItem($line1);

// Repeat for all lines...

$xero->save($invoice);

Creating Attachments

$xero = $this->app->make('XeroPrivate');

$attachment = $this->app->make('XeroAttachment')
    ->createFromLocalFile(storage_path('your_file.pdf'));
  
$invoice = $xero->loadByGUID('Accounting\\Invoice', 'AMO-00002');
$invoice->addAttachment($attachment);

xerolaravel's People

Contributors

amochohan avatar bozenawloch avatar elliotlings avatar geoffs3310 avatar gerrywastaken avatar tariqbilal avatar ziming avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

xerolaravel's Issues

How to use Facade to Make

Hi there,

How would I use the Facade to make an entry into Xero?

There are examples there for using it to load, but nothing for actually inserting say a new contact.

Thanks

Cannot display product lists using Item

I have tried every which way i can think of, but i cannot get either a JSON or an Array response from this package, i all i ever seem to get is the headers, but without the actual content, how can i use this to create a foreach for my items in Xero ?

How do I send a receipt for a paid invoice?

I have figured out the logic to save a payment for an invoice in Xero but I cant seem to find a way to send a receipt for the Payment:

private static function createDepositInvoice($booking) {

		$depositAmount = floatval(0.2 * $booking->total );
		$xero = \App::make('XeroPrivate');
		$invoice = \App::make('XeroInvoice');
		$contact = \App::make('XeroContact');
		$address = \App::make('XeroAddress');
		$line1 = \App::make('XeroInvoiceLine');

		// Set up the invoice contact
		$contact->setContactStatus('ACTIVE');
		$contact->setName($booking->customer_name);
		$contact->setEmailAddress($booking->customer_email);
		$contact->setDefaultCurrency('GBP');
		
		// Assign the contact to the invoice
		$invoice->setContact($contact);

		// Set the type of invoice being created (ACCREC / ACCPAY)
		$invoice->setType('ACCREC');

		$dateInstance = new \DateTime();
		$invoice->setDate($dateInstance);
		$invoice->setDueDate($dateInstance);
		$invoice->setInvoiceNumber('INV-BOOKING-DEP' . $booking->id . ' - ' . uniqid());
		$invoice->setReference('DEP - ' . $booking->id);

		// Provide an URL which can be linked to from Xero to view the full order
		//$invoice->setUrl('http://yourdomain/fullpathtotheorder');

		$invoice->setCurrencyCode('GBP');
		$invoice->setStatus('AUTHORISED');
		

		// Create some order lines
		$line1->setDescription('Deposit payment for Booking: ' . $booking->id);

		$line1->setQuantity(1);
		$line1->setUnitAmount($depositAmount);
		$line1->setTaxAmount(0);
		$line1->setTaxType('NONE');
		$line1->setLineAmount($depositAmount);
		$line1->setAccountCode(200);
		$line1->setDiscountRate(0); // Percentage

		// Add the line to the order
		$invoice->addLineItem($line1);

		$xero->save($invoice);
		
                // create payment for invoice
		$account = \App::make('XeroAccount');
		$account->setAccountID('8078e1c8-d2cc-4794-ba10-dc7e34ec0f89');
		$payment = \App::make('XeroPayment');
		$payment->setInvoice($invoice);
		$payment->setAccount($account);
		$payment->setAmount($depositAmount);
		$xero->save($payment);
		//$invoice->sendEmail();
	}

I see that there is Receipt model for in the API but how do I email the receipt attachment? Any ideas?

Xero PHP API ErrorException in Response.php line 74

There is a cronjob that is runing Every Monday to import the invoices into xero from our booking system. This Monday it encounter an error.

ErrorException in Response.php line 74:
Undefined index: message
in Response.php line 74
at HandleExceptions->handleError('8', 'Undefined index: message', '\vendor\calcinai\xero-php\src\XeroPHP\Remote\Response.php', '74', array()) in Response.php line 74

I didn't change anything on the script or on the server. It suddenly stopped working. I realised that Xero released 2SA on Xero login. It might affected the API. Can anybody help me out please?

Can i use this project for public or partner xero API?

Hi,

I want to build application using initially with using Public API and then we will upgrade it for partner API. So is there any way i can use this project for my application? If you can provide some suggestions then it can be great.

Currently i have setup this and using my public API credentials but it is giving this error

"Curl error: SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed".

Before i have tried same API credentials in XeroOAuth-PHP library at that time it was working well and did not giving any certificate error but i think here it is not working as it is public API.

Thanks,
Jay

Issues with curl and ssl: Curl error: SSL certificate problem: unable to get local issuer certificate

Hey. Thanks for putting this together. I am having a couple of issue that I am hoping you might be able to help me with?

The first being:
Curl error: SSL certificate problem: unable to get local issuer certificate
I have checked and everything is installed properly on the server and the locations of the SSL key etc is all OK:

'rsa_private_key'  => 'file:///' . base_path() . '/privatekey.pem',
'rsa_public_key'   => 'file:///' . base_path() . '/publickey.cer'

cURL is at version 7.37.1
openSSL is installed and enabled

All settings seem OK. Have you experienced this before? I am running this on Homestead. I initially thought this was the issue, so pushed it to the staging server and I have the same issue.

I've also added the paths without the use of base_path() and the issue remains.

Thanks in advance. I am hoping it is something stupid on my side.

Cheers

Public Xero Application

I'm trying to use the example code for creating a new invoice for our Public Xero app. But I'm getting this error:

Token has not been provided

What's the correct way to make the OAuth handshake with Xero for public apps?

Making a payment/marking invoice as paid

Hi ya,

I've been trying to mark and invoice as paid. from reading, I believe that you can't simply mark the invoice's status as 'Paid' as the readme suggests as Xero needs to have a payment associated with it. Do you have any experience with this?

I've added Payments to the Service Provider and I am creating a Payment object, however, going through the API, I can't see how you would make that payment. There is no setPayments on the invoice model and I can't seem to just save the payment on the xero object: $xero->save($payment);

Any ideas?

Xero\config.php

The readme.md file mentions the config file being located in the config dir. (after php artisan vendor:publish) However i found it in "www\laravel\vendor\drawmyattention\xerolaravel\config.php" instead.

Which is correct?

Undefined index: InvoiceID

Hello,

i using v1.0.8 version, it is perfect working before today i get error:

Undefined index: InvoiceID in /Users/g.janjulia/dev/kiwipost/vendor/calcinai/xero-php/src/XeroPHP/Models/Accounting/Invoice.php on line 716

anyone does can help me ?

Can't use Facades nor $this->app->make(...)

Hi Amo,

Thanks for the package.
I'm trying to create an invoice without luck.
here are the initial lines that I have:

$xero = $this->app->make('XeroPrivate');
$invoice = $this->app->make('XeroInvoice');
$xcontact = $this->app->make('XeroContact');
$xcontact->setName($contact->name);
$invoice->setContact($xcontact);
// then foreach(items)
$line1 = $this->app->make('XeroInvoiceLine');
$line1->setDescription($desc);
$line1->setQuantity(1);
$line1->setUnitAmount($price);                      
$line1->setLineAmount($price);
$line1->setLineAmountType('Exclusive');
$line1->setAccountCode('200');
$invoice->addLineItem($line1);
.....

$xero->save($invoice)

This is working if that lines are in routes.php ($line1->setLineAmountType('Exclusive'); gives an error though)

However when I move the code to the controller I'm getting Undefined property: App\Http\Controllers\ProjectsController::$app

I've tried
....

$xero = new \XeroPrivate;
$invoice = new \XeroInvoice;
$xcontact = new \XeroContact;

This time Class 'XeroInvoice' not found
So I thought I should add aliases and added fallowing to the app.php
'XeroInvoice'=> 'DrawMyAttention\XeroLaravel\Facades\XeroInvoice',
'XeroContact'=> 'DrawMyAttention\XeroLaravel\Facades\XeroContact',

Now the error is Class 'DrawMyAttention\XeroLaravel\Facades\XeroContact' not found

So I've created the Facade manually like:

namespace DrawMyAttention\XeroLaravel\Facades;

use Illuminate\Support\Facades\Facade;

class XeroContact extends Facade
{
    protected static function getFacadeAccessor() { return 'XeroContact'; }
}

Now the error is Call to undefined method DrawMyAttention\XeroLaravel\Facades\XeroContact::setName()

I'm not very familiar with Facades, IOC and ServiceProviders.

My laravel version is "laravel/framework": "5.1.*"

Thanks in advance.

Return Type loadByGUID()

What is value return by \XeroPrivate::loadByGUID('Accounting\Invoice', $invoice->id) if the Invoice ID does not exist and how can I handle the exception?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.