Package Data | |
---|---|
Maintainer Username: | BryanYeh |
Maintainer Contact: | BryanYeh@users.noreply.github.com (B Y) |
Package Create Date: | 2017-08-27 |
Package Last Update: | 2018-02-25 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-23 03:01:22 |
Package Statistics | |
---|---|
Total Downloads: | 227 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 5 |
Total Watchers: | 3 |
Total Forks: | 1 |
Total Open Issues: | 0 |
This package is only for Laravel integration with Shopify's API to make a public app
Using command line
composer require bryanyeh/shopify-laravel 1.10
Edit your .env
file add and replace with no < >
SHOPIFY_API_KEY=<replace with api key>
SHOPIFY_API_SECRET=<replace with api secret>
SHOIFY_API_SCOPES=<replace with scopes seperated by commas like: read_products,write_products,read_draft_orders>
Add to providers arrray in config/app.php
Bryanyeh\Shopify\Providers\ShopifyServiceProvider::class,
Add to aliases array in config/app.php
'Shopify' => Bryanyeh\Shopify\Facades\Shopify::class,
Add to routeMiddleware array in app/http/Kernel.php
'shopifyrequest' => \Bryanyeh\Shopify\Middleware\VerifyRequest::class,
'shopifynonce' => \Bryanyeh\Shopify\Middleware\VerifyNonce::class,
'shopifywebhook' => \Bryanyeh\Shopify\Middleware\VerifyWebHook::class,
'shopifyproxy' => \Bryanyeh\Shopify\Middleware\VerifyProxy::class,
In the command line
php artisan vendor:publish --provider="Bryanyeh\Shopify\Providers\ShopifyServiceProvider"
Make sure to use use Bryanyeh\Shopify\Facades\Shopify;
wherever you are planning to use this package.
Make sure to use the middleware shopifyrequest
use Bryanyeh\Shopify\Facades\Shopify;
Route::get('install', function(Request $request){
return redirect(Shopify::init($request->input('shop'))->install('https://example.com/confirm'));
})->middleware('shopifyrequest');
To do this you will need to use the middlewares shopifynonce
and shopifyrequest
use Bryanyeh\Shopify\Facades\Shopify;
Route::get('confirm', function(Request $request){
$access_token = Shopify::init($request->input('shop'))->getAccessToken($request->input('code'))['access_token'];
//save the access_token for later use
//redirect to success or billing page
})->middleware('shopifynonce', 'shopifyrequest');
Simply use the middleware shopifywebhook
Simply use the middleware shopifyproxy
use Bryanyeh\Shopify\Facades\Shopify;
$geturi = '/admin/products/count.json' ;
$posturi = '/admin/products.json';
$puturi = '/admin/products/632910392.json';
$deleteuri = '/admin/products/632910392.json';
$shop = Shopify::init($my_shopify_store,$access_token);
$shop->get($geturi, [if any]);
$shop->post($posturi, [data]);
$shop->put($puturi, [data]);
$shop->delete($deleteuri);
Everything that gets will be in a form of an array containing:
statusCode : 200 or 400 or status code
reasonPhrase : just a phrase that goes with the status code
callLimit : HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT
???? : expected response data shopify returns
shopifywebhook
returns 401 error when hmac is invalidshopifyproxy
returns 401 error when signature or domain are invalidshopifynonce
and shopifyrequest
, will redirect to a named route re-auth
, with this you can decide what to do if either the nonce or request is invalidThis package throws only 1 exception.
InvalidMethodRequestException
get/post/put/delete
is allowed, look at Acessing API Resource
app/Http/Middleware/VerifyCsrfToken.php
in the except
arrayLaravel Shopify is licensed under MIT License (MIT).