Code Monkey home page Code Monkey logo

laravel-quickbooks-client's Introduction

SPINEN's Laravel QuickBooks Client

Latest Stable Version Latest Unstable Version Total Downloads License

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

Branch Status Coverage Code Quality
Develop Build Status Code Coverage Scrutinizer Code Quality
Master Build Status Code Coverage Scrutinizer Code Quality

Installation

  1. Install QuickBooks PHP Client:
$ composer require spinen/laravel-quickbooks-client
  1. 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

  1. You will need a quickBooksToken relationship on your User model. There is a trait named Spinen\QuickBooks\HasQuickBooksToken, which you can include on your User 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.

  1. 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
  2. [Optional] Publish configs & views

    Config

    A configuration file named quickbooks.php can be published to config/ 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');

laravel-quickbooks-client's People

Contributors

cg0012 avatar jimmypuckett avatar lukereimer avatar ssfinney avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-quickbooks-client's Issues

Connecting to Multiple QBO Accounts.

Im having issues, My App needs to be connected to multiple QBO Accounts. The problem is, when my App User A is connected to QBO Account A then another "App User" connects to another (like QBO Account B). App User A will lose its connection to QBO. I followed the configuration as exampled. Thanks.

QBO server time

QBO API Explorer returns a key namely "time" in all responses, this is not available in this package response serialize

Composer 2 throws psr-4 error

I submitted a change to fix the composer2 psr-4 error caused by the quickbooks php sdk package.

No other changes were made, but this will resolve modern composer errors

Can't get OAuth 2 Scope. It is not set.

I have an exception being thrown from Quickbooks which I have been stuck on for hours:
QuickBooksOnline\API\Exception\SdkException Can't get OAuth 2 Scope. It is not set.

The scope is hardcoded and somewhere its being removed.

How to use ?

Please let me know, how can i use this package ?

Composer fails for Laravel 6.0.4

Not sure why it is trying to uninstall laravel/framework v6.0.4 when I run composer? Your composer.json seems to cater for ver 6.0.*. Any ideas?

c:\my-dir>composer require spinen/laravel-quickbooks-client

Using version ^3.0 for spinen/laravel-quickbooks-client
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Conclusion: remove laravel/framework v6.0.4
- Conclusion: don't install laravel/framework v6.0.4
- spinen/laravel-quickbooks-client 3.0.0 requires illuminate/routing 5.5.|5.6.|5.7.|5.8.

  • don't install illuminate/routing 5.5.x-dev|don't install laravel/framework v6.0.4
    • don't install illuminate/routing 5.6.x-dev|don't install laravel/framework v6.0.4
    • don't install illuminate/routing 5.7.17|don't install laravel/framework v6.0.4
    • don't install illuminate/routing 5.7.18|don't install laravel/framework v6.0.4
    • don't install illuminate/routing 5.7.19|don't install laravel/framework v6.0.4
    • don't install illuminate/routing 5.7.x-dev|don't install laravel/framework v6.0.4
    • don't install illuminate/routing 5.8.x-dev|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.5.0|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.5.16|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.5.17|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.5.2|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.5.28|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.5.33|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.5.34|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.5.35|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.5.36|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.5.37|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.5.39|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.5.40|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.5.41|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.5.43|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.5.44|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.0|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.1|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.10|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.11|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.12|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.13|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.14|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.15|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.16|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.17|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.19|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.2|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.20|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.21|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.22|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.23|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.24|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.25|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.26|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.27|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.28|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.29|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.3|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.30|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.31|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.32|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.33|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.34|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.35|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.36|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.37|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.38|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.39|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.4|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.5|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.6|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.7|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.8|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.6.9|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.7.0|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.7.1|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.7.10|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.7.11|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.7.15|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.7.2|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.7.20|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.7.21|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.7.22|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.7.23|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.7.26|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.7.27|don't install laravel/framework v6.0.4
    • don't install illuminate/routing v5.7.28|don't install laravel/framework v6.0.4

Installation failed, reverting ./composer.json to its original content.

Exception on getting company info

Hi

I tried to apply usage example of readme of this gist repo but I got this error message ๐Ÿ’ฏ

QuickBooksOnline/API/Exception/SdkException with message 'Please Setup Service Context before making get CompanyInfo call.'

What I am missing ? Thanks for your help

Auto Discovery not working

I am not a Laravel expert, so I may be doing something totally stupid, but I would appreciate some help. I could not get this package to work on Laravel 6.04, so I tried it on an existing Laravel 5.8 project.

Composer installs fine, but afterwards, none of the Spinen/QuickBooks Service Providers and Middleware or Migrations are added.

After running

c:\my-project>composer require spinen/laravel-quickbooks-client

It installs all the files

  • Installing quickbooks/v3-php-sdk (dev-master f94ac9e): Cloning f94ac9ed63 from cache
  • Installing spinen/laravel-quickbooks-client (3.0.1): Downloading (100%)
  • Installing beyondcode/laravel-dump-server (1.3.0): Downloading (100%)

