Laravel shopify package

v2.0.0 2019-12-17 04:14 UTC

This package is auto-updated.

Last update: 2023-03-19 05:37:53 UTC


Laravel Shopify is a simple package which helps to build robust integration into Shopify.


Add package to composer.json

composer require oseintow/laravel-shopify

Laravel 5.5+

Package auto discovery will take care of setting up the alias and facade for you

Laravel 5.4 <

Add the service provider to config/app.php in the providers array.


'providers' => [

Setup alias for the Facade


'aliases' => [
    'Shopify' => Oseintow\Shopify\Facades\Shopify::class,


Laravel Shopify requires connection configuration. You will need to publish vendor assets

php artisan vendor:publish

This will create a shopify.php file in the config directory. You will need to set your API_KEY and SECRET


To install/integrate a shop you will need to initiate an oauth authentication with the shopify API and this require three components.

They are:

1. Shop URL (eg. example.myshopify.com)
2. Scope (eg. write_products, read_orders, etc)
3. Redirect URL (eg. http://mydomain.com/process_oauth_result)

This process will enable us to obtain the shops access token

use Oseintow\Shopify\Facades\Shopify;

    $shopUrl = "example.myshopify.com";
    $scope = ["write_products","read_orders"];
    $redirectUrl = "http://mydomain.com/process_oauth_result";

    $shopify = Shopify::setShopUrl($shopUrl);
    return redirect()->to($shopify->getAuthorizeUrl($scope,$redirectUrl));

Let's retrieve access token

Route::get("process_oauth_result",function(\Illuminate\Http\Request $request)
    $shopUrl = "example.myshopify.com";
    $accessToken = Shopify::setShopUrl($shopUrl)->getAccessToken($request->code);

    // redirect to success page or billing etc.

To verify request(hmac)

public function verifyRequest(Request $request)
    $queryString = $request->getQueryString();

        logger("verification passed");
        logger("verification failed");

To verify webhook(hmac)

public function verifyWebhook(Request $request)
    $data = $request->getContent();
    $hmacHeader = $request->server('HTTP_X_SHOPIFY_HMAC_SHA256');

    if (Shopify::verifyWebHook($data, $hmacHeader)) {
        logger("verification passed");
    } else {
        logger("verification failed");

To access API resource use

Shopify::get("resource uri", ["query string params"]);
Shopify::post("resource uri", ["post body"]);
Shopify::put("resource uri", ["put body"]);
Shopify::delete("resource uri");

Let use our access token to get products from shopify.

NB: You can use this to access any resource on shopify (be it Product, Shop, Order, etc)

$shopUrl = "example.myshopify.com";
$accessToken = "xxxxxxxxxxxxxxxxxxxxx";
$products = Shopify::setShopUrl($shopUrl)->setAccessToken($accessToken)->get("admin/products.json");

To pass query params

// returns Collection
$shopify = Shopify::setShopUrl($shopUrl)->setAccessToken($accessToken);
$products = $shopify->get("admin/products.json", ["limit"=>20, "page" => 1]);

Controller Example

If you prefer to use dependency injection over facades like me, then you can inject the Class:

use Illuminate\Http\Request;
use Oseintow\Shopify\Shopify;

class Foo
    protected $shopify;

    public function __construct(Shopify $shopify)
        $this->shopify = $shopify;

    * returns Collection
    public function getProducts(Request $request)
        $products = $this->shopify->setShopUrl($shopUrl)



To get Response headers


To get specific header


Check if header exist

    echo "Yes header exist";

To get response status code or status message

Shopify::getStatusCode(); // 200
Shopify::getReasonPhrase(); // ok