AccessTokenStruct example

protected function setUp(): void
    {
        $this->storeService = $this->getContainer()->get(StoreService::class);
    }

    public function testUpdateStoreToken(): void
    {
        $adminStoreContext = $this->createAdminStoreContext();

        $newToken = 'updated-store-token';
        $accessTokenStruct = new AccessTokenStruct(
            new ShopUserTokenStruct(
                $newToken,
                new \DateTimeImmutable()
            )
        );

        $this->storeService->updateStoreToken(
            $adminStoreContext,
            $accessTokenStruct
        );

        
/** * @param array{shopSecret?: string} $accessTokenData * @param array{token: string, expirationDate: string} $userTokenData */
    private function createAccessTokenStruct(array $accessTokenData, array $userTokenData): AccessTokenStruct
    {
        $userToken = new ShopUserTokenStruct(
            $userTokenData['token'],
            new \DateTimeImmutable($userTokenData['expirationDate'])
        );

        return new AccessTokenStruct(
            $userToken,
            $accessTokenData['shopSecret'] ?? null,
        );
    }
}
new \DateTimeImmutable('2022-12-15'),
        );

        $shopUserTokenResponse = [
            'shopUserToken' => [
                'token' => $shopUserTokenStruct->getToken(),
                'expirationDate' => $shopUserTokenStruct->getExpirationDate()->format(Defaults::STORAGE_DATE_FORMAT),
            ],
            'shopSecret' => 'shop-s3cr3t',
        ];

        $accessTokenStruct = new AccessTokenStruct(
            $shopUserTokenStruct,
            $shopUserTokenResponse['shopSecret']
        );

        $frwClient = $this->createMock(FirstRunWizardClient::class);
        $frwClient->expects(static::once())
            ->method('upgradeAccessToken')
            ->willReturn($shopUserTokenResponse);

        $storeService = $this->createMock(StoreService::class);
        $storeService->expects(static::once())
            

            ]
        );

        $data = \json_decode($response->getBody()->getContents(), true, flags: \JSON_THROW_ON_ERROR);

        $userToken = new ShopUserTokenStruct(
            $data['shopUserToken']['token'],
            new \DateTimeImmutable($data['shopUserToken']['expirationDate'])
        );

        $accessTokenStruct = new AccessTokenStruct(
            $userToken,
            $data['shopSecret'] ?? null,
        );

        $this->storeService->updateStoreToken($context$accessTokenStruct);

        $this->configService->set('core.store.shopSecret', $accessTokenStruct->getShopSecret());
    }

    /** * @return array<string, mixed> */

    public function hydrateAccessToken($data$shopwareId)
    {
        $time = new DateTime(
            $data['expire']['date'],
            new DateTimeZone($data['expire']['timezone'])
        );

        $struct = new AccessTokenStruct(
            $data['token'],
            $time,
            $shopwareId,
            $data['userId'],
            $data['locale']
        );

        return $struct;
    }

    /** * @param array $data * * @return PluginStruct */
Home | Imprint | This part of the site doesn't use cookies.