................ etc

IT THEN DOES ITS AUTO DISCOVERY....

Writing lock file
Generating optimized autoload files

@php artisan package:discover --ansi
Discovered Package: beyondcode/laravel-dump-server
Discovered Package: spinen/laravel-quickbooks-client

..... etc

Package manifest generated successfully.
Generated optimized autoload files containing 4094 classes

When I look at my project, however,none of the Service Providers and Middleware or Migrations are added to the project.

Any ideas?

Dependencies current?

I have a Laravel 8 project I'd like to use this with but have dependency errors. Doesn't Laravel provide illuminate/database?

`Your requirements could not be resolved to an installable set of packages.

Problem 1
- spinen/laravel-quickbooks-client[4.0.0, ..., 4.0.3] require illuminate/database ~5.5|~6|~7 -> found illuminate/database[v5.5.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev] but these were not loaded, likely because it conflicts with another require.
- spinen/laravel-quickbooks-client 4.0.4 requires quickbooks/v3-php-sdk ^5.3.6 -> found quickbooks/v3-php-sdk[5.3.6, ..., v5.4.7.x-dev] but it conflicts with your root composer.json require (^6.0).
- Root composer.json requires spinen/laravel-quickbooks-client ^4.0 -> satisfiable by spinen/laravel-quickbooks-client[4.0.0, ..., 4.0.4].

`

Redirect URI

Would you mind to kindly show us how to write the redirect URI or callback with your package?

Please Setup Service Context before making get CompanyInfo call

i have followed the documentation still get this error and I don't have a frontend I want to create APIs for sending data in quikcbooks

QuickBooksOnline\API\Exception\SdkException with message
Please Setup Service Context before making get CompanyInfo call

How to install ?

Please let me know, how can i use this package ?
Which thing have to install first and which command should run after installition...
is there anyone ca help ?

Undefined index; givenName

Provider.php in function mapUserToObject(array $user)
'name' => trim(sprintf('%s %s', $user['givenName'], $user['familyName'])),

Happens then QB have empty user name. Just need to add a small check

Laravel 6 migrations

For Laravel 6 the CreateQuickBooksTokenTable needs to be update.
Change line 18 from
$table->unsignedInteger('user_id');
to
$table->unsignedBigInteger('user_id');

quickBooksToken does not exist

Laravel 5.7

Auth::logInUsingId(1)
App\User {#2894
id: 1,
name: "Joel Gomez",
email: "[email protected]",
created_at: "2018-08-19 16:35:35",
updated_at: "2018-08-19 16:35:35",
quickBooksToken: null,

$quickbooks = app('QuickBooks')
BadMethodCallException with message 'Method Illuminate/Database/Query/Builder::quickBooksToken does not exist.'

Model:

hasQuickBooksToken trait issue

I have modified the config file so that my foreign and owner key is set to a company_id field but the issue is that the trait is not tracking the same config settings. Should the traits relationship be updated to also track the config files keys so you could use a universal token for the whole application?

Use a different model for tokens

For example, save auth against a Company model rather than a user, allowing multiple users to access the same connection.

Will fork and PR.

Crud Example - Call to undefined method Spinen\QuickBooks\Client::Add()

I have everything working fine as per your installation, however getting everything to work is a bit difficult.

        // initialize quickbooks link
        $quickbooks = app('QuickBooks');
        // dd($quickbooks->getDataService()->getCompanyInfo());
        $qbinvoice = Invoice::create([
            "Line" => [
            [
                 "Amount" => 100.00,
                 "DetailType" => "SalesItemLineDetail",
                 "SalesItemLineDetail" => [
                   "ItemRef" => [
                     "value" => 1,
                     "name" => "Services"
                   ]
                 ]
            ]
            ],
            "CustomerRef"=> [
                  "value"=> 1
            ],
            "BillEmail" => [
                  "Address" => "[email protected]"
            ],
            "BillEmailCc" => [
                  "Address" => "[email protected]"
            ],
            "BillEmailBcc" => [
                  "Address" => "[email protected]"
            ]
        ]);
        //save the record
        $resultingObj = $quickbooks->Add($qbinvoice);

I'm trying to adapted the crud from the Quickbooks API examples.

invalid_grant

I have a user getting:

QuickBooksOnline\API\Exception\ServiceException
Refresh OAuth 2 Access token with Refresh Token failed. Body: [{"error":"invalid_grant"}].

While other users continue to connect without issue.

This is the example database row stored when issue happens:
Screen Shot 2021-07-01 at 2 12 17 PM

As referenced in the thread response by @ssfinney on #27

Could it be caused by calling "$qbClient = app('Spinen\QuickBooks\Client');" in multiple tabs/sessions?

I had a similar issue and was addressed by two things, one is making sure refreshing the (access) token is only done when it has expired (not calling it multiple times). Two, this I suspect some people may miss reading on the documentation, refreshing the access token can also return a new RefreshToken, make sure to use the new one for subsequent refresh calls.

Pasted from the doc:

Even though the refresh token is valid for 100 days, the value of refresh token can change every 24-26 hour period. Hence, you might encounter a situation where the request token that you received first is different than the latest one. As a best practice, always store the latest refresh token received from the API response and use that to make subsequent calls to obtain a new pair of tokens.

Also an additional note, some care must be taken when refreshing, making sure it does not get called multiple times (from differing sessions, etc). I used a static/class object to indicate.

Hope this helps to some weary developer :-)

