A handy Laravel Wrapper around using MYOB Account Right v2
Branch: master
Clone or download
Latest commit ccc6360 Feb 10, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config initial commit Feb 2, 2019
database/migrations wip Feb 3, 2019
src create customer Feb 9, 2019
tests initial commit Feb 2, 2019
.editorconfig initial commit Feb 2, 2019
.gitattributes initial commit Feb 2, 2019
.gitignore initial commit Feb 2, 2019
.scrutinizer.yml initial commit Feb 2, 2019
.styleci.yml initial commit Feb 2, 2019
.travis.yml initial commit Feb 2, 2019
CHANGELOG.md initial commit Feb 2, 2019
CONTRIBUTING.md initial commit Feb 2, 2019
LICENSE.md initial commit Feb 2, 2019
README.md readme updates Feb 9, 2019
composer.json Update composer.json Feb 4, 2019
phpunit.xml.dist initial commit Feb 2, 2019

README.md

Laramyob - MYOB in Laravel, made easy.

Latest Version on Packagist Build Status Quality Score Total Downloads

A handy Laravel wrapper around MYOB AccountRight v2. This is still in alpha stage and will include breaking changes regularily. Full Readme in progress.

Installation

You can install the package via composer:

composer require creativecurtis/laramyob

Setup

ENV requirements:

MYOB_CLIENT_ID=
MYOB_CLIENT_SECRET=
MYOB_REDIRECT_URI=myob/login
MYOB_GRANT_TYPE=authorization_code
MYOB_SCOPE=CompanyFile

Publish the preset configuration to store your MYOB authentication details

php artisan vendor:publish --provider="Creativecurtis\Laramyob\LaramyobServiceProvider" --tag="migrations"
php artisan migrate

You'll now need to authenticate with something like the following:

use Creativecurtis\Laramyob\Laramyob;
use Creativecurtis\Laramyob\Models\Remote\CompanyFile;
use Creativecurtis\Laramyob\Models\Remote\Contact\Customer;

$laramyob = new Laramyob;
//Redirect your user to MYOB to authenticate account right v2
$laramyob->authenticate()->getCode();
//When the code is returned, get your access token
$laramyob->authenticate()->getToken();
//Now you can save your credentials like so
//You would first load the company files the MYOB user has access to
$laramyob->of(CompanyFile::class)->load();
//Then save them like so (the username and passwords are Base64 encoded in Laramyob)
$laramyob->authenticate()->saveCompanyFileCredentials([
        'username' => 'Administrator',
        'password' => '',
        'company_file_guid' => '8bf1611b-1666-4f8f-8b7f-ee4cf4fee2ff',
        'company_file_name' => 'API Sandbox Demo 48',
        'company_file_uri'  => 'https:\/\/ar1.api.myob.com\/accountright\/8bf1611b-1666-4f8f-8b7f-ee4cf4fee2ff'
]);

Usage

Get

Once that's completed you'll be able to query the API as you normally would

//And now query the API with the supported models (and paginate if supported)
$laramyob->of(Customer::class)->page(1); //page 1
//Or (if the Model is a paginted model it will stil default to pagination due to MYOB api restrictions)
$laramyob->of(Customer::class)->load(); //page 1
$laramyob->of(Customer::class)->load(2); //page 2

//You can also load the specified model by UID
$laramyob->of(Customer::class)->loadByUid('8bf1611b-1666-4f8f-8b7f-ee4cf4fee2ff');

//Or just return the first from a search
$laramyob->of(TaxCode::class)->whereCode('GST')->first();

//The customer class also has some helper function (whereEmail)
$laramyob->of(Customer::class)->whereEmail('lukesimoncurtis@gmail.com')->get();

You can also expose the Raw API for MYOB if appropriate

$laramyob->rawGet('/Contact/Employee');
$laramyob->rawPost('/Contact/Employee', $data);

Post

Once you're ready to post you can do the following, to, for example, save a Customer

$taxCode = $this->laramyob->of(TaxCode::class)->whereCode('GST')->first();

$customer = (new Customer)->create([
    'CompanyName'    => 'Creativecurtis',
    'LastName'       => 'curtis',
    'FirstName'      => 'luke',
    'IsIndividual'   => false,
    "TaxCode"        => [
        "UID" => $taxCode['UID'],
    ],
    "FreightTaxCode" => [
        "UID" => $taxCode['UID'],
    ],
])

$laramyob->save($customer);

Testing

composer test

Todo:

  • Create API Auth.
  • Create basic model syntax for retrieving data
  • Implement base model for encodable data
  • Create request class
  • Clean up request class.
  • Create get and set for appropriate models instead of current free-for-all
  • Write tests
  • Make OAuth2 request class less dependant on request class

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email lukesimoncurtis@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.