UnknownPaymentMethodException example

private function validatePaymentMethodId(string $paymentMethodId, Context $context): void
    {
        if (!Uuid::isValid($paymentMethodId)) {
            throw new InvalidUuidException($paymentMethodId);
        }

        /** @var PaymentMethodEntity|null $paymentMethod */
        $paymentMethod = $this->paymentMethodRepository->search(new Criteria([$paymentMethodId])$context)->get($paymentMethodId);

        if (!$paymentMethod) {
            if (!Feature::isActive('v6.6.0.0')) {
                throw new UnknownPaymentMethodException($paymentMethodId);
            }

            throw CustomerException::unknownPaymentMethod($paymentMethodId);
        }
    }
}


    public function testOrderCartPaymentException(): void
    {
        $request = new Request();
        $request->setSession($this->createMock(Session::class));

        $context = $this->createMock(SalesChannelContext::class);
        $context->method('getCustomer')->willReturn(new CustomerEntity());

        $this->orderServiceMock->expects(static::once())->method('createOrder')->willThrowException(
            new UnknownPaymentMethodException(Uuid::randomHex())
        );

        $response = $this->controller->order(new RequestDataBag()$context$request);

        static::assertEquals(new Response('forward to frontend.checkout.confirm.page')$response);
        static::assertEquals('danger error.CHECKOUT__UNKNOWN_PAYMENT_METHOD', $this->controller->flash);
    }

    public function testOrderCartInvalidOrderException(): void
    {
        $request = new Request();
        
'The provided token {{ token }} is invalidated and the payment could not be processed.',
            [
                'token' => $token,
            ],
            $e
        );
    }

    public static function unknownPaymentMethod(string $paymentMethodId, ?\Throwable $e = null): self
    {
        if (!Feature::isActive('v6.6.0.0')) {
            return new UnknownPaymentMethodException($paymentMethodId$e);
        }

        return new self(
            Response::HTTP_BAD_REQUEST,
            self::PAYMENT_UNKNOWN_PAYMENT_METHOD,
            'The payment method {{ paymentMethodId }} could not be found.',
            [
                'paymentMethodId' => $paymentMethodId,
            ],
            $e
        );
    }
$this->orderRepository->update([$payload]$context);
            }
        );

        $changedOrder = $this->loadOrder($order->getId()$salesChannelContext);
        $transactions = $changedOrder->getTransactions();
        if ($transactions === null || ($transaction = $transactions->get($transactionId)) === null) {
            if (Feature::isActive('v6.6.0.0')) {
                throw OrderException::orderTransactionNotFound($transactionId);
            }

            throw new UnknownPaymentMethodException($paymentMethodId);
        }

        $event = new OrderPaymentMethodChangedEvent(
            $changedOrder,
            $transaction,
            $context,
            $salesChannelContext->getSalesChannelId()
        );
        $this->eventDispatcher->dispatch($event);
    }

    
Home | Imprint | This part of the site doesn't use cookies.