setPaymentMethodId example

->with(static::isInstanceOf(RecurringPaymentOrderCriteriaEvent::class));

        $processor = new PaymentRecurringProcessor($repo$stateLoader$stateHandler$registrynew PaymentTransactionStructFactory()$dispatcher);
        $processor->processRecurring('foo', Context::createDefaultContext());
    }

    public function testTransactionWithoutPaymentMethodThrows(): void
    {
        $transaction = new OrderTransactionEntity();
        $transaction->setId('foo');
        $transaction->setStateId('initial_state_id');
        $transaction->setPaymentMethodId('foo');

        $transactions = new OrderTransactionCollection([$transaction]);

        $order = new OrderEntity();
        $order->setId('foo');
        $order->setTransactions($transactions);

        $repo = $this->createMock(EntityRepository::class);
        $repo
            ->expects(static::once())
            ->method('search')
            
static::expectException(PaymentException::class);
        static::expectExceptionMessage('The provided token ' . $token . ' is invalidated and the payment could not be processed.');

        $tokenFactory->parseToken($token);
    }

    public static function createTransaction(): OrderTransactionEntity
    {
        $transactionStruct = new OrderTransactionEntity();
        $transactionStruct->setId(Uuid::randomHex());
        $transactionStruct->setOrderId(Uuid::randomHex());
        $transactionStruct->setPaymentMethodId(Uuid::randomHex());
        $transactionStruct->setStateId(Uuid::randomHex());

        return $transactionStruct;
    }

    /** * @return iterable<array-key, array{int, bool}> */
    public static function dataProviderExpiration(): iterable
    {
        yield 'positive expire' => [30, false];
        
private SalesChannelContext $context;

    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,
            


        return $errorCollection;
    }

    private function getSalesChannelContext(bool $dontReturnDefaultPaymentMethod = false): SalesChannelContext
    {
        $salesChannel = new SalesChannelEntity();
        $salesChannel->setId(TestDefaults::SALES_CHANNEL);
        $salesChannel->setLanguageId(Defaults::LANGUAGE_SYSTEM);
        if ($dontReturnDefaultPaymentMethod) {
            $salesChannel->setPaymentMethodId('not-a-valid-id');
        } else {
            $salesChannel->setPaymentMethodId('default-payment-method-id');
        }

        $salesChannelContext = $this->createMock(SalesChannelContext::class);
        $salesChannelContext->method('getSalesChannel')->willReturn($salesChannel);
        $salesChannelContext->method('getContext')->willReturn(Context::createDefaultContext());
        $salesChannelContext->method('getPaymentMethod')->willReturn($this->paymentMethodCollection->get('original-payment-method-id'));

        return $salesChannelContext;
    }

    
$orderDelivery->setPositions($orderDeliveryPositionCollection);
        }
        if ($toManipulate !== 'order-no-order-deliveries') {
            $orderDeliveryCollection->add($orderDelivery);
        }

        // Transactions         $orderTransactionCollection = new OrderTransactionCollection();

        $orderTransaction = new OrderTransactionEntity();
        $orderTransaction->setId('order-transaction-id');
        $orderTransaction->setPaymentMethodId('order-transaction-payment-method-id');
        $stateMachineState = new StateMachineStateEntity();
        $stateMachineState->setId('state-machine-state-id');
        $stateMachineState->setTechnicalName('state-machine-state-technical-name');
        $orderTransaction->setStateMachineState($stateMachineState);

        $orderTransactionCancelled = new OrderTransactionEntity();
        $orderTransactionCancelled->setId('order-transaction-cancelled-id');
        $orderTransactionCancelled->setPaymentMethodId('order-transaction-cancelled-payment-method-id');
        $stateMachineStateCancelled = new StateMachineStateEntity();
        $stateMachineStateCancelled->setId('state-machine-cancelled-state-id');
        $stateMachineStateCancelled->setTechnicalName('cancelled');
        
$invalidSalesChannelId = Uuid::randomHex();
        $paymentMethodId = Uuid::randomHex();
        $customerGroupId = Uuid::randomHex();
        $shippingMethodId = Uuid::randomHex();
        $currencyId = Uuid::randomHex();
        $countryStateId = Uuid::randomHex();
        $countryId = Uuid::randomHex();

        $salesChannelEntity = new SalesChannelEntity();
        $salesChannelEntity->setUniqueIdentifier(TestDefaults::SALES_CHANNEL);
        $salesChannelEntity->setCustomerGroupId($customerGroupId);
        $salesChannelEntity->setPaymentMethodId($paymentMethodId);
        $salesChannelEntity->setShippingMethodId($shippingMethodId);

        $currency = new CurrencyEntity();
        $rounding = new CashRoundingConfig(1, 1, true);
        $currency->setUniqueIdentifier($currencyId);
        $currency->setTotalRounding($rounding);
        $currency->setItemRounding($rounding);
        $currency->setId($currencyId);
        $currency->setFactor(1);

        $country = new CountryEntity();
        
$transactionId = $this->createTransaction($orderId$paymentMethodId$this->context);

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

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

        
$this->ids->get('test-order'),
            new RequestDataBag(),
            Generator::createSalesChannelContext()
        );
    }

    public function testThrowsExceptionOnNullPaymentHandler(): void
    {
        $transaction = new OrderTransactionEntity();
        $transaction->setId(Uuid::randomHex());
        $transaction->setStateId($this->ids->get('order-state'));
        $transaction->setPaymentMethodId($this->ids->get('payment'));

        $order = new OrderEntity();
        $order->setUniqueIdentifier($this->ids->get('test-order'));
        $order->setTransactions(new OrderTransactionCollection([$transaction]));

        $orderRepository = $this->createMock(EntityRepository::class);
        $orderRepository
            ->method('search')
            ->willReturn(
                new EntitySearchResult(
                    'order',
                    
$transactionId = $this->createTransaction($orderId$paymentMethodId$context);

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

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

        return $transaction;
    }
}
Home | Imprint | This part of the site doesn't use cookies.