spinen / laravel-quickbooks-client
SPINEN's Laravel Client for QuickBooks.
Installs: 43 874
Dependents: 0
Suggesters: 0
Security: 0
Stars: 42
Watchers: 10
Forks: 61
Open Issues: 6
Requires
- php: >=7.2
- illuminate/database: ~5.5|~6|~7|~8
- illuminate/http: ~5.5|~6|~7|~8
- illuminate/routing: ~5.5|~6|~7|~8
- nesbot/carbon: ^1.26.3|^2.0
- quickbooks/v3-php-sdk: ^5.3.6
Requires (Dev)
- mockery/mockery: ^1.3.1
- phpunit/phpunit: ^8.4|^9.0
- psy/psysh: ^0.10
- symfony/thanks: ^1.1
This package is auto-updated.
Last update: 2024-10-14 06:00:06 UTC
README
PHP client wrapping the QuickBooks PHP SDK.
We solely use Laravel for our applications, so this package is written with Laravel in mind. If there is a request from the community to split this package into 2 parts to allow it to be used outside of Laravel, then we will consider doing that work.
Build Status
Installation
- Install QuickBooks PHP Client:
$ composer require spinen/laravel-quickbooks-client
- Run our migration to install the
quickbooks_tokens
table:
$ php artisan migrate --package=spinen/laravel-quickbooks-client
The package uses the auto registration feature of Laravel.
Configuration
- You will need a
quickBooksToken
relationship on yourUser
model. There is a trait namedSpinen\QuickBooks\HasQuickBooksToken
, which you can include on yourUser
model, which will setup the relationship. To do this implement the following:
Add use Spinen\QuickBooks\HasQuickBooksToken;
to your service container at the top of User.php
and also add the trait within the class. For example:
class User extends Authenticatable { use Notifiable, HasQuickBooksToken;
NOTE: If your User
model is not App\Models\User
, then you will need to configure the path in the configs/quickbooks.php
.
-
Add the appropriate values to your
.env
Minimal Keys
QUICKBOOKS_CLIENT_ID=<client id given by QuickBooks> QUICKBOOKS_CLIENT_SECRET=<client secret>
Optional Keys
QUICKBOOKS_API_URL=<Development|Production> # Defaults to App's env value QUICKBOOKS_DEBUG=<true|false> # Defaults to App's debug value
-
[Optional] Publish configs & views
Config
A configuration file named
quickbooks.php
can be published toconfig/
by running...php artisan vendor:publish --tag=quickbooks-config
Views
View files can be published by running...
php artisan vendor:publish --tag=quickbooks-views
Usage
Here is an example of getting the company information from QuickBooks:
NOTE: Before doing these commands, go to your connect route (default: /quickbooks/connect) to get a QuickBooks token for your user
php artisan tinker Psy Shell v0.8.17 (PHP 7.1.14 — cli) by Justin Hileman >>> Auth::logInUsingId(1) => App\Models\User {#1668 id: 1, // Other keys removed for example } >>> $quickbooks = app('Spinen\QuickBooks\Client') // or app('QuickBooks') => Spinen\QuickBooks\Client {#1613} >>> $quickbooks->getDataService()->getCompanyInfo(); => QuickBooksOnline\API\Data\IPPCompanyInfo {#1673 +CompanyName: "Sandbox Company_US_1", +LegalName: "Sandbox Company_US_1", // Other properties removed for example } >>>
You can call any of the resources as documented in the SDK.
Middleware
If you have routes that will be dependent on the user's account having a usable QuickBooks OAuth token, there is an included middleware Spinen\QuickBooks\Laravel\Filter
that gets registered as quickbooks
that will ensure the account is linked and redirect them to the connect
route if needed.
Here is an example route definition:
Route::view('some/route/needing/quickbooks/token/before/using', 'some.view') ->middleware('quickbooks');