2017 © Pedro Peláez
 

library laravel-shopify

Laravel shopify package

image

oseintow/laravel-shopify

Laravel shopify package

  • Tuesday, May 8, 2018
  • by oseintow
  • Repository
  • 11 Watchers
  • 46 Stars
  • 10,801 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 15 Forks
  • 10 Open issues
  • 9 Versions
  • 21 % Grown

The README.md

Laravel Shopify

Laravel Shopify is a simple package which helps to build robust integration into Shopify., (*1)

Installation

Add package to composer.json, (*2)

composer require oseintow/laravel-shopify

Laravel 5.5+

Package auto discovery will take care of setting up the alias and facade for you, (*3)

Laravel 5.4 <

Add the service provider to config/app.php in the providers array., (*4)

<?php

'providers' => [
    ...
    Oseintow\Shopify\ShopifyServiceProvider::class,
],

Setup alias for the Facade, (*5)

<?php

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

Configuration

Laravel Shopify requires connection configuration. You will need to publish vendor assets, (*6)

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, (*7)

Usage

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

They are:, (*9)

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, (*10)

use Oseintow\Shopify\Facades\Shopify;

Route::get("install_shop",function()
{
    $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, (*11)

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

    dd($accessToken);

    // redirect to success page or billing etc.
});

To verify request(hmac), (*12)

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

    if(Shopify::verifyRequest($queryString)){
        logger("verification passed");
    }else{
        logger("verification failed");
    }
}

To verify webhook(hmac), (*13)


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, (*14)

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., (*15)

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

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

To pass query params, (*17)

// 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:, (*18)

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)
            ->setAccessToken($accessToken)
            ->get('admin/products.json');

        $products->each(function($product){
             \Log::info($product->title);
        });
    }
}

Miscellaneous

To get Response headers, (*19)

Shopify::getHeaders();

To get specific header, (*20)

Shopify::getHeader("Content-Type");

Check if header exist, (*21)

if(Shopify::hasHeader("Content-Type")){
    echo "Yes header exist";
}

To get response status code or status message, (*22)

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

The Versions

08/05 2018

dev-master

9999999-dev

Laravel shopify package

  Sources   Download

MIT

The Requires

 

by michael osei ntow

07/08 2017

v1.0.7

1.0.7.0

Laravel shopify package

  Sources   Download

MIT

The Requires

 

by michael osei ntow

17/05 2017

v1.0.6

1.0.6.0

Laravel shopify package

  Sources   Download

MIT

The Requires

 

by michael osei ntow

10/04 2017

v1.0.5

1.0.5.0

Laravel shopify package

  Sources   Download

MIT

The Requires

 

by michael osei ntow

03/04 2017

v1.0.4

1.0.4.0

Laravel shopify package

  Sources   Download

MIT

The Requires

 

by michael osei ntow

07/02 2017

v1.0.3

1.0.3.0

Laravel shopify package

  Sources   Download

MIT

The Requires

 

by michael osei ntow

12/10 2016

v1.0.2

1.0.2.0

Laravel shopify package

  Sources   Download

MIT

The Requires

 

by michael osei ntow

15/09 2016

v1.0.1

1.0.1.0

Laravel shopify package

  Sources   Download

MIT

The Requires

 

by michael osei ntow

15/09 2016

v1.0.0

1.0.0.0

Laravel shopify package

  Sources   Download

MIT

The Requires

 

by michael osei ntow