GithubHelp home page GithubHelp logo

bryanyeh / shopify-laravel Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 1.0 10 KB

Laravel 5.4 package to interact with Shopify API to create public app

License: MIT License

PHP 100.00%
shopify-api laravel-5-package laravel54 laravel-package

shopify-laravel's Introduction

Laravel Shopify

This package is only for Laravel integration with Shopify's API to make a public app

Latest Stable Version Total Downloads License

Requirements

  • Laravel 5.4
  • PHP 7+

Installation

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" 

Usage:

Make sure to use use Bryanyeh\Shopify\Facades\Shopify; wherever you are planning to use this package.

Asking for permission to install the app

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');

Retreiving the access token

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');

Verifying webhooks

Simply use the middleware shopifywebhook

Verifying proxy requests

Simply use the middleware shopifyproxy

Accessing API resource

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

Middlewares

  • shopifywebhook returns 401 error when hmac is invalid
  • shopifyproxy returns 401 error when signature or domain are invalid
  • shopifynonce 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 invalid

Errors

This package throws only 1 exception.

Notes:

  • Nonce is automatically taken care for you
  • Make sure to add your incoming webhook routes to the app/Http/Middleware/VerifyCsrfToken.php in the except array

License

Laravel Shopify is licensed under MIT License (MIT).

shopify-laravel's People

Contributors

bryanyeh avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

sltwtr-admin

shopify-laravel's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.