1. Go to this page and download the library: Download shopgpt/shopify-integration 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/ */
public function getKey();
public function shopifyDomain(): string;
public function shopifyExternalId(): ?string;
public function shopifyAccessToken(): ?string;
public function shopifyRefreshToken(): ?string;
public function shopifyTokenExpiresAt(): ?DateTimeInterface;
public function shopifyScopes(): ?string;
public function shopifyIsInstalled(): bool;
use ShopGPT\ShopifyIntegration\Concerns\InteractsWithShopifyStore;
use ShopGPT\ShopifyIntegration\Contracts\ShopifyStore;
class Integration extends Model implements ShopifyStore
{
use InteractsWithShopifyStore;
}
class AuthenticateStoreOwner
{
public function handle($request, Closure $next)
{
$storeUserId = ShopifyIntegration::currentStore()?->user_id;
if ($storeUserId && $user = User::find($storeUserId)) {
Auth::setUser($user);
}
return $next($request);
}
}
class Integration extends Model implements ShopifyStore
{
use InteractsWithShopifyStore;
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}
try {
$store->api()->graphql($query);
} catch (StoreUninstalledException $e) {
// already flagged; your StoreUninstalled listeners have run
} catch (RateLimitedException $e) {
$this->release($e->retryAfter);
} catch (StoreUnavailableException $e) {
// still installed — try again later
}
// StoreScopesUpdated — what actually moved
$event->gained(); // ['write_products']
$event->lost(); // ['read_orders'] — calls needing these now 403
// StoreProfileUpdated — the one that matters for billing
$event->planChanged(); // the plan is not what it was — dev store went live?
$event->previousPlan; // and $event->currentPlan
// TokenRefreshFailed — false means the current token is still usable and
// the next call retries; true means the merchant must re-authorise
$event->fatal;
$context->store; // ShopifyStore
$context->shopData; // array — raw shop.json
$context->viaTokenExchange; // bool — arrived embedded, not through the redirect
$context->scopes; // string|null — what Shopify granted
$context->host; // string|null — the host param, embedded only
$context->domain(); // acme.myshopify.com
$context->email();
$context->profile(); // the 11 profile fields, read from shop.json
$context->isDevelopmentStore();
'topics' => [
'app/uninstalled' => HandleAppUninstalled::class,
'app/scopes_update' => HandleScopesUpdate::class,
'shop/update' => HandleShopUpdate::class,
'shop/redact' => HandleShopRedact::class,
'customers/redact' => HandleCustomersRedact::class,
'customers/data_request' => HandleCustomersDataRequest::class,
// Any other topic you subscribe to, mapped to your own job:
// 'your/topic' => App\Jobs\YourHandler::class,
],
use ShopGPT\ShopifyIntegration\Jobs\WebhookJob;
class YourHandler extends WebhookJob
{
public function handle(): void
{
$this->store(); // ?ShopifyStore, resolved through your repository
$this->topic; // the topic this was registered under
$this->payload; // array
$this->webhookId; // X-Shopify-Webhook-Id
$this->resourceId(); // $payload['id']
}
}