コード例 #1
0
ファイル: configuration.php プロジェクト: retargeting/Shopify
<?php

session_start();
require __DIR__ . '/db.php';
require __DIR__ . '/vendor/autoload.php';
use phpish\shopify;
require __DIR__ . '/conf.php';
// $counter = true -> valid token already exists
// $counter = false -> no valid token found, installation required
$counter = false;
if (verifyShopStatus($conn, $_GET['shop'])) {
    shopify\is_valid_request($_GET, SHOPIFY_APP_SHARED_SECRET) or die('Invalid Request! Request or redirect did not come from Shopify');
    $shop = getShopDetails($conn, $_GET['shop']);
    try {
        $shopify = shopify\client($shop['shop'], SHOPIFY_APP_API_KEY, $shop['token']);
        $shopShopifyDetails = $shopify('GET /admin/shop.json');
        if ($shopShopifyDetails) {
            $counter = true;
        }
    } catch (Exception $e) {
        // there was a problem with the current token
        uninstallShop($conn, $_GET['shop']);
        $counter = false;
    }
}
if (!$counter) {
    // [begin]OAUTH
    # Guard: http://docs.shopify.com/api/authentication/oauth#verification
    shopify\is_valid_request($_GET, SHOPIFY_APP_SHARED_SECRET) or die('Invalid Request! Request or redirect did not come from Shopify');
    # Step 2: http://docs.shopify.com/api/authentication/oauth#asking-for-permission
    if (!isset($_GET['code'])) {
コード例 #2
0
ファイル: embedd.php プロジェクト: retargeting/Shopify
<?php

session_start();
require __DIR__ . '/../db.php';
if (isset($_GET['shop']) && ($shop = verifyShopStatus($conn, $_GET['shop']))) {
    if ($shop['domain_api_key'] != '') {
        ?>
(function(){
ra_key = "<?php 
        echo $shop['domain_api_key'];
        ?>
";
ra_params = {
	add_to_cart_button_id: '<?php 
        echo $shop['qs_add_to_cart'] != '' ? $shop['qs_add_to_cart'] : 'form[action="/cart/add"] [type="submit"]';
        ?>
',
	price_label_id: '<?php 
        echo $shop['qs_price'] != '' ? $shop['qs_price'] : '#price-preview';
        ?>
',
};
var ra = document.createElement("script"); ra.type ="text/javascript"; ra.async = true; ra.src = ("https:" ==
document.location.protocol ? "https://" : "http://") + "tracking.retargeting.biz/v3/rajs/" + ra_key + ".js";
var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ra,s);})();
<?php 
    }
}
コード例 #3
0
ファイル: create.php プロジェクト: retargeting/Shopify
<?php

require __DIR__ . '/../../db.php';
require __DIR__ . '/../../vendor/autoload.php';
use phpish\shopify;
require __DIR__ . '/../../conf.php';
require __DIR__ . '/../../lib/retargeting-rest-api/Client.php';
function verify_webhook($data, $hmac_header)
{
    $calculated_hmac = base64_encode(hash_hmac('sha256', $data, SHOPIFY_APP_SHARED_SECRET, true));
    return $hmac_header == $calculated_hmac;
}
$hmac_header = $_SERVER['HTTP_X_SHOPIFY_HMAC_SHA256'];
$data = file_get_contents('php://input');
$verified = verify_webhook($data, $hmac_header);
if ($verified && !empty($_SERVER['HTTP_X_SHOPIFY_SHOP_DOMAIN']) && ($shop = verifyShopStatus($conn, $_SERVER['HTTP_X_SHOPIFY_SHOP_DOMAIN']))) {
    $shopify = shopify\client($shop['shop'], SHOPIFY_APP_API_KEY, $shop['token']);
    if (empty($shop['domain_api_key']) || empty($shop['api_token'])) {
        return false;
    }
    // get Order through Shopify API - unsolved issue
    // $order = $shopify('GET /admin/orders.json?ids='.$data['id']);
    $client = new Retargeting_REST_API_Client($shop['domain_api_key'], $shop['api_token']);
    $client->setResponseFormat("json");
    $client->setDecoding(false);
    $orderObj = json_decode($data);
    $discountCodes = array();
    foreach ($orderObj->discount_codes as $dc) {
        $discountCodes[] = $dc->code;
    }
    $discountCodes = implode(', ', $discountCodes);