PHP code example of clevpro / laravel-quickbooks

1. Go to this page and download the library: Download clevpro/laravel-quickbooks library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

clevpro / laravel-quickbooks example snippets


use Clevpro\LaravelQuickbooks\Services\QuickbooksOAuthService;

$quickbooksOAuthService = new QuickbooksOAuthService();
$authUrl = $quickbooksOAuthService->generateAuthUrl();
return redirect($authUrl);

use Clevpro\LaravelQuickbooks\Services\QuickbooksOAuthService;
use Illuminate\Http\Request;

public function callback(Request $request)
{
    $quickbooksOAuthService = new QuickbooksOAuthService();
    $accessTokenData = $quickbooksOAuthService->getAccessToken($request->input('code'));

    // Store the access token, refresh token, and realm ID in the database
    // Example:
    $user = Auth::user();
    $user->quickbooks_access_token = $accessTokenData['access_token'];
    $user->quickbooks_refresh_token = $accessTokenData['refresh_token'];
    $user->quickbooks_realm_id = $accessTokenData['realm_id'];
    $user->save();

    return redirect()->route('dashboard')->with('success', 'QuickBooks connected successfully!');
}

use Clevpro\LaravelQuickbooks\Services\QuickbooksInvoiceService;

$quickbooksInvoiceService = new QuickbooksInvoiceService($user->quickbooks_access_token, $user->quickbooks_realm_id);

$lineItems = [
    [
        "Amount" => 100,
        "DetailType" => "SalesItemLineDetail",
        "SalesItemLineDetail" => [
            "Qty" => 1,
            "UnitPrice" => 100,
            "ItemRef" => [
                "value" => "123" // The ID of a valid QuickBooks item
            ]
        ],
        "Description" => "Consulting services"
    ]
];

$invoiceData = [
    'customer_id' => '1', // Valid customer ID in QuickBooks
    'line_items' => $lineItems
];

$invoice = $quickbooksInvoiceService->createInvoice($invoiceData);

$updatedInvoiceData = [
    'customer_id' => '1',
    'line_items' => $lineItems
];

$updatedInvoice = $quickbooksInvoiceService->updateInvoice($invoiceId, $updatedInvoiceData);

$invoice = $quickbooksInvoiceService->getInvoice($invoiceId);

$pdf = $quickbooksInvoiceService->getInvoicePdf($invoiceId);
return response($pdf, 200)->header('Content-Type', 'application/pdf');
bash
php artisan vendor:publish --provider="Clevpro\LaravelQuickbooks\QuickbooksServiceProvider" --tag=config