Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
Sanjay-100 edited this page Mar 31, 2022 · 20 revisions

Here's some helpful tips on using this package's facade.

Accessing the current shop

Simply use Laravel's Auth::user().

Controller example:

In routes/web.php:

Route::get('shopify', 'ShopifyController@index')->middleware(['verify.shopify']);

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Log;

class ShopifyController extends Controller
{
    public function index() {
        $shop = Auth::user();
        $domain = $shop->getDomain()->toNative();
        $shopApi = $shop->api()->rest('GET', '/admin/shop.json')['body']['shop'];

        Log::info("Shop {$domain}'s object:" . json_encode($shop));
        Log::info("Shop {$domain}'s API objct:" . json_encode($shopApi));
        return;
    }
}

?>

Accessing API for the current shop

// Underlying API package (osiset/basic-shopify-api)
$shop = Auth::user();
$shop->api()->rest(...);
$shop->api()->graph(...);

Example:

$shop = Auth::user();
$request = $shop->api()->rest('GET', '/admin/shop.json');
// $request = $shop->api()->graph('{ shop { name } }');
echo $request['body']['shop']['name'];

Example with parameters:

$shop = Auth::user();
$request = $shop->api()->rest('GET', '/admin/api/customers/search.json', ['query' => "phone:{$phone}"]);
echo $request['body']['customers'];

Example POST with payload:

$shop = Auth::user();
$request = $shop->api()->rest('POST', '/admin/api/customers/customer.json', ['customer' => "phone:{$phone}"]);
echo $request['body']['customers'];

Accessing Shop's plan charge

For single/recurring/credit type charges, you can access them via the Charge model's retrieve method for charges which exist in the database for a shop.

Example:

use Osiset\ShopifyApp\Services\ChargeHelper;

$shop = Auth::user();
$chargeHelper = app()->make(ChargeHelper::class);
$charge = $chargeHelper->chargeForPlan($shop->plan->getId(), $shop);
$chargeApi = $chargeHelper->useCharge($charge->getReference())->retrieve(); 

Rate Limiting

Info

The package (through BasicShopifyAPI library) has the ability to handle basic rate limiting to ensure your API requests will run a single API call during x milliseconds for REST, and for GraphQL it will ensure only x points are used within 1 second.

Limits

  • Plus Plans (REST): 2 calls per 500ms (4 calls per second)

  • Regular Plans (REST): 1 call per 500ms (2 calls per second)

  • Plus Plans (GraphQL): 100 points per 1s

  • Regular Plans (GraphQL): 50 points per 1s

Retry

API calls will be retried at a default of two times if the API response code is 500, 429, or 503.

Additional Information

For more information on Shopify's rate limiting, see Shopify's documentation.

For more information on underlying API package features, see BasicShopifyAPI.