actionButtonProcessException example

private readonly RouterInterface $router,
        private readonly RequestStack $requestStack,
        private readonly KernelInterface $kernel
    ) {
    }

    public function execute(AppAction $action, Context $context): Response
    {
        try {
            $this->shopIdProvider->getShopId();
        } catch (AppUrlChangeDetectedException $e) {
            throw AppException::actionButtonProcessException($action->getActionId()$e->getMessage()$e);
        }

        $payload = $action->asPayload();
        $payload['meta'] = [
            'timestamp' => (new \DateTime())->getTimestamp(),
            'reference' => Uuid::randomHex(),
            'language' => $context->getLanguageId(),
        ];

        $appSecret = $action->getAppSecret();

        
/** * @param array<mixed> $payload */
    public function createFromResponse(AppAction $action, string $actionType, array $payload, Context $context): ActionButtonResponse
    {
        foreach ($this->factories as $factory) {
            if ($factory->supports($actionType)) {
                return $factory->create($action$payload$context);
            }
        }

        throw AppException::actionButtonProcessException($action->getActionId()sprintf('No factory found for action type "%s"', $actionType));
    }
}
$response->assign($payload);

        return $response;
    }

    /** * @param array<mixed> $payload */
    private function validate(array $payload, string $actionId): void
    {
        if (!isset($payload['redirectUrl']) || empty($payload['redirectUrl'])) {
            throw AppException::actionButtonProcessException($actionId, 'The app provided an invalid redirectUrl');
        }
    }
}
$response->assign($payload);

        return $response;
    }

    /** * @param array<mixed> $payload */
    private function validate(array $payload, string $actionId): void
    {
        if (!isset($payload['iframeUrl']) || empty($payload['iframeUrl'])) {
            throw AppException::actionButtonProcessException($actionId, 'The app provided an invalid iframeUrl');
        }

        if (!isset($payload['size']) || !\in_array($payload['size'], self::VALID_MODAL_SIZES, true)) {
            throw AppException::actionButtonProcessException($actionId, 'The app provided an invalid size');
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.