Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
Omar Guzman edited this page Dec 28, 2018 · 20 revisions

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

Accessing the current shop

Using the facade:

// Returns instance of \OhMyBrew\ShopifyApp\Models\Shop
// For this to properly work your route must be behind auth.shop
// In example: Route::get('shopify', 'ShopifyController@index')->middleware(['auth.shop']);
ShopifyApp::shop()

Accessing API for the current shop

// Returns instance of \OhMyBrew\BasicShopifyAPI (ohmybrew/basic-shopify-api)
$shop = ShopifyApp::shop();
$shop->api()->rest(...);

Example:

$shop = ShopifyApp::shop();
$request = $shop->api()->rest('GET', '/admin/shop.json');
echo $request->body->shop->name;

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:

$shop = ShopifyApp::shop();
$charge = $shop->planCharge();
print_r($charge->retrieve()); // Returns an object of the API data for the charge

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.

Limits

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

Enable

To enable, edit your environment variables or config/shopify-app.php; example (for env variables):

SHOPIFY_API_RATE_LIMITING_ENABLED=true
SHOPIFY_API_RATE_LIMIT_CYCLE=500 # This is default
SHOPIFY_API_RATE_LIMIT_BUFFER=100 # This is default

Notes

This will not handle the 429 Too Many Requests exception from Shopify, but it will track the time it takes to completed one API calls to another, and if the call is too quick, it will calculate the required microseconds needed to sleep before making another call. For 429 specifically, should it ever happen, you'll have to handle this through your own code by checking the API credits remaining.

Additional Information

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

For more information on rate limiting features, see BasicShopifyAPI.

Welcome to the wiki!

Please see the homepage for a list of relevant pages.

Clone this wiki locally