From 82c040698c15a5c106030b30e1338fb3e46d1606 Mon Sep 17 00:00:00 2001 From: Anik Ghosh Date: Mon, 25 Sep 2023 18:56:40 +0600 Subject: [PATCH] feat: add getEmbeddedAppUrl method --- lib/ShopifySDK.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 2a5d4af..db7da2f 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -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 *