hotrush/quickbooks-manager

v0.2.2 2019-12-03 19:35 UTC

This package is auto-updated.

Last update: 2024-10-29 05:46:57 UTC


README

  • Manage different connections (credentials)
  • Store tokens in the database
  • Refresh token automatically
  • Functionality for tokens acquiring
  • Webhooks management
  • Api SDK included
  • Logging

Installation

composer require hotrush/quickbooks-manager

You have to migrate the database

php artisan migrate

Also you can publish config file

php artisan vendor:publish --provider="Hotrush\QuickBooksManager\QuickBooksManagerServiceProvider" --tag="config"

Authorization

To redirect to OAuth authorization page use qbm.redirect route e.g.:

redirect(route('qbm.redirect', ['connection' => 'default']));

On successful auth token will be stored in the database and used automatically for API requests. You can configure redirect-back route for success authorization in config file changing redirect_route option.

Api requests

When token received you can use connection manager to send api requests. To get manager instance you can use laravel's container resolving stuff and resolve for Hotrush\QuickBooksManager\QuickBooksManager class.

Then just get needed connection and send request.

$invoiceToCreate = Invoice::create([...]);
$manager = resolve(\Hotrush\QuickBooksManager\QuickBooksManager::class);
$manager->connection('default')->Add($invoiceToCreate);

Webhooks

Each connection has it's own webhook endpoint e.g.

/qbm/webhook/{connection?}

You can also define verifier_token for each connection to verify data received by webhook (read more).

Each webhook's notification will spawn a new laravel's event. You can easily create your own event listener to handle it.

Events list:

  • Hotrush\QuickBooksManager\Events\EntityCreate
  • Hotrush\QuickBooksManager\Events\EntityUpdate
  • Hotrush\QuickBooksManager\Events\EntityDelete
  • Hotrush\QuickBooksManager\Events\EntityMerge
  • Hotrush\QuickBooksManager\Events\EntityVoid

Each event has next arguments:

  • connection name
  • realmId
  • entityName - the name of the entity type that changed (Customer, Invoice, etc.)
  • entityId - changed entity id
  • lastUpdated - carbon-parsed date object
  • deletedId - the ID of the entity that was deleted and merged (only for Merge events)

Tokens refresh schedule

Schedule refreshing in App\Console\Kernel. Schedule docs.

$schedule->command(RefreshTokensCommand::class)->everyMinute();

Token's database table

Now you can configure token's table name, just change table_name in config file.