finalizeTransaction example


        $data = $this->prepareTransaction();

        $response = (new AsyncFinalizeResponse())->assign([
            'message' => self::ERROR_MESSAGE,
        ]);
        $json = \json_encode($response, \JSON_THROW_ON_ERROR);
        static::assertNotFalse($json);

        $this->appendNewResponse(new Response(200, ['shopware-app-signature' => 'invalid']$json));

        $return = $this->paymentService->finalizeTransaction($data['token']new \Symfony\Component\HttpFoundation\Request()$this->getSalesChannelContext($data['paymentMethodId']));

        static::assertInstanceOf(PaymentException::class$return->getException());

        /** @var PaymentException $exception */
        $exception = $return->getException();
        static::assertEquals(PaymentException::PAYMENT_ASYNC_FINALIZE_INTERRUPTED, $exception->getErrorCode());

        if (!Feature::isActive('v6.6.0.0')) {
            static::assertInstanceOf(AsyncPaymentFinalizeException::class$return->getException());
        }

        
#[Route(path: '/payment/finalize-transaction', name: 'payment.finalize.transaction', methods: ['GET', 'POST'])]     public function finalizeTransaction(Request $request): Response
    {
        $paymentToken = $request->get('_sw_payment_token');

        if ($paymentToken === null) {
            throw RoutingException::missingRequestParameter('_sw_payment_token');
        }

        $salesChannelContext = $this->assembleSalesChannelContext($paymentToken);

        $result = $this->paymentService->finalizeTransaction(
            $paymentToken,
            $request,
            $salesChannelContext
        );

        $response = $this->handleException($result);
        if ($response !== null) {
            return $response;
        }

        $finishUrl = $result->getFinishUrl();
        
$tokenFactory,
            $paymentHandlerRegistry,
            $transactionRepository,
            $this->createMock(OrderTransactionStateHandler::class),
            $this->createMock(LoggerInterface::class),
            $this->createMock(EntityRepository::class),
            $this->createMock(SalesChannelContextServiceInterface::class),
            $paymentStructFactory,
            $eventDispatcher
        );

        $paymentService->finalizeTransaction('paymentToken', $request$context);
    }
}
static::assertNotNull($response);
        static::assertEquals(AsyncTestPaymentHandler::REDIRECT_URL, $response->getTargetUrl());

        $transaction = new OrderTransactionEntity();
        $transaction->setId($transactionId);
        $transaction->setPaymentMethodId($paymentMethodId);
        $transaction->setOrderId($orderId);
        $transaction->setStateId(Uuid::randomHex());
        $tokenStruct = new TokenStruct(null, null, $transaction->getPaymentMethodId()$transaction->getId(), 'testFinishUrl');
        $token = $this->tokenFactory->generateToken($tokenStruct);
        $request = new Request();
        $tokenStruct = $this->paymentService->finalizeTransaction($token$request$salesChannelContext);

        static::assertSame('testFinishUrl', $tokenStruct->getFinishUrl());
        $criteria = new Criteria([$transactionId]);
        $criteria->addAssociation('stateMachineState');
        $transactionEntity = $this->orderTransactionRepository->search($criteria$this->context)->first();

        static::assertNotNull($transactionEntity);
        static::assertInstanceOf(OrderTransactionEntity::class$transactionEntity);
        static::assertSame(
            OrderTransactionStates::STATE_PAID,
            $transactionEntity->getStateMachineState()?->getTechnicalName()
        );
Home | Imprint | This part of the site doesn't use cookies.