getPaymentMethodId example

$orderRepository = $this->createMock(EntityRepository::class);
        $orderRepository->expects(static::once())->method('search')->willReturn(new EntitySearchResult('order', 1, new OrderCollection([$order]), null, new Criteria()$context->getContext()));

        $struct = new SyncPaymentTransactionStruct($transaction$order);
        $paymentStructFactory = $this->createMock(AbstractPaymentTransactionStructFactory::class);
        $paymentStructFactory->expects(static::once())->method('sync')->willReturn($struct);

        $paymentHandler = $this->createMock(SynchronousPaymentHandlerInterface::class);
        $paymentHandler->expects(static::once())->method('pay')->with($struct$requestDataBag$context);

        $paymentHandlerRegistry = $this->createMock(PaymentHandlerRegistry::class);
        $paymentHandlerRegistry->expects(static::once())->method('getPaymentMethodHandler')->with($transaction->getPaymentMethodId())->willReturn($paymentHandler);

        $initialStateIdLoader = $this->createMock(InitialStateIdLoader::class);
        $initialStateIdLoader->expects(static::once())->method('get')->willReturn(OrderTransactionStates::STATE_OPEN);

        $processor = new PaymentTransactionChainProcessor(
            $this->createMock(TokenFactoryInterfaceV2::class),
            $orderRepository,
            $this->createMock(RouterInterface::class),
            $paymentHandlerRegistry,
            new StaticSystemConfigService([]),
            $initialStateIdLoader,
            
return true;
        }

        return false;
    }

    private function validateCart(Cart $cart, Context $context): void
    {
        $idsOfPaymentMethods = [];

        foreach ($cart->getTransactions() as $paymentMethod) {
            $idsOfPaymentMethods[] = $paymentMethod->getPaymentMethodId();
        }

        $criteria = new Criteria();
        $criteria->addFilter(
            new EqualsFilter('active', true)
        );

        $paymentMethods = $this->paymentMethodRepository->searchIds($criteria$context);

        if ($paymentMethods->getTotal() !== \count(array_unique($idsOfPaymentMethods))) {
            foreach ($cart->getTransactions() as $paymentMethod) {
                
$response = $this->paymentService->handlePaymentByOrder($orderIdnew RequestDataBag()$salesChannelContext);

        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);
        
/** * @extends EntityCollection<PaymentMethodTranslationEntity> */
#[Package('checkout')] class PaymentMethodTranslationCollection extends EntityCollection
{
    /** * @return list<string> */
    public function getPaymentMethodIds(): array
    {
        return $this->fmap(fn (PaymentMethodTranslationEntity $paymentMethodTranslation) => $paymentMethodTranslation->getPaymentMethodId());
    }

    public function filterByPaymentMethodId(string $id): self
    {
        return $this->filter(fn (PaymentMethodTranslationEntity $paymentMethodTranslation) => $paymentMethodTranslation->getPaymentMethodId() === $id);
    }

    /** * @return list<string> */
    public function getLanguageIds(): array
    {
$token = $this->tokenFactory->parseToken($paymentToken);

        if ($token->isExpired()) {
            $token->setException(PaymentException::tokenExpired($paymentToken));
            if ($token->getToken() !== null) {
                $this->tokenFactory->invalidateToken($token->getToken());
            }

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

        
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\Log\Package;

/** * @internal */
#[Package('checkout')] class AppRecurringHandlerTest extends AbstractAppPaymentHandlerTestCase
{
    public function testRecurring(): void
    {
        $paymentMethodId = $this->getPaymentMethodId('recurring');
        $orderId = $this->createOrder($paymentMethodId);
        $transactionId = $this->createTransaction($orderId$paymentMethodId);

        $response = RecurringPayResponse::create($transactionId[
            'status' => OrderTransactionStates::STATE_PAID,
        ]);

        $this->appendNewResponse($this->signResponse($response->jsonSerialize()));

        $paymentHandler = $this->getContainer()->get(AppPaymentHandler::class);
        $paymentHandler->captureRecurring($this->getRecurringStruct(), Context::createDefaultContext());

        
SalesChannelContextService::PERMISSIONS => self::ADMIN_EDIT_ORDER_PERMISSIONS,
            SalesChannelContextService::VERSION_ID => $context->getVersionId(),
        ];

        /** @var OrderDeliveryEntity|null $delivery */
        $delivery = $order->getDeliveries()?->first();
        if ($delivery !== null) {
            $options[SalesChannelContextService::SHIPPING_METHOD_ID] = $delivery->getShippingMethodId();
        }

        foreach ($order->getTransactions() as $transaction) {
            $options[SalesChannelContextService::PAYMENT_METHOD_ID] = $transaction->getPaymentMethodId();
            if (
                $transaction->getStateMachineState() !== null
                && $transaction->getStateMachineState()->getTechnicalName() !== OrderTransactionStates::STATE_PAID
                && $transaction->getStateMachineState()->getTechnicalName() !== OrderTransactionStates::STATE_CANCELLED
                && $transaction->getStateMachineState()->getTechnicalName() !== OrderTransactionStates::STATE_FAILED
            ) {
                break;
            }
        }

        $options = array_merge($options$overrideOptions);

        
static::assertArrayHasKey('success', $responseprint_r($response, true));
        static::assertTrue($response['success']print_r($response, true));

        $criteria = new Criteria([$this->orderId]);
        $criteria->addAssociation('transactions');

        $order = $this->orderRepository->search($criteria, Context::createDefaultContext())->getEntities()->get($this->orderId);

        static::assertNotNull($order);
        static::assertNotNull($transactions = $order->getTransactions());
        static::assertNotNull($transaction = $transactions->last());
        static::assertEquals($this->defaultPaymentMethodId, $transaction->getPaymentMethodId());
    }

    public function testSetAnotherPaymentMethodToOrder(): void
    {
        if (!$this->getContainer()->has(AccountOrderController::class)) {
            // ToDo: NEXT-16882 - Reactivate tests again             static::markTestSkipped('Order mail tests should be fixed without storefront in NEXT-16882');
        }

        $dispatcher = $this->getContainer()->get('event_dispatcher');
        $phpunit = $this;
        
/** @var TaxCollection $taxes */
        $taxes = $this->taxRepository->search($criteria$context)->getEntities();

        return $taxes;
    }

    /** * @param array<string, mixed> $options */
    private function getPaymentMethod(array $options, Context $context, SalesChannelEntity $salesChannel): PaymentMethodEntity
    {
        $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);
        }

        
$customerRepository->upsert(
            [
                [
                    'id' => $customerId,
                    'name' => 'test',
                    'email' => $email,
                    'password' => $password,
                    'firstName' => 'foo',
                    'lastName' => 'bar',
                    'groupId' => $salesChannel->getCustomerGroupId(),
                    'salutationId' => $this->getValidSalutationId(),
                    'defaultPaymentMethodId' => $salesChannel->getPaymentMethodId(),
                    'salesChannelId' => $salesChannel->getId(),
                    'defaultBillingAddress' => [
                        'id' => $defaultBillingAddress,
                        'countryId' => $salesChannel->getCountryId(),
                        'salutationId' => $this->getValidSalutationId(),
                        'firstName' => 'foo',
                        'lastName' => 'bar',
                        'zipcode' => '48599',
                        'city' => 'gronau',
                        'street' => 'Schillerstr.',
                    ],
                    
private PaymentMethodRouteResponse $response;

    protected function setUp(): void
    {
        $this->decorated = $this->createMock(AbstractPaymentMethodRoute::class);
        $this->executor = $this->createMock(ScriptExecutor::class);
        $salesChannel = new SalesChannelEntity();
        $salesChannel->setId(Uuid::randomHex());
        $salesChannel->setPaymentMethodId(Uuid::randomHex());
        $paymentMethod = new PaymentMethodEntity();
        $paymentMethod->setId($salesChannel->getPaymentMethodId());
        $this->context = new SalesChannelContext(
            new Context(new SalesChannelApiSource(Uuid::randomHex())),
            Uuid::randomHex(),
            null,
            $salesChannel,
            new CurrencyEntity(),
            new CustomerGroupEntity(),
            new TaxCollection(),
            $paymentMethod,
            new ShippingMethodEntity(),
            new ShippingLocation(new CountryEntity(), null, null),
            
public function filterByCurrencyId(string $id): SalesChannelCollection
    {
        return $this->filter(fn (SalesChannelEntity $salesChannel) => $salesChannel->getCurrencyId() === $id);
    }

    /** * @return list<string> */
    public function getPaymentMethodIds(): array
    {
        return $this->fmap(fn (SalesChannelEntity $salesChannel) => $salesChannel->getPaymentMethodId());
    }

    public function filterByPaymentMethodId(string $id): SalesChannelCollection
    {
        return $this->filter(fn (SalesChannelEntity $salesChannel) => $salesChannel->getPaymentMethodId() === $id);
    }

    /** * @return list<string> */
    public function getShippingMethodIds(): array
    {
use Shopware\Core\Framework\App\Hmac\Guzzle\AuthMiddleware;
use Shopware\Core\Framework\App\Payment\Response\RefundResponse;
use Shopware\Core\Framework\Feature;

/** * @internal */
class AppRefundHandlerTest extends AbstractAppPaymentHandlerTestCase
{
    public function testRefund(): void
    {
        $paymentMethodId = $this->getPaymentMethodId('refundable');
        $orderId = $this->createOrder($paymentMethodId);
        $transactionId = $this->createTransaction($orderId$paymentMethodId);
        $captureId = $this->createCapture($transactionId);
        $refundId = $this->createRefund($captureId);

        $salesChannelContext = $this->getSalesChannelContext($paymentMethodId);

        $response = RefundResponse::create($transactionId[
            'status' => 'complete',
        ]);

        
public function filterByOrderId(string $id): self
    {
        return $this->filter(fn (OrderTransactionEntity $orderTransaction) => $orderTransaction->getOrderId() === $id);
    }

    /** * @return list<string> */
    public function getPaymentMethodIds(): array
    {
        return $this->fmap(fn (OrderTransactionEntity $orderTransaction) => $orderTransaction->getPaymentMethodId());
    }

    public function filterByPaymentMethodId(string $id): self
    {
        return $this->filter(fn (OrderTransactionEntity $orderTransaction) => $orderTransaction->getPaymentMethodId() === $id);
    }

    public function getApiAlias(): string
    {
        return 'order_transaction_collection';
    }

    
return $this->filter(fn (PaymentMethodEntity $paymentMethod) => $paymentMethod->getPluginId() === $id);
    }

    /** * Sorts the selected payment method first * If a different default payment method is defined, it will be sorted second * All other payment methods keep their respective sorting */
    public function sortPaymentMethodsByPreference(SalesChannelContext $context): void
    {
        $ids = array_merge(
            [$context->getPaymentMethod()->getId()$context->getSalesChannel()->getPaymentMethodId()],
            $this->getIds()
        );

        $this->sortByIdArray($ids);
    }

    public function getApiAlias(): string
    {
        return 'payment_method_collection';
    }

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