From 3704868f7246717b8f127b1ea4fb7a384d726185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Corr=C3=AAa=20Gomes?= Date: Sat, 29 Apr 2023 16:25:08 +0000 Subject: [PATCH 1/2] Private App to Custom Store App --- docs/getting_started.md | 4 ++-- src/Clients/Graphql.php | 4 ++-- src/Clients/Rest.php | 4 ++-- src/Clients/Storefront.php | 2 +- src/Context.php | 12 ++++++------ tests/Auth/OAuthTest.php | 4 ++-- tests/Clients/RestTest.php | 4 ++-- tests/Clients/StorefrontTest.php | 4 ++-- tests/ContextTest.php | 4 ++-- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/docs/getting_started.md b/docs/getting_started.md index 96f583ec..40435f85 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -21,7 +21,7 @@ The first thing your app will need to do to use this library is to set up your c | `sessionStorage` | `SessionStorage` | Yes | - | Session storage strategy. Read our [notes on session handling](issues.md#notes-on-session-handling) for more information | | `apiVersion` | `string` | No | `'unstable'` | App API version, defaults to unstable | | `isEmbeddedApp` | `bool` | No | `true` | Whether the app is an embedded app | -| `isPrivateApp` | `bool` | No | `false` | Whether the app is a private app | +| `isCustomStoreApp` | `bool` | No | `false` | Whether the app is a custom store app | | `userAgentPrefix` | `string` | No | - | Prefix for user agent header sent with a request | | `logger` | `LoggerInterface` | No | - | App logger, so the library can add its own logs to it. Must implement the [PSR-3](https://www.php-fig.org/psr/psr-3/) `Psr\Log\LoggerInterface` interface from the `psr/log` package | @@ -36,7 +36,7 @@ Context::initialize( sessionStorage: new FileSessionStorage('/tmp/php_sessions'), apiVersion: '2023-04', isEmbeddedApp: true, - isPrivateApp: false, + isCustomStoreApp: false, ); ``` diff --git a/src/Clients/Graphql.php b/src/Clients/Graphql.php index 07926255..5c8f1da2 100644 --- a/src/Clients/Graphql.php +++ b/src/Clients/Graphql.php @@ -26,7 +26,7 @@ public function __construct( string $domain, ?string $token = null ) { - if (!Context::$IS_PRIVATE_APP && empty($token)) { + if (!Context::$IS_CUSTOM_APP && empty($token)) { throw new MissingArgumentException('Missing access token when creating GraphQL client'); } $this->client = new Http($domain); @@ -126,7 +126,7 @@ protected function getApiPath(): string */ protected function getAccessTokenHeader(): array { - $accessToken = Context::$IS_PRIVATE_APP ? Context::$API_SECRET_KEY : $this->token; + $accessToken = Context::$IS_CUSTOM_APP ? Context::$API_SECRET_KEY : $this->token; return [HttpHeaders::X_SHOPIFY_ACCESS_TOKEN, $accessToken]; } } diff --git a/src/Clients/Rest.php b/src/Clients/Rest.php index 8f707f0c..ceaf486d 100644 --- a/src/Clients/Rest.php +++ b/src/Clients/Rest.php @@ -25,7 +25,7 @@ public function __construct(string $domain, ?string $accessToken = null) parent::__construct($domain); $this->accessToken = $accessToken; - if (!Context::$IS_PRIVATE_APP && !$this->accessToken) { + if (!Context::$IS_CUSTOM_APP && !$this->accessToken) { throw new MissingArgumentException('Missing access token when creating REST client'); } } @@ -43,7 +43,7 @@ protected function request( string $dataType = self::DATA_TYPE_JSON ): RestResponse { $headers[HttpHeaders::X_SHOPIFY_ACCESS_TOKEN] = - Context::$IS_PRIVATE_APP ? Context::$API_SECRET_KEY : $this->accessToken; + Context::$IS_CUSTOM_APP ? Context::$API_SECRET_KEY : $this->accessToken; $response = parent::request($path, $method, $body, $headers, $query, $tries, $dataType); diff --git a/src/Clients/Storefront.php b/src/Clients/Storefront.php index cd82734c..8a7fcb8a 100644 --- a/src/Clients/Storefront.php +++ b/src/Clients/Storefront.php @@ -21,7 +21,7 @@ protected function getApiPath(): string */ protected function getAccessTokenHeader(): array { - $accessToken = Context::$IS_PRIVATE_APP ? + $accessToken = Context::$IS_CUSTOM_APP ? (Context::$PRIVATE_APP_STOREFRONT_ACCESS_TOKEN ?: $this->token) : $this->token; return [HttpHeaders::X_SHOPIFY_STOREFRONT_ACCESS_TOKEN, $accessToken]; diff --git a/src/Context.php b/src/Context.php index 03b1f38f..1e7bee3d 100644 --- a/src/Context.php +++ b/src/Context.php @@ -34,7 +34,7 @@ class Context /** @var bool */ public static $IS_EMBEDDED_APP = true; /** @var bool */ - public static $IS_PRIVATE_APP = false; + public static $IS_CUSTOM_APP = false; /** @var string|null */ public static $PRIVATE_APP_STOREFRONT_ACCESS_TOKEN = null; /** @var string */ @@ -61,8 +61,8 @@ class Context * @param SessionStorage $sessionStorage Session storage strategy * @param string $apiVersion App API key, defaults to unstable * @param bool $isEmbeddedApp Whether the app is an embedded app, defaults to true - * @param bool $isPrivateApp Whether the app is a private app, defaults to false - * @param string|null $privateAppStorefrontAccessToken The Storefront API Access Token for a private app + * @param bool $isCustomStoreApp Whether the app is a custom store app, defaults to false + * @param string|null $privateAppStorefrontAccessToken The Storefront API Access Token for a custom store app * @param string $userAgentPrefix Prefix for user agent header sent with a request * @param LoggerInterface|null $logger App logger, so the library can add its own logs to * it @@ -78,7 +78,7 @@ public static function initialize( SessionStorage $sessionStorage, string $apiVersion = ApiVersion::LATEST, bool $isEmbeddedApp = true, - bool $isPrivateApp = false, + bool $isCustomStoreApp = false, string $privateAppStorefrontAccessToken = null, string $userAgentPrefix = '', LoggerInterface $logger = null, @@ -130,7 +130,7 @@ public static function initialize( self::$HTTP_CLIENT_FACTORY = new HttpClientFactory(); self::$API_VERSION = $apiVersion; self::$IS_EMBEDDED_APP = $isEmbeddedApp; - self::$IS_PRIVATE_APP = $isPrivateApp; + self::$IS_CUSTOM_APP = $isCustomStoreApp; self::$PRIVATE_APP_STOREFRONT_ACCESS_TOKEN = $privateAppStorefrontAccessToken; self::$USER_AGENT_PREFIX = $userAgentPrefix; self::$LOGGER = $logger; @@ -163,7 +163,7 @@ public static function throwIfUninitialized(): void */ public static function throwIfPrivateApp(string $message): void { - if (self::$IS_PRIVATE_APP) { + if (self::$IS_CUSTOM_APP) { throw new PrivateAppException($message); } } diff --git a/tests/Auth/OAuthTest.php b/tests/Auth/OAuthTest.php index b105f6b0..042bca71 100644 --- a/tests/Auth/OAuthTest.php +++ b/tests/Auth/OAuthTest.php @@ -376,7 +376,7 @@ public function testFailsForPrivateApp() { $this->createTestSession(false); - Context::$IS_PRIVATE_APP = true; + Context::$IS_CUSTOM_APP = true; $mockCookies = [ OAuth::SESSION_ID_SIG_COOKIE_NAME => hash_hmac('sha256', $this->oauthSessionId, Context::$API_SECRET_KEY), @@ -493,7 +493,7 @@ public function testFailsIfTokenFetchFails() public function testBeginFailsOnPrivateApp() { - Context::$IS_PRIVATE_APP = true; + Context::$IS_CUSTOM_APP = true; $this->expectexception(PrivateAppException::class); OAuth::begin('shopname', '/redirect', true); diff --git a/tests/Clients/RestTest.php b/tests/Clients/RestTest.php index 29228027..089fb787 100644 --- a/tests/Clients/RestTest.php +++ b/tests/Clients/RestTest.php @@ -30,7 +30,7 @@ public function testFailsToInstantiateWithoutAccessTokenForNonPrivateApps() public function testInstantiateWithoutAccessTokenForPrivateApps() { - Context::$IS_PRIVATE_APP = true; + Context::$IS_CUSTOM_APP = true; $client = new Rest($this->domain); $this->assertNotNull($client); @@ -38,7 +38,7 @@ public function testInstantiateWithoutAccessTokenForPrivateApps() public function testPrivateAppsUseApiSecretKeyAsAccessToken() { - Context::$IS_PRIVATE_APP = true; + Context::$IS_CUSTOM_APP = true; $headers = ['X-Test-Header' => 'test_value']; diff --git a/tests/Clients/StorefrontTest.php b/tests/Clients/StorefrontTest.php index a78fa499..f8dc0c75 100644 --- a/tests/Clients/StorefrontTest.php +++ b/tests/Clients/StorefrontTest.php @@ -55,7 +55,7 @@ public function testCanMakeRequest() public function testCanMakeRequestForPrivateApp() { - Context::$IS_PRIVATE_APP = true; + Context::$IS_CUSTOM_APP = true; Context::$PRIVATE_APP_STOREFRONT_ACCESS_TOKEN = 'private_token'; $this->mockTransportRequests([ @@ -82,7 +82,7 @@ public function testCanMakeRequestForPrivateApp() public function testCanUseTokenForPrivateAppRequest() { - Context::$IS_PRIVATE_APP = true; + Context::$IS_CUSTOM_APP = true; $this->mockTransportRequests([ new MockRequest( diff --git a/tests/ContextTest.php b/tests/ContextTest.php index 1440b895..0902bbdc 100644 --- a/tests/ContextTest.php +++ b/tests/ContextTest.php @@ -92,7 +92,7 @@ public function testThrowsIfPrivateApp() hostName: 'my-friends-cats', sessionStorage: new MockSessionStorage(), apiVersion: 'unstable', - isPrivateApp: true, + isCustomStoreApp: true, ); $this->expectException(\Shopify\Exception\PrivateAppException::class); $this->expectExceptionMessage('BOOOOOO'); @@ -258,7 +258,7 @@ public function testCanSetCustomShopDomains() hostName: 'my-friends-cats', sessionStorage: new MockSessionStorage(), apiVersion: ApiVersion::LATEST, - isPrivateApp: false, + isCustomStoreApp: false, customShopDomains: $domains, ); From dac944d9b3ca532e3c7d99067be7e7b665c71c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Corr=C3=AAa=20Gomes?= Date: Sat, 29 Apr 2023 16:32:16 +0000 Subject: [PATCH 2/2] Adding changes to the backlog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f5f938d..97fe2ce9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). - [#236](https://github.com/Shopify/shopify-api-php/pull/236) [bugfix] Correct requirements in `composer.json` - [#262](https://github.com/Shopify/shopify-api-php/pull/262) ⚠️ [Breaking] Added support for PHP 8.2, and removed support for PHP 7.4 - [#264](https://github.com/Shopify/shopify-api-php/pull/264) [Patch] Remove support for currently-non-existent versions of PHP (8.3+) +- [#268](https://github.com/Shopify/shopify-api-php/pull/268) ⚠️ [Breaking] Changing Private App to Custom Store App ## v4.3.0 - 2023-04-12