Downloads
Stars
Version
PHP wrapper for connecting to the QuickBooks Online V3 REST API.
composer require XX
php artisan vendor:publish
php artisan migrate
Dont forget to add \Keggermont\LaravelQuickbooks\QuickbooksServiceProvider::class into your config/app.php file
You can edit the file config/quickbooks.php for setup your configuration. You can use the playground for generate your accessToken, refreshToken, RealmID etc .. ( https://developer.intuit.com/v2/ui#/playground )
You have access to few commands :
php artisan quickbooks:import-accounts
php artisan quickbooks:import-taxcodes
php artisan quickbooks:refresh-objects
Import data from Quickbooks to the table quickbooks_accounts. More information about Account :
Import data from Quickbooks to the table quickbooks_tax_rates and quickbooks_tax_codes. More information about TaxRate and TaxCode :
Import objects data from Quickbooks (Bill, PurchaseOrder, Invoice, CreditMemo) to the table quickbooks_entities. More information about objects :
You have access to 4 new entities (with Eloquent) :
You can make some events with Eloquent for listening changes.
https://github.com/intuit/QuickBooks-V3-PHP-SDK
You can access to the dataService with :
$Qb = Keggermont\LaravelQuickbooks\Helpers\Quickbooks::getInstance();
$dataService = $Qb->getDataService();
Sample code for playing with the Api :
/* Dump all Invoices */
$Qb = Keggermont\LaravelQuickbooks\Helpers\Quickbooks::getInstance();
$dataService = $Qb->getDataService();
dump($dataService->query("SELECT * FROM Invoice")
/* Dump an Customer Id */
dump($dataService->FindById("customer",1);
/* Dump all Customers */
dump($dataService->FindAll("customer");
You can have some code example of the library on : https://github.com/IntuitDeveloper/SampleApp-CRUD-PHP
Best practice for create or update data with the Quickbooks API is using Transformer.
At start, import the package fractal :
composer require league/fractal
Now you can create your Transformer like :
# File: app/Transformers/QuickbooksCustomerTransformer.php
namespace App\Transformers;
use App\Customer;
use League\Fractal\TransformerAbstract;
class QuickbooksCustomerTransformer extends TransformerAbstract
{
/**
* @param Customer $customer
* @return array
*/
public function transform(Customer $customer)
{
// Append the display name for avoid Vendor/Customer duplication
$displayName = $customer->name." (C)";
$billing_address = $customer->billing_address;
$arr_methods = ["MONEY" => "1","CARD" => "3","WIRE" => "5"];
$arr_conditions = ["NET30" => "3", "NET15" => "2", "NET60" => "4", "DEFAULT" => "1"];
return [
"BillAddr" => [
"Line1" => $billing_address->address,
"Line2" => $billing_address->address_line_2,
"Line3" => null,
"City" => $billing_address->city,
"Country" => $billing_address->country,
"CountrySubDivisionCode" => "FR",
"PostalCode" => $billing_address->zip
],
"GivenName" => $customer->owner->first_name,
"FamilyName" => $customer->owner->name,
"CompanyName" => $customer->name,
"DisplayName" => $displayName,
"SalesTermRef" => ["value" => $arr_conditions[strtoupper($customer->payment_condition)]],
"PaymentMethodRef" => ["value" => $arr_methods[strtoupper($customer->payment_method)]],
"Notes" => $customer->notes,
"PrintOnCheckName" => $customer->name,
"PrimaryPhone" => [
"FreeFormNumber" => $customer->owner->phone
],
"PrimaryEmailAddr" => [
"Address" => $customer->owner->email
]
];
}
}
Now you can create the customer with Quickbooks :
use Keggermont\LaravelQuickbooks\Helpers\Quickbooks;
use App\Transformers\QuickbooksCustomerTransformer;
use QuickBooksOnline\API\Facades\Customer;
$Qb = Quickbooks::getInstance();
$dataService = $Qb->getDataService();
$customerObj = App\Customer::firstOrFail();
$customerQuickbooks = (new QuickbooksCustomerTransformer)->transform($customerObj);
$theResourceObj = Customer::create($customerQuickbooks);
$resultingObj = $dataService->Add($theResourceObj);