PHP code example of clarity-tech / laravel-shopify
1. Go to this page and download the library: Download clarity-tech/laravel-shopify library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
5
Route::get("process_oauth_result",function(\Illuminate\Http\Request $request)
{
$shopifyApi = resolve('shopify');
$myShopifyDomain = $request->shop;
$code = $request->code;
$token = $shopifyApi
->setShopDomain($myShopifyDomain)
->getAccessToken($code);
//this gets access token from shopify and set it to the current instance which will be passed in further api calls
dd($accessToken);
//store the access token for future api calls on behalf of the shop
// redirect to success page or billing etc.
});
5
use ClarityTech\Shopify\Facades\Shopify;
public function verifyRequest(Request $request)
{
$params = $request->all();
if (Shopify::verifyRequest($params)){
logger("verification passed");
}else{
logger("verification failed");
}
}
5
use ClarityTech\Shopify\Facades\Shopify;
public function verifyWebhook(Request $request)
{
$data = $request->getContent();
$hmacHeader = $request->header('x-shopify-hmac-sha256');
if (Shopify::verifyWebHook($data, $hmacHeader)) {
logger("verification passed");
} else {
logger("verification failed");
}
}
5
$myshopify_domain = "example.myshopify.com";
$access_token = "xxxxxxxxxxxxxxxxxxxxx";
$api = Shopify::setShop($myshopify_domain, $access_token)->basicApi();
// For sync rest api
$res = $api->rest('GET', '/admin/shop.json')
// For sync graphql api
$res = $api->graph('{ products(first: 1) { edges { node { handle, id } } } }', [])
5
use Illuminate\Http\Request;
use ClarityTech\Shopify\Shopify;
class Foo
{
protected $shopify;
public function __construct(Shopify $shopify)
{
$this->shopify = $shopify;
}
/*
* returns products
*/
public function getProducts(Request $request)
{
$accessToken = 'xxxxxxxxxxxxxxxxxxxxx';//retrieve from your storage(db)
$products = $this->shopify->setShop($request->shop, $accessToken)
->get('admin/products.json');
dump($products);
}
}