Download the PHP package dcblogdev/laravel-xero without Composer
On this page you can find all versions of the php package dcblogdev/laravel-xero. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dcblogdev/laravel-xero
More information about dcblogdev/laravel-xero
Files in dcblogdev/laravel-xero
Package laravel-xero
Short Description A Laravel Xero package
License MIT
Homepage https://github.com/dcblogdev/laravel-xero
Informations about the package laravel-xero
Community
There is a Discord community. https://discord.gg/VYau8hgwrm For quick help, ask questions in the appropriate channel.
Laravel package for working with the Xero API
Watch a video walkthrough https://www.youtube.com/watch?v=sORX2z-AH1k
Xero API documentation can be found at: https://developer.xero.com/documentation/
Before you can integrate with Xero you will need to create an app, go to https://developer.xero.com/myapps to register a new app.
For the grant type select, Auth code (web app)
For OAuth 2.0 redirect URI enter the full URL you want to use for connection to Xero from your application such as https://domain.com/xero/connect
Install
You can install the package via composer:
Config
You can publish the config file with:
Encrypt Tokens at rest
You can enable token encryption at rest by setting the following in your .env file:
this will use the native Laravel Crypt library to ensure the tokens are encrypted at rest.
Migration
You can publish the migration with:
After the migration has been published you can create the tokens tables by running the migration:
.ENV Configuration Ensure you've set the following in your .env file:
Middleware
To restrict access to routes only to authenticated users there is a middleware route called XeroAuthenticated
Add XeroAuthenticated to routes to ensure the user is authenticated:
To access token model reference this ORM model:
Multi-tenancy
To set the tenant call setTenantId
and pass in your tenant_id
Once set all calls will use the set tenant.
Commands
Refresh Token
When using Xero as a background process, tokens will need to be renwed, to automate this process use the command:
This will refresh the token when its due to expire.
Its recommended to add this to a schedule ie inside App\Console\Kernal.php
add the command to a schedule.
Usage
A routes example:
Or using a middleware route, if the user does not have a token then automatically redirect to get authenticated:
Once authenticated you can call Xero:: with the following verbs:
The second param of array is not always required, its requirement is determined from the endpoint being called, see the API documentation for more details.
These expect the API endpoints to be passed, the URL https://api.xero.com/api.xro/2.0/ is provided, only endpoints after this should be used ie:
Is Connected
Anytime you need to check if Xero is authenticated you can call a ->isConnected method. The method returns a boolean.
To do an action when a Xero is not connected can be done like this:
Disconnect
To disconnect from Xero call a ->disconnect() method.
The disconnect will send a POST request to Xero to revoke the connection, in addition, the stored token will be deleted.
Typically you only want to run this is there is a connection, so it makes sense to wrap this in a ->isConnected() check:
Contacts
Xero provides a clean way of working with Xero contacts.
To work with contacts first call ->contacts() followed by a method.
List Contacts
To list contacts call the contacts()->get() method.
Xero docs for listing contacts - https://developer.xero.com/documentation/api/contacts#GET
The optional parameters are $page and $where. $page defaults to 1 which means being back on the first page, for additional pages enter higher page numbers until there are no pages left to return. The API does not offer a count to determine how many pages there are.
$where allows for filter options to be passed, the most common filters have been optimised to ensure performance across organisations of all sizes. We recommend you restrict your filtering to the following optimised parameters.
Filter by name:
Filter by email:
Filter by account number:
View Contact
To view a single contact a find method can be called passing in the contact id
Create Contacts
To create a contact call a store method passing in an array of contact data:
See https://developer.xero.com/documentation/api/contacts#POST for the array contents specifications
Update Contact
To update a contact 2 params are required the contact Id and an array of data to be updated:
See https://developer.xero.com/documentation/api/contacts#POST for details on the fields that can be updated.
Invoices
Xero provides a clean way of working with Xero invoices.
To work with invoices first call ->invocies() followed by a method.
List Invoices
To list invoices call the invoices()->get() method.
Xero docs for listing invoices - https://developer.xero.com/documentation/api/invoices#get
The optional parameters are $page and $where. $page defaults to 1 which means being back on the first page, for additional pages enter higher page numbers until there are no pages left to return. The API does not offer a count to determine how many pages there are.
$where allows for filter options to be passed, the most common filters have been optimised to ensure performance across organisations of all sizes. We recommend you restrict your filtering to the following optimised parameters.
Filter by status:
Filter by contact id:
Filter by contact number
Filter by reference
Filter by date
Filter by type
View Invoice
To view a single invoice a find method can be called passing in the invoice id
Online Invoice
For invoices created that have a status of either Submitted, Authorised, or Paid an online invoice can be seen by calling onlineUrl passing in the invoiceId
Create Invoice
To create a invoice call a store method passing in an array of invoice data:
See https://developer.xero.com/documentation/api/invoices#post for the array contents specifications
Update Invoice
To update an invoice 2 params are required the invoice Id and an array of data to be updated:
See https://developer.xero.com/documentation/api/invoices#post for details on the fields that can be updated.
PDF resources
Some Xero resources support being downloaded as PDF. To do this you can:
Change log
Please see the changelog for more information on what has changed recently.
Contributing
Contributions are welcome and will be fully credited.
Contributions are accepted via Pull Requests on Github.
Pull Requests
-
Document any change in behaviour - Make sure the
readme.md
and any other relevant documentation are kept up-to-date. -
Consider our release cycle - We try to follow SemVer v2.0.0. Randomly breaking public APIs is not an option.
- One pull request per feature - If you want to do more than one thing, send multiple pull requests.
Security
If you discover any security related issues, please email [email protected] email instead of using the issue tracker.
License
license. Please see the license file for more information.
All versions of laravel-xero with dependencies
league/oauth2-client Version ^1.4|^2
guzzlehttp/guzzle Version 6.x|7.x
ext-json Version *
ext-fileinfo Version *
ext-curl Version *