1. Go to this page and download the library: Download amadulhaque/shopify-bridge 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/ */
// app/Providers/AppServiceProvider.php
use App\Shopify\MongoOAuthStateRepository;
use App\Shopify\SubdomainShopResolver;
use App\Shopify\TenantTokenRepository;
use App\Shopify\TenantWebhookRepository;
use Amadulhaque\Shopify\Contracts\OAuthStateRepository;
use Amadulhaque\Shopify\Contracts\ShopResolver;
use Amadulhaque\Shopify\Contracts\TokenRepository;
use Amadulhaque\Shopify\Contracts\WebhookRepository;
public function register(): void
{
$this->app->bind(OAuthStateRepository::class, MongoOAuthStateRepository::class);
$this->app->bind(TokenRepository::class, TenantTokenRepository::class);
$this->app->bind(ShopResolver::class, SubdomainShopResolver::class);
$this->app->bind(WebhookRepository::class, TenantWebhookRepository::class);
}
use App\Shopify\CurrentUserShopAuthorization;
use Amadulhaque\Shopify\Contracts\AuthorizationResolver;
$this->app->bind(AuthorizationResolver::class, CurrentUserShopAuthorization::class);
use App\Http\Controllers\ShopifyInstallController;
use Illuminate\Support\Facades\Route;
Route::get('/shopify/install', [ShopifyInstallController::class, 'install']);
Route::get('/shopify/callback', [ShopifyInstallController::class, 'callback'])
->name('shopify.callback');
namespace App\Http\Controllers;
use App\Shopify\ShopifyInstallationStore;
use Amadulhaque\Shopify\Facades\Shopify;
use Illuminate\Http\Request;
class ShopifyInstallController
{
public function install(Request $request)
{
return Shopify::oauth()->redirect($request->string('shop')->toString());
}
public function callback(Request $request, ShopifyInstallationStore $installations)
{
$result = Shopify::oauth()->exchange($request);
// Your application decides where and how this is persisted/encrypted.
$installations->save($result->shop, $result->token);
return to_route('dashboard');
}
}
$oauth = Shopify::oauth('amad123s.myshopify.com', 'shpat_existing_token');
if (! $oauth->accessTokenIsValid()) {
// Reinstall or ask the merchant to reconnect the app.
}
// The configured shop makes the domain optional here.
$url = Shopify::oauth('amad123s.myshopify.com')->authorizationUrl();
use Amadulhaque\Shopify\Facades\Shopify;
$response = Shopify::graph()
->shop('demo.myshopify.com')
->query('query ($id: ID!) { product(id: $id) { id title } }', [
'id' => 'gid://shopify/Product/1',
]);
if ($response->hasErrors()) {
return response()->json(['errors' => $response->errors()], 422);
}
return response()->json($response->data());
public function __invoke(Request $request)
{
$webhook = $request->attributes->get('shopify.webhook');
ProcessShopifyWebhook::dispatch($webhook);
return response()->noContent();
}
use Amadulhaque\Shopify\Events\ShopInstalled;
use Illuminate\Support\Facades\Event;
Event::listen(ShopInstalled::class, function (ShopInstalled $event) {
// Persist the result, initialize a tenant, or enqueue onboarding work.
});