2017 © Pedro Peláez
 

library shopify-api-client

Lightweight multi-paradigm PHP (JSON) client for the Shopify API.

image

wic/shopify-api-client

Lightweight multi-paradigm PHP (JSON) client for the Shopify API.

  • Tuesday, August 16, 2016
  • by GaryPEGEOT-WIC
  • Repository
  • 2 Watchers
  • 0 Stars
  • 1,724 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 105 Forks
  • 0 Open issues
  • 7 Versions
  • 2 % Grown

The README.md

shopify.php

Lightweight multi-paradigm PHP (JSON) client for the Shopify API., (*1)

Installation

With Composer:, (*2)

composer require wic/shopify-api-client

Requirements

Getting Started

Basic needs for authorization and redirecting, (*3)

getAccessToken($_GET['code']);
        if ($_SESSION['token'] != '')
            $_SESSION['shop'] = $_GET['shop'];
    
        header("Location: index.php");
        exit;       
    }
    // if they posted the form with the shop name
    else if (isset($_POST['shop'])) {
    
        // Step 1: get the shopname from the user and redirect the user to the
        // shopify authorization page where they can choose to authorize this app
        $shop = isset($_POST['shop']) ? $_POST['shop'] : $_GET['shop'];
        $shopifyClient = new ShopifyClient($shop, "", SHOPIFY_API_KEY, SHOPIFY_SECRET);
    
        // get the URL to the current page
        $pageURL = 'http';
        if ($_SERVER["HTTPS"] == "on") { $pageURL .= "s"; }
        $pageURL .= "://";
        if ($_SERVER["SERVER_PORT"] != "80") {
            $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
        } else {
            $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
        }
    
        // redirect to authorize url
        header("Location: " . $shopifyClient->getAuthorizeUrl(SHOPIFY_SCOPE, $pageURL));
        exit;
    }
    
    // first time to the page, show the form below
?>
    <p>Install this app in a shop to get access to its private admin data.</p> 

    <p style="padding-bottom: 1em;">
        <span class="hint">Don&rsquo;t have a shop to install your app in handy? <a href="https://app.shopify.com/services/partners/api_clients/test_shops">Create a test shop.</a></span>
    </p> 

    <form action="" method="post">
      <label for='shop'><strong>The URL of the Shop</strong> 
        <span class="hint">(enter it exactly like this: myshop.myshopify.com)</span> 
      </label> 
      <p> 
        <input id="shop" name="shop" size="45" type="text" value="" /> 
        <input name="commit" type="submit" value="Install" /> 
      </p> 
    </form>

Once you have authorized and stored the token in the session, you can make API calls, (*4)

Making API calls:, (*5)

call('GET', '/admin/products.json', array('published_status'=>'published'));


        // Create a new recurring charge
        $charge = array
        (
            "recurring_application_charge"=>array
            (
                "price"=>10.0,
                "name"=>"Super Duper Plan",
                "return_url"=>"http://super-duper.shopifyapps.com",
                "test"=>true
            )
        );

        try
        {
            $recurring_application_charge = $sc->call('POST', '/admin/recurring_application_charges.json', $charge);

            // API call limit helpers
            echo $sc->callsMade(); // 2
            echo $sc->callsLeft(); // 498
            echo $sc->callLimit(); // 500

        }
        catch (ShopifyApiException $e)
        {
            // If you're here, either HTTP status code was >= 400 or response contained the key 'errors'
        }

    }
    catch (ShopifyApiException $e)
    {
        /* 
         $e->getMethod() -> http method (GET, POST, PUT, DELETE)
         $e->getPath() -> path of failing request
         $e->getResponseHeaders() -> actually response headers from failing request
         $e->getResponse() -> curl response object
         $e->getParams() -> optional data that may have been passed that caused the failure

        */
    }
    catch (ShopifyCurlException $e)
    {
        // $e->getMessage() returns value of curl_errno() and $e->getCode() returns value of curl_ error()
    }
?>

When receiving requests from the Shopify API, validate the signature value:, (*6)

validateSignature($_GET))
        die('Error: invalid signature.');

?>

The Versions

16/08 2016

dev-master

9999999-dev

Lightweight multi-paradigm PHP (JSON) client for the Shopify API.

  Sources   Download

GNU GPL V3

The Requires

  • ext-curl *
  • ext-json *
  • php >= 5.4.0

 

by Gary PEGEOT
by Colin McDonald

17/12 2015

v1.0.5

1.0.5.0

Lightweight multi-paradigm PHP (JSON) client for the Shopify API.

  Sources   Download

GNU GPL V3

The Requires

  • php >= 5.4.0
  • ext-curl *
  • ext-json *

 

by Gary PEGEOT
by Colin McDonald

28/10 2015

v1.0.4

1.0.4.0

Lightweight multi-paradigm PHP (JSON) client for the Shopify API.

  Sources   Download

GNU GPL V3

The Requires

  • php >= 5.4.0
  • ext-curl *
  • ext-json *

 

by Gary PEGEOT
by Colin McDonald

22/10 2015

v1.0.3

1.0.3.0

Lightweight multi-paradigm PHP (JSON) client for the Shopify API.

  Sources   Download

GNU GPL V3

The Requires

  • php >= 5.4.0
  • ext-curl *
  • ext-json *

 

by Gary PEGEOT
by Colin McDonald

13/10 2015

v1.0.2

1.0.2.0

Lightweight multi-paradigm PHP (JSON) client for the Shopify API.

  Sources   Download

GNU GPL V3

The Requires

  • php >= 5.4.0
  • ext-curl *
  • ext-json *

 

by Gary PEGEOT
by Colin McDonald

13/10 2015

v1.0.1

1.0.1.0

Lightweight multi-paradigm PHP (JSON) client for the Shopify API.

  Sources   Download

GNU GPL V3

The Requires

  • php >= 5.4.0
  • ext-curl *
  • ext-json *

 

by Gary PEGEOT
by Colin McDonald

13/10 2015

v1.0.0

1.0.0.0

Lightweight multi-paradigm PHP (JSON) client for the Shopify API.

  Sources   Download

GNU GPL V3

The Requires

  • php 5.4
  • ext-curl *
  • ext-json *

 

by Gary PEGEOT
by Colin McDonald