popplestones / quickbooks-helper
Everything you need to integrate Quickbooks with Laravel
Requires
- quickbooks/v3-php-sdk: dev-master
- dev-main
- v1.2.8
- v1.2.7
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.27
- v1.1.26
- v1.1.25
- v1.1.24
- v1.1.23
- v1.1.22
- v1.1.21
- v1.1.20
- v1.1.18
- v1.1.17
- v1.1.16
- v1.1.15
- v1.1.14
- v1.1.13
- v1.1.12
- v1.1.11
- v1.1.10
- v1.1.9
- v1.1.8
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.22
- v1.0.21
- v1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
This package is auto-updated.
Last update: 2024-10-30 01:40:20 UTC
README
Helper wrapping the Quickbooks PHP SDK.
Installation
- Install the package
composer require popplestones/quickbooks-helper
- Run our migrations to install the
quickbooks_tokens
table:
``bash php artisan migrate --package=popplestones/quickbooks-helper
The package uses auto registration of Laravel.
Configuration
- You will need a
quickbooksToken
relationship on youruser
model, or optionally another model. There is a trait namedPoppletstones\Quickbooks\Traits\HasQuickbooksToken
, which you can iunclude on youruser
model, which will setup the relationship. To do this implement the following:
Add use Popplestones\Quickbooks\Traits\HasQuickbooksToken;
to the top of User.php
and also add the trait to the class. For example:
use Popplestones\Quickbooks\Traits\HasQuickbooksToken; class User extends Authenticateable { use Notifiable, HasQuickbooksToken;
Note: If your User
model is not App\models\User
, then you will need to publish the config and modify it as documented below.
Change model
- Publish the config
php artisan vendor:publish --tag=quickbooks.config
- Modify the model and fields as required
... 'user' => [ 'keys' => [ 'foreign' => 'user_id', 'owner' => 'id' ], 'model' => 'App\Models\User' ] ...
Quickbooks API Keys
- Add your client_id and client_secret to your .env file
Minimal keys
QUICKBOOKS_CLIENT_ID=<client id provided by quickbooks> QUICKBOOKS_CLIENT_SECRET=<client secret provided by quickbooks>
Optional keys
QUICKBOOKS_API_URL=<Development|Production> # defaults to App's env value QUICKBOOKS_DEBUG=<true|false> # defaults to App's debug value
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 using tinker:
Note: Before doing these commands, go to your connect route (default /quickbooks/connect) to get a quickbooks token for your user.
Auth::logInUsingId(1); $quickbooks = app('Quickbooks') $quickbooks->getDataService()->getCompanyInfo();
You can call any of the resources as documented in the SDK.
Using the included artisan commands
If you want to use the included artisan commands, you will need to provide the query to use to retrieve your data. In your AppServiceProvider's boot method add your customer queries.
QuickbooksHelper::setCustomerQuery(function() { return User::query() ->with('client') ->role(User::ROLE_APPROVED); }); QuickbooksHelper::setCustomerFilter(function($query) { $query ->has('orders') ->whereNull('qb_customer_id') ->where('sync_failed', '<', 3); });
Once you have set the customerQuery and the customerFilter, you can then run the artisan command to sync customers with quickbooks.
php artisan qb:customer
In this provided example only customers that have orders and have not failed syncing more than 3 times and have not already been synced with quickbooks will be synced. If you specify a customer to sync by ID like this:
php artisan qb:customer --id=123
The customer filter will be ignored, this enables you to update an existing customer that has already been synced.
Similarly to use the qb:invoice command you will also need to set the invoiceQuery and invoiceFilter, e.g.
QuickbooksHelper::setInvoiceQuery(function() { return Order::query() ->with(['user', 'items']) ->whereHas('user', function ($q) { $q->whereNotNull('qb_customer_id'); }) ->whereNotNull('paymentid'); }); QuickbooksHelper::setInvoiceFilter(function(&$query) { $query->where(function ($q) { $q->whereNull('qb_invoice_id') ->orWhereNull('qb_payment_id') ->orWhere('sync', 1); }) ->where('sync_failed', '<', 3) });
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 Codemonkey76\Quickbooks\Http\Middleware\QuickbooksConnected
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');