Download the PHP package litvinjuan/laravel-shopify without Composer
On this page you can find all versions of the php package litvinjuan/laravel-shopify. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download litvinjuan/laravel-shopify
More information about litvinjuan/laravel-shopify
Files in litvinjuan/laravel-shopify
Package laravel-shopify
Short Description Connect your Laravel application to the Shopify API
License MIT
Homepage https://github.com/litvinjuan/laravel-shopify
Informations about the package laravel-shopify
Connect your Laravel application to the Shopify API
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
Installation
You can install the package via composer:
You can publish and run the migrations with:
You can publish the config file with:
Setup
The package comes with a default Shop model that you can use. However, if you want to add extra properties or relationships, you'll need to create your own Shop model that implements the ShopContract
interface and uses the ShopTrait
trait.
Note: Remember to also modify the migration before running it to add any additional columns you may need
Then, you have to add your shop model to the package configuration. Publish the configuration if you haven't (using the command in the Installation
section) and change the shop-model
value to your own model:
The next step to set up our Shop owner, which is the model that's related to your shop. Right now, we only support the user as the owner, so go into your User model and add the following interface:
Now, there's two ways in which you can relate your users and shops.
If you want each user to only have one shop, then you should the HasShop
trait. If you want each user to own multiple shops, meaning that one user has access to many shops, use the HasShops
trait.
Note: only include one trait in your model
Once your user model is set up, go into the configuration file once again and change the user-model
value to your own model
The last step is to implement the ShopLoader
. This is a class that will tell shopify how to determine which shop to use during requests. Below is an example of a ShopLoader that works for a user that only has one shop, and simply tells shopify to use the shop of the current authenticated user:
Once you've implemented your own ShopLoader, or used the own provided above, you'll need to add it to the shopify configuration file:
Lastly, you'll need to create an App in your Shopify Developer account, and set up the following variables in your .env
file:
SHOPIFY_API_KEY=
This is your app's api key. You can find it in your app dashboard
SHOPIFY_API_SECRET=
This is your app's api secret. You can find it in your app dashboard
SHOPIFY_API_SCOPES=
If no scopes are provided during an authentication request, shopify will use these.
SHOPIFY_API_CALLBACK_URL=
Callback url to use after the user has installed the app on shopify. Remember to whitelist this URL in your app dashboard.
Usage
This package adds a few things to your laravel application.
First, you have a new middleware signed.shopify
, which verifies that the request is coming from shopify and has a valid signature. Include this middleware in any webhook routes or other requests where you want to verify that the request came from Shopify.
There's also a new Shopify authentication guard, which allows you to authenticate a user when they are viewing your app within the Shopify Admin Panel. You should use this auth guard for any routes that the user may access from within the Shopify Admin Panel, and not through your own website.
Authentication
To authenticate your users in Shopify, you'll need to add two routes: one to redirect the user to Shopify's Oauth screen, and one for the callback from that screen:
In your redirect route, you'll need to receive a shop domain parameter for the Shopify store your user wants to connect to. Then, simply redirect them with the following:
After the user accepts the scopes and installs the app on their Shopify store, they'll be redirected back to your callback url. The last step, is to configure the callback to generate the necessary access token for the shop:
You can also pass a different callback url or scopes as the third and fourth arguments to the redirect method
To interact with the Shopify Api, simply call the api() method in the shop you want to use, and hit the endpoint you want to use
Shopify Facade
The package makes a Shopify Facade available that has a few useful methods.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Juan Litvin
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-shopify with dependencies
illuminate/database Version ^8.0
illuminate/support Version ^8.0
illuminate/http Version ^8.0
ext-json Version *