asyncProcessInterrupted example

#[Package('core')] class AppAsyncPaymentHandler extends AppPaymentHandler implements AsynchronousPaymentHandlerInterface
{
    public function pay(AsyncPaymentTransactionStruct $transaction, RequestDataBag $dataBag, SalesChannelContext $salesChannelContext): RedirectResponse
    {
        $this->transactionStateHandler->processUnconfirmed($transaction->getOrderTransaction()->getId()$salesChannelContext->getContext());

        $payload = $this->buildPayPayload($transaction$dataBag->all());

        $app = $this->getAppPaymentMethod($transaction->getOrderTransaction())->getApp();
        if ($app === null) {
            throw PaymentException::asyncProcessInterrupted($transaction->getOrderTransaction()->getId(), 'App not defined');
        }

        $url = $this->getAppPaymentMethod($transaction->getOrderTransaction())->getPayUrl();
        if ($url === null) {
            throw PaymentException::asyncFinalizeInterrupted($transaction->getOrderTransaction()->getId(), 'Pay URL not defined');
        }

        try {
            $response = $this->payloadService->request($url$payload$app, AsyncPayResponse::class$salesChannelContext->getContext());
        } catch (ClientExceptionInterface $exception) {
            throw PaymentException::asyncProcessInterrupted($transaction->getOrderTransaction()->getId()sprintf('App error: %s', $exception->getMessage()));
        }
public function getRedirectUrl(): string
    {
        return $this->redirectUrl;
    }

    public function validate(string $transactionId): void
    {
        if (!$this->redirectUrl
            && !$this->message
            && $this->status !== StateMachineTransitionActions::ACTION_FAIL
        ) {
            throw PaymentException::asyncProcessInterrupted($transactionId, 'No redirect URL provided by App');
        }
    }
}
$response->getStatus(),
                'stateId'
            ),
            $context
        );
    }

    protected function getAppPaymentMethod(OrderTransactionEntity $orderTransaction): AppPaymentMethodEntity
    {
        $paymentMethod = $orderTransaction->getPaymentMethod();
        if ($paymentMethod === null) {
            throw PaymentException::asyncProcessInterrupted($orderTransaction->getId(), 'Loaded data invalid');
        }

        $appPaymentMethod = $paymentMethod->getAppPaymentMethod();
        if ($appPaymentMethod === null) {
            throw PaymentException::asyncProcessInterrupted($orderTransaction->getId(), 'Loaded data invalid');
        }

        return $appPaymentMethod;
    }

    protected function buildRefundPayload(OrderTransactionCaptureRefundEntity $refund, OrderEntity $order): RefundPayload
    {
$payload = $this->buildPayload($transaction$dataBag->all());

        $app = $this->getAppPaymentMethod($transaction->getOrderTransaction())->getApp();
        if ($app === null) {
            throw PaymentException::syncProcessInterrupted($transaction->getOrderTransaction()->getId(), 'App not defined');
        }

        try {
            $response = $this->payloadService->request($payUrl$payload$app, SyncPayResponse::class$salesChannelContext->getContext());
        } catch (ClientExceptionInterface $exception) {
            throw PaymentException::asyncProcessInterrupted($transaction->getOrderTransaction()->getId()sprintf('App error: %s', $exception->getMessage()));
        }

        if (!$response instanceof SyncPayResponse) {
            throw PaymentException::syncProcessInterrupted($transaction->getOrderTransaction()->getId(), 'Invalid app response');
        }

        if ($response->getMessage() || $response->getStatus() === StateMachineTransitionActions::ACTION_FAIL) {
            throw PaymentException::syncProcessInterrupted($transaction->getOrderTransaction()->getId()$response->getMessage() ?? 'Payment was reported as failed.');
        }

        if (empty($response->getStatus())) {
            
/** * @return array<string, mixed> */
    private function getRequestOptions(SourcedPayloadInterface $payload, AppEntity $app, Context $context): array
    {
        $payload->setSource($this->buildSource($app));
        $encoded = $this->encode($payload);
        $jsonPayload = json_encode($encoded, \JSON_THROW_ON_ERROR);

        if (!$jsonPayload) {
            if ($payload instanceof PaymentPayloadInterface) {
                throw PaymentException::asyncProcessInterrupted($payload->getOrderTransaction()->getId(), \sprintf('Empty payload, got: %s', var_export($jsonPayload, true)));
            }

            throw PaymentException::validatePreparedPaymentInterrupted(\sprintf('Empty payload, got: %s', var_export($jsonPayload, true)));
        }

        $secret = $app->getAppSecret();
        if ($secret === null) {
            throw AppException::registrationFailed($app->getName(), 'App secret is missing');
        }

        return [
            
/** * @return array<string, mixed> */
    private function getRequestOptions(SourcedPayloadInterface $payload, AppEntity $app, Context $context): array
    {
        $payload->setSource($this->helper->buildSource($app$this->shopUrl));
        $encoded = $this->helper->encode($payload);
        $jsonPayload = json_encode($encoded, \JSON_THROW_ON_ERROR);

        if (!$jsonPayload) {
            if ($payload instanceof PaymentPayloadInterface) {
                throw PaymentException::asyncProcessInterrupted($payload->getOrderTransaction()->getId(), \sprintf('Empty payload, got: %s', var_export($jsonPayload, true)));
            }

            throw PaymentException::validatePreparedPaymentInterrupted(\sprintf('Empty payload, got: %s', var_export($jsonPayload, true)));
        }

        $secret = $app->getAppSecret();
        if ($secret === null) {
            throw AppException::registrationFailed($app->getName(), 'App secret is missing');
        }

        return [
            
return $token;
        }

        if ($token->getPaymentMethodId() === null) {
            throw PaymentException::invalidToken($paymentToken);
        }

        $transactionId = $token->getTransactionId();

        if ($transactionId === null || !Uuid::isValid($transactionId)) {
            throw PaymentException::asyncProcessInterrupted((string) $transactionId, 'Payment JWT didn\'t contain a valid orderTransactionId');
        }

        $transaction = $this->getPaymentTransactionStruct($transactionId$context);

        $paymentHandler = $this->getPaymentHandlerById($token->getPaymentMethodId());

        try {
            $paymentHandler->finalize($transaction$request$context);
        } catch (CustomerCanceledAsyncPaymentException|PaymentException $e) {
            if ($e->getErrorCode() === PaymentException::PAYMENT_CUSTOMER_CANCELED_EXTERNAL) {
                $this->transactionStateHandler->cancel($transactionId$context->getContext());
            }
Home | Imprint | This part of the site doesn't use cookies.