diff --git a/src/Context/ActionSource.php b/src/Context/ActionSource.php index 0c42fd6..f72c430 100644 --- a/src/Context/ActionSource.php +++ b/src/Context/ActionSource.php @@ -9,8 +9,17 @@ class ActionSource /** * @param string $url The shop url * @param string $appVersion The installed App version + * @param string[] $inAppPurchases The active in-app-purchases */ - public function __construct(public readonly string $url, public readonly string $appVersion) + public function __construct( + public readonly string $url, + public readonly string $appVersion, + public readonly array $inAppPurchases = [], + ) { + } + + public function hasInAppPurchase(string $inAppPurchase): bool { + return \in_array($inAppPurchase, $this->inAppPurchases, true); } } diff --git a/src/Context/ContextResolver.php b/src/Context/ContextResolver.php index 809147d..64a3fbf 100644 --- a/src/Context/ContextResolver.php +++ b/src/Context/ContextResolver.php @@ -29,6 +29,9 @@ use Shopware\App\SDK\Framework\Collection; use Shopware\App\SDK\Shop\ShopInterface; +/** + * @psalm-import-type StorefrontClaimsArray from StorefrontClaims + */ class ContextResolver { public function assembleWebhook(RequestInterface $request, ShopInterface $shop): WebhookAction @@ -69,17 +72,28 @@ public function assembleActionButton(RequestInterface $request, ShopInterface $s public function assembleModule(RequestInterface $request, ShopInterface $shop): ModuleAction { - parse_str($request->getUri()->getQuery(), $params); - - if (!isset($params['sw-version'], $params['sw-context-language']) || !is_string($params['sw-version']) || !is_string($params['sw-context-language']) || !isset($params['sw-user-language']) || !is_string($params['sw-user-language'])) { + \parse_str($request->getUri()->getQuery(), $params); + + if (!isset($params['sw-version'], $params['sw-context-language'], $params['sw-user-language']) + || !is_string($params['sw-version']) + || !is_string($params['sw-context-language']) + || !is_string($params['sw-user-language']) + || (isset($params['in-app-purchases']) && !is_string($params['in-app-purchases'])) + ) { throw new MalformedWebhookBodyException(); } + $inAppPurchaseString = $params['in-app-purchases'] ?? ''; + \assert(\is_string($inAppPurchaseString)); + + $inAppPurchases = \explode(',', $inAppPurchaseString); + return new ModuleAction( $shop, $params['sw-version'], $params['sw-context-language'], - $params['sw-user-language'] + $params['sw-user-language'], + $inAppPurchases, ); } @@ -227,8 +241,8 @@ public function assembleStorefrontRequest(RequestInterface $request, ShopInterfa throw new MalformedWebhookBodyException(); } - /** @var array $claims */ - $claims = json_decode(base64_decode($parts[1]), true, flags: JSON_THROW_ON_ERROR); + /** @var StorefrontClaimsArray $claims */ + $claims = \json_decode(\base64_decode($parts[1]), true, flags: JSON_THROW_ON_ERROR); return new StorefrontAction( $shop, @@ -261,13 +275,21 @@ public function assembleCheckoutGatewayRequest(RequestInterface $request, ShopIn */ private function parseSource(array $source): ActionSource { - if (!isset($source['url'], $source['appVersion']) || !is_string($source['url']) || !is_string($source['appVersion'])) { + if (!isset($source['url'], $source['appVersion']) || !\is_string($source['url']) || !\is_string($source['appVersion'])) { throw new MalformedWebhookBodyException(); } + if (isset($source['inAppPurchases']) && !\is_array($source['inAppPurchases'])) { + throw new MalformedWebhookBodyException(); + } + + /** @var string[] $inAppPurchase */ + $inAppPurchase = $source['inAppPurchases'] ?? []; + return new ActionSource( $source['url'], - $source['appVersion'] + $source['appVersion'], + $inAppPurchase, ); } } diff --git a/src/Context/Module/ModuleAction.php b/src/Context/Module/ModuleAction.php index 33fe2ba..7748a9d 100644 --- a/src/Context/Module/ModuleAction.php +++ b/src/Context/Module/ModuleAction.php @@ -11,12 +11,14 @@ class ModuleAction /** * @param string $contentLanguage - The language of the Shopware content as UUID * @param string $userLanguage - The language of the Shopware user as ISO (en-GB) + * @param string[] $inAppPurchases - The active in-app-purchases */ public function __construct( public readonly ShopInterface $shop, public readonly string $shopwareVersion, public readonly string $contentLanguage, public readonly string $userLanguage, + public readonly array $inAppPurchases = [], ) { } } diff --git a/src/Context/Storefront/StorefrontClaims.php b/src/Context/Storefront/StorefrontClaims.php index 34c14c9..e700f1b 100644 --- a/src/Context/Storefront/StorefrontClaims.php +++ b/src/Context/Storefront/StorefrontClaims.php @@ -6,10 +6,21 @@ use Shopware\App\SDK\Exception\MissingClaimException; +/** + * @psalm-type StorefrontClaimsArray = array{ + * salesChannelId?: string, + * customerId?: string, + * currencyId?: string, + * languageId?: string, + * paymentMethodId?: string, + * shippingMethodId?: string, + * inAppPurchases?: string[], + * } + */ class StorefrontClaims { /** - * @param array $claims + * @param StorefrontClaimsArray $claims */ public function __construct(private readonly array $claims) { @@ -74,4 +85,22 @@ public function getShippingMethodId(): string return $value; } + + /** + * @return string[] + */ + public function getInAppPurchases(): array + { + $value = $this->claims['inAppPurchases'] ?? []; + if (!\is_array($value)) { + throw new MissingClaimException('inAppPurchases'); + } + + return $value; + } + + public function hasInAppPurchase(string $inAppPurchase): bool + { + return \in_array($inAppPurchase, $this->getInAppPurchases(), true); + } } diff --git a/tests/Context/ActionSourceTest.php b/tests/Context/ActionSourceTest.php index a031081..fa72c50 100644 --- a/tests/Context/ActionSourceTest.php +++ b/tests/Context/ActionSourceTest.php @@ -11,7 +11,7 @@ #[CoversClass(ActionSource::class)] class ActionSourceTest extends TestCase { - public function testConstruct(): void + public function testConstructDefaults(): void { $url = 'https://example.com'; $version = '1.0.0'; @@ -20,5 +20,25 @@ public function testConstruct(): void static::assertSame($url, $source->url); static::assertSame($version, $source->appVersion); + static::assertSame([], $source->inAppPurchases); + + static::assertFalse($source->hasInAppPurchase('purchase1')); + } + + public function testConstruct(): void + { + $url = 'https://example.com'; + $version = '1.0.0'; + $inAppPurchases = ['purchase1', 'purchase2']; + + $source = new ActionSource($url, $version, $inAppPurchases); + + static::assertSame($url, $source->url); + static::assertSame($version, $source->appVersion); + static::assertSame($inAppPurchases, $source->inAppPurchases); + + static::assertTrue($source->hasInAppPurchase('purchase1')); + static::assertTrue($source->hasInAppPurchase('purchase2')); + static::assertFalse($source->hasInAppPurchase('purchase3')); } } diff --git a/tests/Context/ContextResolverTest.php b/tests/Context/ContextResolverTest.php index 12d019c..6dc1333 100644 --- a/tests/Context/ContextResolverTest.php +++ b/tests/Context/ContextResolverTest.php @@ -42,6 +42,7 @@ public function testAssembleWebhook(): void 'source' => [ 'url' => 'https://example.com', 'appVersion' => '1.0.0', + 'inAppPurchases' => ['foo', 'bar'], ], 'data' => [ 'event' => 'order.placed', @@ -54,6 +55,11 @@ public function testAssembleWebhook(): void $this->getShop() ); + static::assertSame(['foo', 'bar'], $webhook->source->inAppPurchases); + static::assertTrue($webhook->source->hasInAppPurchase('foo')); + static::assertTrue($webhook->source->hasInAppPurchase('bar')); + static::assertFalse($webhook->source->hasInAppPurchase('baz')); + static::assertSame('123', $webhook->payload['orderId']); static::assertSame('order.placed', $webhook->eventName); static::assertSame('https://example.com', $webhook->source->url); @@ -80,6 +86,7 @@ public function testAssembleActionButton(): void 'source' => [ 'url' => 'https://example.com', 'appVersion' => '1.0.0', + 'inAppPurchases' => ['foo', 'bar'], ], 'data' => [ 'ids' => ['123'], @@ -96,6 +103,9 @@ public function testAssembleActionButton(): void static::assertSame('https://example.com', $actionButton->source->url); static::assertSame('1.0.0', $actionButton->source->appVersion); + static::assertSame(['foo', 'bar'], $actionButton->source->inAppPurchases); + static::assertTrue($actionButton->source->hasInAppPurchase('foo')); + static::assertTrue($actionButton->source->hasInAppPurchase('bar')); } public function testMalformedSource(): void @@ -118,13 +128,14 @@ public function testAssembleModule(): void $contextResolver = new ContextResolver(); $module = $contextResolver->assembleModule( - new Request('GET', 'http://localhost:6001/module/test?shop-id=vvRy7Nv3Bo8mAVda&shop-url=http://localhost:8000×tamp=1683015472&sw-version=6.5.9999999.9999999-dev&sw-context-language=2fbb5fe2e29a4d70aa5854ce7ce3e20b&sw-user-language=en-GB&shopware-shop-signature=650455d43eda4eeb4c9a12ee0eb15b46ce88776abaf9beb1ffac31be136e1d9b'), + new Request('GET', 'http://localhost:6001/module/test?shop-id=vvRy7Nv3Bo8mAVda&shop-url=http://localhost:8000×tamp=1683015472&sw-version=6.5.9999999.9999999-dev&sw-context-language=2fbb5fe2e29a4d70aa5854ce7ce3e20b&sw-user-language=en-GB&in-app-purchases=foo,bar&shopware-shop-signature=650455d43eda4eeb4c9a12ee0eb15b46ce88776abaf9beb1ffac31be136e1d9b'), $this->getShop() ); static::assertSame('6.5.9999999.9999999-dev', $module->shopwareVersion); static::assertSame('2fbb5fe2e29a4d70aa5854ce7ce3e20b', $module->contentLanguage); static::assertSame('en-GB', $module->userLanguage); + static::assertSame(['foo', 'bar'], $module->inAppPurchases); } /** @@ -153,6 +164,13 @@ public function testAssembleTaxProvider(): void $contextResolver = new ContextResolver(); $tax = $contextResolver->assembleTaxProvider(new Request('GET', '/', [], (string) file_get_contents(__DIR__ . '/_fixtures/tax.json')), $this->getShop()); + static::assertSame('http://localhost:8000', $tax->source->url); + static::assertSame('1.0.0', $tax->source->appVersion); + static::assertSame(['foo', 'bar'], $tax->source->inAppPurchases); + static::assertTrue($tax->source->hasInAppPurchase('foo')); + static::assertTrue($tax->source->hasInAppPurchase('bar')); + static::assertFalse($tax->source->hasInAppPurchase('baz')); + static::assertSame('W4K2OUeCshirU015lWDfche9vymD4cUt', $tax->cart->getToken()); static::assertNull($tax->cart->getAffiliateCode()); static::assertNull($tax->cart->getCampaignCode()); @@ -401,6 +419,7 @@ public function testAssemblePay(): void 'source' => [ 'url' => 'https://example.com', 'appVersion' => 'foo', + 'inAppPurchases' => ['foo', 'bar'], ], 'order' => [ 'id' => 'foo', @@ -426,6 +445,10 @@ public function testAssemblePay(): void static::assertInstanceOf(PaymentPayAction::class, $paymentPayResponse); static::assertSame('https://example.com', $paymentPayResponse->source->url); static::assertSame('foo', $paymentPayResponse->source->appVersion); + static::assertSame(['foo', 'bar'], $paymentPayResponse->source->inAppPurchases); + static::assertTrue($paymentPayResponse->source->hasInAppPurchase('foo')); + static::assertTrue($paymentPayResponse->source->hasInAppPurchase('bar')); + static::assertFalse($paymentPayResponse->source->hasInAppPurchase('baz')); static::assertSame('foo', $paymentPayResponse->order->getId()); static::assertSame('bar', $paymentPayResponse->orderTransaction->getId()); static::assertSame('https://example.com/return', $paymentPayResponse->returnUrl); @@ -443,6 +466,7 @@ public function testAssemblePayWithoutRecurringData(): void 'source' => [ 'url' => 'https://example.com', 'appVersion' => 'foo', + 'inAppPurchases' => ['foo', 'bar'], ], 'order' => [ 'id' => 'foo', @@ -464,6 +488,10 @@ public function testAssemblePayWithoutRecurringData(): void static::assertInstanceOf(PaymentPayAction::class, $paymentPayResponse); static::assertSame('https://example.com', $paymentPayResponse->source->url); static::assertSame('foo', $paymentPayResponse->source->appVersion); + static::assertSame(['foo', 'bar'], $paymentPayResponse->source->inAppPurchases); + static::assertTrue($paymentPayResponse->source->hasInAppPurchase('foo')); + static::assertTrue($paymentPayResponse->source->hasInAppPurchase('bar')); + static::assertFalse($paymentPayResponse->source->hasInAppPurchase('baz')); static::assertSame('foo', $paymentPayResponse->order->getId()); static::assertSame('bar', $paymentPayResponse->orderTransaction->getId()); static::assertSame('https://example.com/return', $paymentPayResponse->returnUrl); @@ -479,6 +507,7 @@ public function testAssemblePayCaptureRecurring(): void 'source' => [ 'url' => 'https://example.com', 'appVersion' => 'foo', + 'inAppPurchases' => ['foo', 'bar'], ], 'order' => [ 'id' => 'foo', @@ -500,6 +529,10 @@ public function testAssemblePayCaptureRecurring(): void static::assertInstanceOf(PaymentRecurringAction::class, $paymentPayResponse); static::assertSame('https://example.com', $paymentPayResponse->source->url); static::assertSame('foo', $paymentPayResponse->source->appVersion); + static::assertSame(['foo', 'bar'], $paymentPayResponse->source->inAppPurchases); + static::assertTrue($paymentPayResponse->source->hasInAppPurchase('foo')); + static::assertTrue($paymentPayResponse->source->hasInAppPurchase('bar')); + static::assertFalse($paymentPayResponse->source->hasInAppPurchase('baz')); static::assertSame('foo', $paymentPayResponse->order->getId()); static::assertSame('bar', $paymentPayResponse->orderTransaction->getId()); } @@ -512,6 +545,7 @@ public function testAssemblePayFinalize(): void 'source' => [ 'url' => 'https://example.com', 'appVersion' => 'foo', + 'inAppPurchases' => ['foo', 'bar'], ], 'orderTransaction' => [ 'id' => 'bar', @@ -533,6 +567,10 @@ public function testAssemblePayFinalize(): void static::assertInstanceOf(PaymentFinalizeAction::class, $paymentPayResponse); static::assertSame('https://example.com', $paymentPayResponse->source->url); static::assertSame('foo', $paymentPayResponse->source->appVersion); + static::assertSame(['foo', 'bar'], $paymentPayResponse->source->inAppPurchases); + static::assertTrue($paymentPayResponse->source->hasInAppPurchase('foo')); + static::assertTrue($paymentPayResponse->source->hasInAppPurchase('bar')); + static::assertFalse($paymentPayResponse->source->hasInAppPurchase('baz')); static::assertSame('bar', $paymentPayResponse->orderTransaction->getId()); static::assertSame(['returnId' => '123'], $paymentPayResponse->queryParameters); static::assertNotNull($paymentPayResponse->recurring); @@ -548,6 +586,7 @@ public function testPaymentPayCapture(): void 'source' => [ 'url' => 'https://example.com', 'appVersion' => 'foo', + 'inAppPurchases' => ['foo', 'bar'], ], 'order' => [ 'id' => 'foo', @@ -572,6 +611,10 @@ public function testPaymentPayCapture(): void static::assertInstanceOf(PaymentCaptureAction::class, $paymentPayResponse); static::assertSame('https://example.com', $paymentPayResponse->source->url); static::assertSame('foo', $paymentPayResponse->source->appVersion); + static::assertSame(['foo', 'bar'], $paymentPayResponse->source->inAppPurchases); + static::assertTrue($paymentPayResponse->source->hasInAppPurchase('foo')); + static::assertTrue($paymentPayResponse->source->hasInAppPurchase('bar')); + static::assertFalse($paymentPayResponse->source->hasInAppPurchase('baz')); static::assertSame('bar', $paymentPayResponse->orderTransaction->getId()); static::assertSame(['returnId' => '123'], $paymentPayResponse->requestData); static::assertNotNull($paymentPayResponse->recurring); @@ -599,6 +642,13 @@ public function testResolvePay(): void $this->getShop() ); + static::assertSame('1.0.0', $action->source->appVersion); + static::assertSame('http://localhost:8000', $action->source->url); + static::assertSame(['foo', 'bar'], $action->source->inAppPurchases); + static::assertTrue($action->source->hasInAppPurchase('foo')); + static::assertTrue($action->source->hasInAppPurchase('bar')); + static::assertFalse($action->source->hasInAppPurchase('baz')); + static::assertSame([], $action->requestData); $order = $action->order; @@ -676,6 +726,12 @@ public function testAssembleFinalize(): void $this->getShop() ); + static::assertSame('1.0.0', $action->source->appVersion); + static::assertSame('http://localhost:8000', $action->source->url); + static::assertSame(['foo', 'bar'], $action->source->inAppPurchases); + static::assertTrue($action->source->hasInAppPurchase('foo')); + static::assertTrue($action->source->hasInAppPurchase('bar')); + static::assertFalse($action->source->hasInAppPurchase('baz')); static::assertSame(395.01, $action->orderTransaction->getAmount()->getTotalPrice()); } @@ -699,6 +755,12 @@ public function testAssembleCapture(): void $this->getShop() ); + static::assertSame('1.0.0', $action->source->appVersion); + static::assertSame('http://localhost:8000', $action->source->url); + static::assertSame(['foo', 'bar'], $action->source->inAppPurchases); + static::assertTrue($action->source->hasInAppPurchase('foo')); + static::assertTrue($action->source->hasInAppPurchase('bar')); + static::assertFalse($action->source->hasInAppPurchase('baz')); static::assertSame(395.01, $action->orderTransaction->getAmount()->getTotalPrice()); } @@ -733,6 +795,13 @@ public function testAssembleValidate(): void $this->getShop() ); + static::assertSame('1.0.0', $action->source->appVersion); + static::assertSame('http://localhost:8000', $action->source->url); + static::assertSame(['foo', 'bar'], $action->source->inAppPurchases); + static::assertTrue($action->source->hasInAppPurchase('foo')); + static::assertTrue($action->source->hasInAppPurchase('bar')); + static::assertFalse($action->source->hasInAppPurchase('baz')); + static::assertSame(['tos' => 'on'], $action->requestData); } @@ -756,6 +825,13 @@ public function testRefund(): void $this->getShop() ); + static::assertSame('1.0.0', $action->source->appVersion); + static::assertSame('http://localhost:8000', $action->source->url); + static::assertSame(['foo', 'bar'], $action->source->inAppPurchases); + static::assertTrue($action->source->hasInAppPurchase('foo')); + static::assertTrue($action->source->hasInAppPurchase('bar')); + static::assertFalse($action->source->hasInAppPurchase('baz')); + static::assertSame('70d9f8c7b9074445b9dd84b7b179374b', $action->refund->getId()); static::assertSame([], $action->refund->getCustomFields()); static::assertSame(420.69, $action->refund->getAmount()->getTotalPrice()); @@ -785,13 +861,18 @@ public function testAssembleStorefrontRequest(): void $contextResolver = new ContextResolver(); $request = new Request('POST', '/', [], '{}'); - $request = $request->withHeader('shopware-app-token', 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJGcWFIV1VzQ1JOc3JaOWtRIiwiaWF0IjoxNjg5ODM3MDkyLjI3ODMyOSwibmJmIjoxNjg5ODM3MDkyLjI3ODMyOSwiZXhwIjoxNjg5ODQwNjkyLjI3ODI0Mywic2FsZXNDaGFubmVsSWQiOiIwMTg5NjQwNTU0YjU3MDBjODBjMmM0YTIwMmUyNDAxZCJ9.g8Da0bN3bkkmEdzMeXmI8wlDQEZMCDiKJvqS288B4JI'); + $request = $request->withHeader('shopware-app-token', 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJGcWFIV1VzQ1JOc3JaOWtRIiwiaWF0IjoxNjg5ODM3MDkyLjI3ODMyOSwibmJmIjoxNjg5ODM3MDkyLjI3ODMyOSwiZXhwIjoxNjg5ODQwNjkyLjI3ODI0MywiaW5BcHBQdXJjaGFzZXMiOlsiZm9vIiwiYmFyIl0sInNhbGVzQ2hhbm5lbElkIjoiMDE4OTY0MDU1NGI1NzAwYzgwYzJjNGEyMDJlMjQwMWQifQ.DgWj0Shiiy33hstb2U4vwgqJeW4m4ODEVuzwDpOH2Os'); $action = $contextResolver->assembleStorefrontRequest( $request, $this->getShop() ); + static::assertSame(['foo', 'bar'], $action->claims->getInAppPurchases()); + static::assertTrue($action->claims->hasInAppPurchase('foo')); + static::assertTrue($action->claims->hasInAppPurchase('bar')); + static::assertFalse($action->claims->hasInAppPurchase('baz')); + static::assertSame('0189640554b5700c80c2c4a202e2401d', $action->claims->getSalesChannelId()); } @@ -818,6 +899,7 @@ public function testAssembleCheckoutGatewayRequest(): void 'source' => [ 'url' => 'https://example.com', 'appVersion' => 'foo', + 'inAppPurchases' => ['foo', 'bar'], ], 'cart' => [ 'token' => 'cart-token', @@ -844,6 +926,11 @@ public function testAssembleCheckoutGatewayRequest(): void static::assertSame('https://example.com', $action->source->url); static::assertSame('foo', $action->source->appVersion); + static::assertSame(['foo', 'bar'], $action->source->inAppPurchases); + static::assertTrue($action->source->hasInAppPurchase('foo')); + static::assertTrue($action->source->hasInAppPurchase('bar')); + static::assertFalse($action->source->hasInAppPurchase('baz')); + static::assertSame('cart-token', $action->cart->getToken()); static::assertSame('sales-channel-id', $action->context->getSalesChannel()->getId()); @@ -893,6 +980,15 @@ public function testParseSourceInvalid(string $source): void $contextResolver->assembleWebhook($request, $this->getShop()); } + public function testParseInAppPurchasesInvalid(): void + { + $request = new Request('POST', '/', [], '{"source":{"url":"https://example.com","appVersion":"foo","inAppPurchases":1}}'); + + $contextResolver = new ContextResolver(); + static::expectException(MalformedWebhookBodyException::class); + $contextResolver->assembleWebhook($request, $this->getShop()); + } + /** * @return iterable */ diff --git a/tests/Context/Storefront/StorefrontClaimsTest.php b/tests/Context/Storefront/StorefrontClaimsTest.php index caf60cf..15c8fd9 100644 --- a/tests/Context/Storefront/StorefrontClaimsTest.php +++ b/tests/Context/Storefront/StorefrontClaimsTest.php @@ -20,6 +20,7 @@ public function testAllSet(): void 'languageId' => 'languageId', 'paymentMethodId' => 'paymentMethodId', 'shippingMethodId' => 'shippingMethodId', + 'inAppPurchases' => ['foo', 'bar'], ]); static::assertSame('salesChannelId', $claims->getSalesChannelId()); @@ -28,6 +29,21 @@ public function testAllSet(): void static::assertSame('languageId', $claims->getLanguageId()); static::assertSame('paymentMethodId', $claims->getPaymentMethodId()); static::assertSame('shippingMethodId', $claims->getShippingMethodId()); + + static::assertSame(['foo','bar'], $claims->getInAppPurchases()); + static::assertTrue($claims->hasInAppPurchase('foo')); + static::assertTrue($claims->hasInAppPurchase('bar')); + static::assertFalse($claims->hasInAppPurchase('baz')); + } + + public function testWithNonInAppPurchaseArray(): void + { + $claims = new StorefrontClaims([ + 'inAppPurchases' => 'this-is-wrong', + ]); + + $this->expectExceptionMessage('Missing claim "inAppPurchases", did you forgot to add permissions in your app to this?'); + $claims->getInAppPurchases(); } public function testMissingSalesChannelId(): void @@ -77,4 +93,11 @@ public function testMissingShippingMethodId(): void $this->expectExceptionMessage('Missing claim "shippingMethodId"'); $claims->getShippingMethodId(); } + + public function testMissingInAppPurchases(): void + { + $claims = new StorefrontClaims([]); + + static::assertSame([], $claims->getInAppPurchases()); + } } diff --git a/tests/Context/_fixtures/payment-validation.json b/tests/Context/_fixtures/payment-validation.json index c63b865..02d4f14 100644 --- a/tests/Context/_fixtures/payment-validation.json +++ b/tests/Context/_fixtures/payment-validation.json @@ -2,7 +2,8 @@ "source": { "url": "http:\/\/localhost:8000", "shopId": "hRCw2xo1EDZnLco4", - "appVersion": "1.0.0" + "appVersion": "1.0.0", + "inAppPurchases": ["foo", "bar"] }, "cart": { "extensions": { diff --git a/tests/Context/_fixtures/payment.json b/tests/Context/_fixtures/payment.json index c0b1c21..738b59c 100644 --- a/tests/Context/_fixtures/payment.json +++ b/tests/Context/_fixtures/payment.json @@ -2,7 +2,8 @@ "source": { "url": "http:\/\/localhost:8000", "shopId": "hRCw2xo1EDZnLco4", - "appVersion": "1.0.0" + "appVersion": "1.0.0", + "inAppPurchases": ["foo", "bar"] }, "orderTransaction": { "extensions": { diff --git a/tests/Context/_fixtures/refund.json b/tests/Context/_fixtures/refund.json index fce1d45..c9bb827 100644 --- a/tests/Context/_fixtures/refund.json +++ b/tests/Context/_fixtures/refund.json @@ -2,7 +2,8 @@ "source": { "url": "http:\/\/localhost:8000", "shopId": "vvRy7Nv3Bo8mAVda", - "appVersion": "1.0.0" + "appVersion": "1.0.0", + "inAppPurchases": ["foo", "bar"] }, "refund": { "extensions": { diff --git a/tests/Context/_fixtures/tax.json b/tests/Context/_fixtures/tax.json index 54bf1f2..addcd0e 100644 --- a/tests/Context/_fixtures/tax.json +++ b/tests/Context/_fixtures/tax.json @@ -2,7 +2,8 @@ "source": { "url": "http:\/\/localhost:8000", "shopId": "vvRy7Nv3Bo8mAVda", - "appVersion": "1.0.0" + "appVersion": "1.0.0", + "inAppPurchases": ["foo", "bar"] }, "cart": { "extensions": { diff --git a/tests/Response/PaymentResponseTest.php b/tests/Response/PaymentResponseTest.php index 93c6d7c..f876504 100644 --- a/tests/Response/PaymentResponseTest.php +++ b/tests/Response/PaymentResponseTest.php @@ -11,6 +11,14 @@ #[CoversClass(PaymentResponse::class)] class PaymentResponseTest extends TestCase { + public function testCreateStatusResponse(): void + { + $response = PaymentResponse::createStatusResponse('status'); + + static::assertSame(200, $response->getStatusCode()); + static::assertSame('{"status":"status"}', $response->getBody()->getContents()); + } + public function testPaid(): void { $response = PaymentResponse::paid();