-
-
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(['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;
}
}
?>
// 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'];
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 for REST, and for GraphQL it will ensure only x points are used within 1 second.
-
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
API calls will be retried at a default of two times if the API response code is 500, 429, or 503.
For more information on Shopify's rate limiting, see Shopify's documentation.
For more information on underlying API package features, see BasicShopifyAPI.
road map
Welcome to the wiki!
Please see the homepage for a list of relevant pages.