handlePostOrderPayment example

$context->getSalesChannel()->getId()
        );

        Profiler::trace('checkout-order::event-listeners', function D) use ($event): void {
            $this->eventDispatcher->dispatch($event);
        });

        $this->cartPersister->delete($context->getToken()$context);

        try {
            Profiler::trace('checkout-order::post-payment', function D) use ($orderEntity$data$context$preOrderPayment): void {
                $this->preparedPaymentService->handlePostOrderPayment($orderEntity$data$context$preOrderPayment);
            });
        } catch (UnknownPaymentMethodException|PaymentException) {
            throw CartException::invalidPaymentButOrderStored($orderId);
        }

        return new CartOrderRouteResponse($orderEntity);
    }

    private function addCustomerComment(Cart $cart, DataBag $data): void
    {
        $customerComment = ltrim(rtrim((string) $data->get(OrderService::CUSTOMER_COMMENT_KEY, '')));

        
public function testCapture(): void
    {
        $paymentMethodId = $this->getPaymentMethodId('prepared');
        $orderId = $this->createOrder($paymentMethodId);
        $transactionId = $this->createTransaction($orderId$paymentMethodId);
        $salesChannelContext = $this->getSalesChannelContext($paymentMethodId);
        $order = $this->loadOrder($orderId$salesChannelContext);

        $response = new CaptureResponse();
        $this->appendNewResponse($this->signResponse($response->jsonSerialize()));

        $this->preparedPaymentService->handlePostOrderPayment($ordernew RequestDataBag()$salesChannelContextnew ArrayStruct(['test' => 'test']));

        /** @var Request $request */
        $request = $this->getLastRequest();
        $body = $request->getBody()->getContents();

        $appSecret = $this->app->getAppSecret();
        static::assertNotNull($appSecret);

        static::assertTrue($request->hasHeader('shopware-shop-signature'));
        static::assertSame(\hash_hmac('sha256', $body$appSecret)$request->getHeaderLine('shopware-shop-signature'));
        static::assertNotEmpty($request->getHeaderLine('sw-version'));
        
public function testHandlePostOrderPayment(): void
    {
        $paymentMethodId = $this->createPaymentMethod($this->context);
        $customerId = $this->createCustomer($this->context);
        $salesChannelContext = $this->getSalesChannelContext($paymentMethodId);
        $orderId = $this->createOrder($customerId$paymentMethodId$salesChannelContext->getContext());
        $this->createTransaction($orderId$paymentMethodId$salesChannelContext->getContext());
        $order = $this->loadOrder($orderId$salesChannelContext);
        $struct = new ArrayStruct(['testStruct']);

        $this->paymentService->handlePostOrderPayment($ordernew RequestDataBag()$salesChannelContext$struct);

        static::assertSame($struct, PreparedTestPaymentHandler::$preOrderPaymentStruct);
    }

    public function testHandlePostOrderPaymentWithoutStruct(): void
    {
        $paymentMethodId = $this->createPaymentMethod($this->context);
        $customerId = $this->createCustomer($this->context);
        $salesChannelContext = $this->getSalesChannelContext($paymentMethodId);
        $orderId = $this->createOrder($customerId$paymentMethodId$salesChannelContext->getContext());
        $this->createTransaction($orderId$paymentMethodId$salesChannelContext->getContext());
        
Home | Imprint | This part of the site doesn't use cookies.