Skip to content

dSpaceLabs/shopify-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shopify Client Build Status

PHP Shopify Client for easy integration into your projects and apps

  • PHP Client for working with the Shopify API
  • Source code is well documented
  • Heavily tested and maintained
  • Production Shopify Apps are using
  • Maintain a high standard of code quality Code Climate
  • Private apps support

Requirements

Installation

composer require "dspacelabs/shopify:^1.0@dev"

Usage

Redirect user to Shopify to authorize your application

<?php

use Dspacelabs\Component\Shopify\Client;

$client = new Client($accessKey, $secretKey);
$client->setShop('example.myshopify.com');
// This is the same thing as doing the entire domain
//$client->setShop('example');

// List of scopes can be in the Client class
$client->setScopes(
    array(
        Client::SCOPE_WRITE_CUSTOMERS,
        Client::SCOPE_READ_CUSTOMERS
    )
);

$nonce = time(); // Save in session, used in callback action

$authorizationUri = $client->getAuthorizationUrl('https://example.com/shopify/callback', $nonce);
// redirect user to $authorizationUri

Shopify redirects user back to your callback url

<?php

use Dspacelabs\Component\Shopify\Client;

if (!$session->has('nonce')) {
    throw new AccessedDeniedError();
}

$client = new Client($accessKey, $secretKey);
$client->setShop('example.myshopify.com');

// `isValid` takes array of query parameters, think $_GET, $_POST, etc.
// This example is using a Request object from the symfony/http-foundation
// library
if (!$client->isValid($request->query->all())) {
    throw new \AccessDeniedError();
}

// Persist access token in database
$accessToken = $client->getAccessToken($request->query->get('code'));

Making requests to Shopify

<?php

use Dspacelabs\Component\Shopify\Client;

$client = new Client($accessKey, $secretKey):
$client
    ->setShop('example.myshopify.com')
    ->setAccessToken($accessToken);

$result = $client->call('GET', '/admin/customers.json');

// Process $result

Recurring application charges

@todo

Creating and using webhooks

@todo

Private Apps

See Generate private app credentials.

<?php

use Dspacelabs\Component\Shopify\Client;

/**
 * The API Key and Password are generated for you on Shopify once you create
 * Your private app. Those are the credentials you need here.
 */
$client = new Client($apiKey, $password):
$client
    ->setPrivate(true)
    ->setShop('example.myshopify.com');

Applications using this library