Skip to content

Commit

Permalink
feat: add getEmbeddedAppUrl method
Browse files Browse the repository at this point in the history
  • Loading branch information
anikghosh256 committed Sep 25, 2023
1 parent 284d7c8 commit 82c0406
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/ShopifySDK.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,28 @@ public static function getApiUrl() {
return self::$config['ApiUrl'];
}

/**
* Returns the appropriate URL for the host that should load the embedded app.
*
* @param string $host The host value received from Shopify
*
* @return string
*/
public static function getEmbeddedAppUrl($host)
{
if (empty($host)) {
throw new SdkException("Host value cannot be empty");
}

$decodedHost = base64_decode($host, true);
if (!$decodedHost) {
throw new SdkException("Host was not a valid base64 string");
}

$apiKey = self::$config['ApiKey'];
return "https://$decodedHost/apps/$apiKey";
}

/**
* Maintain maximum 2 calls per second to the API
*
Expand Down

0 comments on commit 82c0406

Please sign in to comment.