Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand All @@ -36,7 +36,7 @@ Context::initialize(
sessionStorage: new FileSessionStorage('/tmp/php_sessions'),
apiVersion: '2023-04',
isEmbeddedApp: true,
isPrivateApp: false,
isCustomStoreApp: false,
);
```

Expand Down
4 changes: 2 additions & 2 deletions src/Clients/Graphql.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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];
}
}
4 changes: 2 additions & 2 deletions src/Clients/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/Clients/Storefront.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
12 changes: 6 additions & 6 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Auth/OAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/Clients/RestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public function testFailsToInstantiateWithoutAccessTokenForNonPrivateApps()

public function testInstantiateWithoutAccessTokenForPrivateApps()
{
Context::$IS_PRIVATE_APP = true;
Context::$IS_CUSTOM_APP = true;

$client = new Rest($this->domain);
$this->assertNotNull($client);
}

public function testPrivateAppsUseApiSecretKeyAsAccessToken()
{
Context::$IS_PRIVATE_APP = true;
Context::$IS_CUSTOM_APP = true;

$headers = ['X-Test-Header' => 'test_value'];

Expand Down
4 changes: 2 additions & 2 deletions tests/Clients/StorefrontTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -82,7 +82,7 @@ public function testCanMakeRequestForPrivateApp()

public function testCanUseTokenForPrivateAppRequest()
{
Context::$IS_PRIVATE_APP = true;
Context::$IS_CUSTOM_APP = true;

$this->mockTransportRequests([
new MockRequest(
Expand Down
4 changes: 2 additions & 2 deletions tests/ContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -258,7 +258,7 @@ public function testCanSetCustomShopDomains()
hostName: 'my-friends-cats',
sessionStorage: new MockSessionStorage(),
apiVersion: ApiVersion::LATEST,
isPrivateApp: false,
isCustomStoreApp: false,
customShopDomains: $domains,
);

Expand Down