ShopUserTokenStruct 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
        );

        /** @var AdminApiSource $adminSource */
        
'query' => $this->getQueries($context),
                'json' => [
                    'shopwareId' => $shopwareId,
                    'password' => $password,
                    'shopwareUserId' => $userId,
                ],
            ]
        );

        $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);

        
$frwService = $this->createFirstRunWizardService(
            frwClient: $frwClient,
        );

        $this->expectException(\RuntimeException::class);

        $frwService->upgradeAccessToken(Context::createDefaultContext());
    }

    public function testSuccessfulUpgradeAccessTokenDeletesFrwTokenAndStoresStoreToken(): void
    {
        $shopUserTokenStruct = new ShopUserTokenStruct(
            'shop-us3r-t0k3n',
            new \DateTimeImmutable('2022-12-15'),
        );

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

        


        return $this->userConfigRepository->searchIds($criteria$context)->firstId();
    }

    /** * @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,
        );
    }
}
Home | Imprint | This part of the site doesn't use cookies.