maxepam2015 / shopify-integration
A Laravel package for integrating Shopify API
Package info
github.com/MaxEpam2015/laravel-package-shopify-integration
pkg:composer/maxepam2015/shopify-integration
Requires
- php: ^8.3
- guzzlehttp/guzzle: ^7.8
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^10.6
- phpunit/phpunit: ^12.0
README
A modern, production-ready Laravel package for connecting your app to Shopify with full OAuth authentication, multi-store support, and Laravel integration.
๐ Why Use This Package
This package provides: โ Deep Laravel integration (service providers, routers, requests, services, tests, middleware, artisan command, migration) ๐ Production-ready OAuth authentication and shop session management ๐งโ๐ผ Multi-store token handling ๐งฐ Easy access to Shopify REST and GraphQL APIs ๐งฉ Configuration, migrations, and routing out of the box ๐งช Testable, extensible architecture for your own Shopify apps
With this package, you spend less time writing boilerplate and more time building features merchants love.
โ๏ธ Prerequisites
Before you begin, make sure you have:
-
PHP 8.3+
-
Laravel 10+
-
Composer installed
-
A Shopify Partner Account to create your app and get credentials
-
A Shopify development store for testing
-
ngrok for HTTPS tunneling during local OAuth testing
๐งฉ Step 1: Install the Package
From your Laravel project root:
composer require maxepam2015/shopify-integration
If developing locally via path repository, ensure your main project composer.json includes:
"repositories": [
{
"type": "path",
"url": "packages/Max/ShopifyIntegration"
}
]
โ๏ธ Step 2: Publish Config and Migration Files
php artisan vendor:publish --provider="Max\ShopifyIntegration\ShopifyServiceProvider"
This publishes:
- config/shopify.php
- database/migrations/2025_10_09_856483_create_shopify_stores_table.php
๐๏ธ Step 3: Run the Migrations
php artisan migrate
This creates the shopify_stores table used to store connected shops and their OAuth tokens.
๐ Step 4: Configure Your App Credentials
Edit your .env file:
SHOPIFY_API_KEY=your-shopify-api-key SHOPIFY_API_SECRET=your-shopify-api-secret SHOPIFY_API_SCOPES=read_products,write_products SHOPIFY_REDIRECT_URI=https://your-ngrok-url.ngrok-free.dev/api/shopify/callback SHOPIFY_API_VERSION=2025-01
make sure your settings match your Shopify app dashboard (especially API Key, Secret, Scopes, Redirect URLs).
๐งญ Step 5: Update Your Shopify App URLs
In your Shopify Partner Dashboard โ App setup:
| Field | Value |
|---|---|
| App URL | https://your-ngrok-url.ngrok-free.dev |
| Allowed redirection URL(s) | https://your-ngrok-url.ngrok-free.dev/api/shopify/callback |
๐ ๏ธ Step 6: OAuth Flow (No /install Route)
Merchants (or you, for your dev store) can install the app manually using the direct OAuth URL below:
https://your-store.myshopify.com/admin/oauth/authorize?client_id={SHOPIFY_API_KEY}&scope={SHOPIFY_SCOPES}&redirect_uri={SHOPIFY_REDIRECT_URI}
When authorization completes, Shopify redirects to:
https://your-ngrok-url.ngrok-free.dev/api/shopify/callback?code=xxxx&shop=your-store.myshopify.com
Your package handles this automatically and securely stores the access token in the shopify_stores table.
๐งฉ Step 7: Access Connected Shops via Model
The package includes a ready-to-use Eloquent model:
use Max\ShopifyIntegration\Models\ShopifyStore; $store = ShopifyStore::firstWhere('shop', 'your-store.myshopify.com'); $token = $store->access_token;
๐ Step 8: Fetch Products via API
Once the shop is connected, you can call the /api/shopify/products endpoint:
GET /api/shopify/products?shop=your-store.myshopify.com
Response example:
{
"products": [
{ "id": 123456789, "title": "T-Shirt", "price": "29.99" },
{ "id": 987654321, "title": "Hat", "price": "19.99" }
]
}
Under the hood ShopifyClient dynamically loads the shopโs token and sends the request:
use Max\ShopifyIntegration\Services\ShopifyClient; $shopify = new ShopifyClient('your-store.myshopify.com'); $products = $shopify->getProducts();
๐ Step 9: Middleware Protection (Optional)
You can protect your routes to ensure only connected stores access them:
Route::middleware(['auth.shopify'])->group(function () { Route::get('/dashboard', [DashboardController::class, 'index']); });
๐ง Step 10: Testing Locally with ngrok
For development, run:
php artisan serve
ngrok http 8000
Use the generated HTTPS URL (e.g., https://your-app.ngrok-free.dev) in your .env and Shopify App setup. Then open:
https://your-store.myshopify.com/admin/oauth/authorize?client_id=your-key&scope=read_products&redirect_uri=https://your-app.ngrok-free.dev/api/shopify/callback
and approve the permissions. After the redirect, your Laravel app will automatically store the access token.
๐งฉ Directory structure
ShopifyIntegration/
โโโ config/shopify.php
โโโ database/migrations/2025_10_09_856483_create_shopify_stores_table.php
โโโ routes/api.php
โโโ src/
โ โโโ Models/ShopifyStore.php
โ โโโ Services/
โ โ โโโ ShopifyClient.php
โ โ โโโ OAuthService.php
โ โ โโโ ProductService.php
โ โโโ Http/
โ โ โโโ Controllers/
โ โ โโโ OAuthController.php
โ โ โโโ ProductController.php
โ โ โโโ Requests/
โ โ โโโ OAuth/
โ โ โโโ CallbackRequest.php
โ โ โโโ InstallRequest.php
โ โ โโโ Product/
โ โ โโโ IndexRequest.php
โ โ โโโ Middleware/
โ โ โโโ AuthenticateShopify.php
โ โโโ ShopifyServiceProvider.php
โโโ tests/
โ โโโ TestCase.php
โ โโโ OAuthControllerTest.php
โ โโโ ShopifyClientTest
โ โโโ ProductControllerTest.php
โโโ composer.json
โโโ phpunit.xml
โโโ README.md
๐งช Testing
Option 1: Run Only the Package Tests
vendor/bin/phpunit
Option 2: run Tests by docker (Package + App)
docker compose up
From your Laravel project root:
๐ค Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
Make sure your PR includes:
- Tests for new or changed functionality
- Clear commit messages
- Code that follows PSR-12 formatting guidelines
๐ License
The MIT License (MIT). Please see License File for more information.