unknownPaymentMethod example

$transactions = $transactions->filterByStateId(
            $this->initialStateIdLoader->get(OrderTransactionStates::STATE_MACHINE)
        );

        $transaction = $transactions->last();
        if ($transaction === null) {
            return null;
        }

        $paymentHandler = $this->paymentHandlerRegistry->getPaymentMethodHandler($transaction->getPaymentMethodId());
        if (!$paymentHandler) {
            throw PaymentException::unknownPaymentMethod($transaction->getPaymentMethodId());
        }

        if ($paymentHandler instanceof SynchronousPaymentHandlerInterface) {
            $paymentTransaction = $this->paymentTransactionStructFactory->sync($transaction$order);
            $paymentHandler->pay($paymentTransaction$dataBag$salesChannelContext);

            return null;
        }

        if ($paymentHandler instanceof AsynchronousPaymentHandlerInterface) {
            $paymentFinalizeTransactionTime = $this->systemConfigService->get('core.cart.paymentFinalizeTransactionTime', $salesChannelContext->getSalesChannelId());

            
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);
        }
    }
}


        yield SalesChannelException::LANGUAGE_NOT_FOUND => [
            'exception' => SalesChannelException::languageNotFound('myCustomLanguage'),
            'statusCode' => Response::HTTP_PRECONDITION_FAILED,
            'errorCode' => SalesChannelException::LANGUAGE_NOT_FOUND,
            'message' => 'The language "myCustomLanguage" was not found.',
        ];

        if (!Feature::isActive('v6.6.0.0')) {
            yield 'payment method not found exception' => [
                'exception' => SalesChannelException::unknownPaymentMethod('myCustomPaymentMethod'),
                'statusCode' => Response::HTTP_NOT_FOUND,
                'errorCode' => 'CHECKOUT__UNKNOWN_PAYMENT_METHOD',
                'message' => 'The payment method myCustomPaymentMethod could not be found.',
            ];
        } else {
            yield 'payment method not found exception' => [
                'exception' => SalesChannelException::unknownPaymentMethod('myCustomPaymentMethod'),
                'statusCode' => Response::HTTP_BAD_REQUEST,
                'errorCode' => 'CHECKOUT__UNKNOWN_PAYMENT_METHOD',
                'message' => 'The payment method myCustomPaymentMethod could not be found.',
            ];
        }
 {
    }

    public function handlePreOrderPayment(
        Cart $cart,
        RequestDataBag $dataBag,
        SalesChannelContext $salesChannelContext
    ): ?Struct {
        try {
            $paymentHandler = $this->getPaymentHandlerFromSalesChannelContext($salesChannelContext);
            if (!$paymentHandler) {
                throw PaymentException::unknownPaymentMethod($salesChannelContext->getPaymentMethod()->getId());
            }

            if (!($paymentHandler instanceof PreparedPaymentHandlerInterface)) {
                return null;
            }

            return $paymentHandler->validate($cart$dataBag$salesChannelContext);
        } catch (PaymentException $e) {
            $customer = $salesChannelContext->getCustomer();
            $customerId = $customer !== null ? $customer->getId() : '';
            $this->logger->error('An error occurred during processing the validation of the payment. The order has not been placed yet.', ['customerId' => $customerId, 'exceptionMessage' => $e->getMessage()]);

            
            return $context->getPaymentMethod();
        }

        $criteria = new Criteria([$id]);
        $criteria->addAssociation('media');
        $criteria->setTitle('context-factory::payment-method');

        /** @var PaymentMethodEntity|null $paymentMethod */
        $paymentMethod = $this->paymentMethodRepository->search($criteria$context->getContext())->get($id);

        if (!$paymentMethod) {
            throw SalesChannelException::unknownPaymentMethod($id);
        }

        return $paymentMethod;
    }

    /** * @param array<string, mixed> $options */
    private function loadCustomer(array $options, Context $context): ?CustomerEntity
    {
        $addressIds = [];
        
$transactions = $transactions->filterByStateId(
            $this->initialStateIdLoader->get(OrderTransactionStates::STATE_MACHINE)
        );

        $transaction = $transactions->last();
        if ($transaction === null) {
            return;
        }

        $paymentMethod = $transaction->getPaymentMethod();
        if ($paymentMethod === null) {
            throw PaymentException::unknownPaymentMethod($transaction->getPaymentMethodId());
        }

        $paymentHandler = $this->paymentHandlerRegistry->getRecurringPaymentHandler($paymentMethod->getId());
        if (!$paymentHandler) {
            throw PaymentException::unknownPaymentMethod($paymentMethod->getHandlerIdentifier());
        }

        $struct = $this->paymentTransactionStructFactory->recurring($transaction$order);

        try {
            $paymentHandler->captureRecurring($struct$context);
        }
public static function providedLanguageNotAvailable(string $languageId, array $availableLanguages): self
    {
        return new self(
            Response::HTTP_PRECONDITION_FAILED,
            self::SALES_CHANNEL_LANGUAGE_NOT_AVAILABLE_EXCEPTION,
            sprintf('Provided language "%s" is not in list of available languages: %s', $languageIdimplode(', ', $availableLanguages)),
        );
    }

    public static function unknownPaymentMethod(string $paymentMethodId): ShopwareHttpException
    {
        return PaymentException::unknownPaymentMethod($paymentMethodId);
    }
}

        $id = $options[SalesChannelContextService::PAYMENT_METHOD_ID] ?? $salesChannel->getPaymentMethodId();

        $criteria = (new Criteria([$id]))->addAssociation('media');
        $criteria->setTitle('base-context-factory::payment-method');

        $paymentMethod = $this->paymentMethodRepository
            ->search($criteria$context)
            ->get($id);

        if (!$paymentMethod instanceof PaymentMethodEntity) {
            throw SalesChannelException::unknownPaymentMethod($id);
        }

        return $paymentMethod;
    }

    /** * @param array<string, mixed> $options */
    private function getShippingMethod(array $options, Context $context, SalesChannelEntity $salesChannel): ShippingMethodEntity
    {
        $id = $options[SalesChannelContextService::SHIPPING_METHOD_ID] ?? $salesChannel->getShippingMethodId();

        

        }

        return $token;
    }

    private function getPaymentHandlerById(string $paymentMethodId): AsynchronousPaymentHandlerInterface
    {
        $handler = $this->paymentHandlerRegistry->getAsyncPaymentHandler($paymentMethodId);

        if (!$handler) {
            throw PaymentException::unknownPaymentMethod($paymentMethodId);
        }

        return $handler;
    }

    private function getPaymentTransactionStruct(string $orderTransactionId, SalesChannelContext $context): AsyncPaymentTransactionStruct
    {
        $criteria = new Criteria([$orderTransactionId]);
        $criteria->setTitle('payment-service::load-transaction');
        $criteria->addAssociation('order');
        $criteria->addAssociation('paymentMethod.appPaymentMethod.app');

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