Skip to content

Commit 9bb793b

Browse files
committed
Merge pull request #307 from anikghosh256/master
feat: add getEmbeddedAppUrl method
2 parents f58f627 + 9bd197f commit 9bb793b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/ShopifySDK.php

+22
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,28 @@ public static function getApiUrl() {
421421
return self::$config['ApiUrl'];
422422
}
423423

424+
/**
425+
* Returns the appropriate URL for the host that should load the embedded app.
426+
*
427+
* @param string $host The host value received from Shopify
428+
*
429+
* @return string
430+
*/
431+
public static function getEmbeddedAppUrl($host)
432+
{
433+
if (empty($host)) {
434+
throw new SdkException("Host value cannot be empty");
435+
}
436+
437+
$decodedHost = base64_decode($host, true);
438+
if (!$decodedHost) {
439+
throw new SdkException("Host was not a valid base64 string");
440+
}
441+
442+
$apiKey = self::$config['ApiKey'];
443+
return "https://$decodedHost/apps/$apiKey";
444+
}
445+
424446
/**
425447
* Maintain maximum 2 calls per second to the API
426448
*

0 commit comments

Comments
 (0)