-
-
Notifications
You must be signed in to change notification settings - Fork 374
Usage
Here's some helpful tips on using this package's facade.
Simply use Laravel's Auth::user()
.
Controller example:
In routes/web.php:
Route::get('shopify', 'ShopifyController@index')->middleware(['auth.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();
Log::info('This is the Shop Object: '.json_encode($shop));
return;
}
}
?>
// Returns instance of \Osiset\BasicShopifyAPI (osiset/basic-shopify-api)
$shop = Auth::user();
$shop->api()->rest(...);
Example:
$shop = Auth::user();
$request = $shop->api()->rest('GET', '/admin/shop.json');
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;
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();
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.
- Plus Plans: 2 calls per 500ms (4 calls per second)
- Regular Plans: 1 call per 500ms (2 calls per second)
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
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.
For more information on Shopify's rate limiting, see Shopify's documentation.
For more information on rate limiting features, see BasicShopifyAPI.
road map
Welcome to the wiki!
Please see the homepage for a list of relevant pages.