Installation issue on Laravel 10.39.0

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - spinen/laravel-quickbooks-client[1.0.0, ..., 1.0.2, 2.0.0, ..., 2.0.1] require illuminate/database ^5.5 -> found illuminate/database[v5.5.0, ..., v5.8.36] but it conflicts with your root composer.json require (v10.39.0).
    - spinen/laravel-quickbooks-client[3.0.0, ..., 3.0.1] require illuminate/database 5.5.*|5.6.*|5.7.*|5.8.* -> found illuminate/database[v5.5.0, ..., v5.8.36] but it conflicts with your root composer.json require (v10.39.0).
    - spinen/laravel-quickbooks-client 3.0.2 requires illuminate/database 5.5.*|5.6.*|5.7.*|5.8.*|6.0.* -> found illuminate/database[v5.5.0, ..., v5.8.36, v6.0.0, ..., v6.0.4] but it conflicts with your root composer.json require (v10.39.0).
    - spinen/laravel-quickbooks-client 3.1.0 requires illuminate/database ~5.5|~6 -> found illuminate/database[v5.5.0, ..., v5.8.36, v6.0.0, ..., v6.20.44] but it conflicts with your root composer.json require (v10.39.0).
    - spinen/laravel-quickbooks-client[4.0.0, ..., 4.0.3] require illuminate/database ~5.5|~6|~7 -> found illuminate/database[v5.5.0, ..., v5.8.36, v6.0.0, ..., v6.20.44, v7.0.0, ..., v7.30.6] but it conflicts with your root composer.json require (v10.39.0).
    - spinen/laravel-quickbooks-client 4.0.4 requires illuminate/database ~5.5|~6|~7|~8 -> found illuminate/database[v5.5.0, ..., v5.8.36, v6.0.0, ..., v6.20.44, v7.0.0, ..., v7.30.6, v8.0.0, ..., v8.83.27] but it conflicts with your root composer.json require (v10.39.0).
    - Root composer.json requires spinen/laravel-quickbooks-client * -> satisfiable by spinen/laravel-quickbooks-client[1.0.0, 1.0.1, 1.0.2, 2.0.0, 2.0.1, 3.0.0, 3.0.1, 3.0.2, 3.1.0, 4.0.0, ..., 4.0.4].

You can also try re-running composer require with an explicit version constraint, e.g. "composer require spinen/laravel-quickbooks-client:*" to figure out if any version is installable, or "composer require spinen/laravel-quickbooks-client:^2.1" if you know which you need.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

syntax error, unexpected 'foreach' (T_FOREACH), expecting ']'

When creating my line items I'm trying a foreach loop as so:

            "Line" => [
                foreach ($bill->items as $item) {
                [
                    "Amount" => $item->total,
                    "DetailType" => "SalesItemLineDetail",
                    "SalesItemLineDetail" => [
                        "ItemRef" => [
                            // "value" => 1,
                            "name" => $item->costcode->desc
                        ]
                    ]
                ],
                }
            ],

but I'm running into that error.

Laravel v7 NOT NULL constraint error

I just installed your package in a Laravel 7 application.

After connecting to Quickbooks, and saving the token I get this error:

[2020-05-19 11:51:00] local.ERROR: SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: quickbooks_tokens.id (SQL: insert into "quickbooks_tokens" ("user_id", "access_token", "access_token_expires_at", "realm_id", "refresh_token", "refresh_token_expires_at", "updated_at", "created_at") values (1,...)

I managed to fix it by editing the "quickbooks_tokens" migration file - the "id" column from this:
$table->unsignedBigInteger('id');
to this:
$table->id();

Should I create a pull request?
Or publishing the vendor-migrations in my project should suffice?

Error installing

Hello, running into an issue installing on my staging server, this one has me stumped. Package installs with latest version of laravel on my local dev with no issues whatsoever but for some reason i'm getting the following error elsewheres. The staging server I am updating on also is up to date. Any ideas?

 Error
  Call to a member function name() on array
  at vendor/spinen/laravel-quickbooks-client/src/Providers/ServiceProvider.php:92
    88|                           ->namespace('Spinen\QuickBooks\Http\Controllers')
    89|                           ->group(function (Router $router) use ($config) {
    90|                               $router->get($config['paths']['connect'], 'Controller@connect')
    91|                                      ->middleware($config['middleware']['authenticated'])
  > 92|                                      ->name('connect');
    93|
    94|                               $router->delete($config['paths']['disconnect'], 'Controller@disconnect')
    95|                                      ->middleware($config['middleware']['authenticated'])
    96|                                      ->name('disconnect');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.