<?php // echo "signature: " . $_GET['signature']; require __DIR__ . '/ShopifyApi/ShopifyClient.php'; session_start(); define("SHOPIFY_API_KEY", ""); define("SHOPIFY_SECRET", ""); $sc = new ShopifyClient($_SESSION['shop'], $_SESSION['token'], SHOPIFY_API_KEY, SHOPIFY_SECRET); try { // Get all products $products = $sc->call('GET', '/admin/shop.json?page=1', array()); echo "shop: " . $_SESSION['shop']; echo "<br/>token: " . $_SESSION['token']; echo "<br/>"; echo "<pre>"; var_dump($products); echo "</pre>"; } 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 */ }
session_start(); require_once "config.php"; require 'shopifyclient.php'; //require 'shopify.php'; require 'vendor/autoload.php'; use sandeepshetty\shopify_api; $shop = $_REQUEST['shop'] != '' ? $_REQUEST['shop'] : $_SESSION['shop']; $date = date("Y-m-d H:i:s"); $select_sql = "SELECT `id`,`token` FROM `app` WHERE `shop` = '" . $shop . "' ORDER BY `id` DESC LIMIT 1"; $res = mysql_query($select_sql); if (mysql_num_rows($res) > 0) { $res_arr = mysql_fetch_assoc($res); $token = $res_arr['token']; } $sc = new ShopifyClient($shop, $token, SHOPIFY_API_KEY, SHOPIFY_SECRET); session_unset(); /* try { $select_sql_3 = "SELECT `id` FROM `general_settings` WHERE `shop` = '" . $shop . "' ORDER BY `id` DESC LIMIT 1"; $res3 = mysql_query($select_sql_3); if (mysql_num_rows($res3) <= 0) { mysql_query("insert into general_settings(`shop`,`display_related_product`,`product_number`,`heading_text`,`heading_color`,`heading_style`,`product_title_color`,`product_title_style`,`product_price_color`,`product_price_style`,`display_button`,`button_color`,`button_text`,`button_text_color`) VALUES('" . mysql_real_escape_string($shop) . "','1','5','Related Product','#000','normal','#000','normal','#000','normal','1','#000','View','#fff') "); } } catch (Exception $ex) { }*/ if (PLAN == 'paid') { $charge_id = $_GET['charge_id']; if ($shop != '' && $charge_id != '') {
$res = mysql_query($select_sql); if (mysql_num_rows($res) > 0) { $res_arr = mysql_fetch_assoc($res); $token = $res_arr['token']; $payment_status = $res_arr['payment_status']; $app_status = $res_arr['app_status']; $id = $res_arr['id']; } if (($payment_status == 'accepted' || $payment_status == 'free') && $app_status == 'installed') { header("Location: admin/add_image.php?shop=" . $shop); exit; } if ($_SESSION['token'] != '') { $token = $_SESSION['token']; } $sc = new ShopifyClient($shop, $token, SHOPIFY_API_KEY, SHOPIFY_SECRET); $fields_arr = array("fields" => "myshopify_domain,domain"); $shop_resp = $sc->call('GET', "/admin/shop.json", $fields_arr); $domain = preg_replace('/^www\\./', '', $shop_resp['domain']); $app_update_sql = "UPDATE `app` SET `shop_domain` = '" . $domain . "' WHERE `id` = '" . $id . "'"; mysql_query($app_update_sql); $status_update_sql = "UPDATE `app` SET `app_status` = 'installed' WHERE `id` = '" . $id . "'"; mysql_query($status_update_sql); if (PLAN == 'paid') { /*Recurring Charge Code Start*/ $recurring_charge_arr = array("recurring_application_charge" => array("name" => "Standard Plan", "price" => PLAN_PRICE, "return_url" => SITE_URL . "/install.php?shop={$shop}", "trial_days" => PLAN_TRIAL, "test" => PLAN_MODE)); $recurring_charge_call = $sc->call('POST', "/admin/recurring_application_charges.json", $recurring_charge_arr); session_unset(); if (count($recurring_charge_call) > 0) { if ($recurring_charge_call['confirmation_url'] != '') { header("Location: " . $recurring_charge_call['confirmation_url']);
if (isset($_GET['code'])) { // Step 2: do a form POST to get the access token $shopifyClient = new ShopifyClient($_GET['shop'], "", SHOPIFY_API_KEY, SHOPIFY_SECRET); session_unset(); $_SESSION['token'] = $shopifyClient->getAccessToken($_GET['code']); if ($_SESSION['token'] != '') { $_SESSION['shop'] = $_GET['shop']; } header("Location: index.php"); exit; } else { if (isset($_POST['shop']) || isset($_GET['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; }
public function __construct($shop_domain, $token, $api_key, $secret) { parent::__construct($shop_domain, $token, $api_key, $secret); }
// die( "signature: " . $_GET['signature']); // Now, request the token and store it in your session. $token = $shopifyClient->getAccessToken($_GET['code'], REDIRECT_URI); $_SESSION['token'] = $token; if ($_SESSION['token'] != '') { $_SESSION['shop'] = $_GET['shop']; } echo $token; header("Location: shop.php"); exit; } else { if (isset($_POST['shop']) || isset($_GET['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); // if(!$shopifyClient->validateSignature($_GET)) die('Error: invalid signature.'); // redirect to authorize url header("Location: " . $shopifyClient->getAuthorizeUrl(SHOPIFY_SCOPE, REDIRECT_URI)); 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’t have a shop to install your app in handy? <a href="https://app.shopify.com/services/partners/dev_shops/new">Create a test shop.</a></span> </p> <form action="" method="post">