getTransactions example

$criteria->getAssociation('transactions')->addSorting(new FieldSorting('createdAt'));

        $this->eventDispatcher->dispatch(new RecurringPaymentOrderCriteriaEvent($orderId$criteria$context));

        /** @var OrderEntity $order */
        $order = $this->orderRepository->search($criteria$context)->first();

        if (!$order) {
            throw OrderException::orderNotFound($orderId);
        }

        $transactions = $order->getTransactions();
        if ($transactions === null) {
            throw OrderException::missingTransactions($orderId);
        }

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

        $transaction = $transactions->last();
        if ($transaction === null) {
            return;
        }
static::fail('Should catch a RecurringException');
    }

    private function getRecurringStruct(): RecurringPaymentTransactionStruct
    {
        $criteria = new Criteria([$this->ids->get('order')]);
        $criteria->addAssociation('transactions.paymentMethod.appPaymentMethod.app');

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

        static::assertInstanceOf(OrderEntity::class$order);
        static::assertInstanceOf(OrderTransactionCollection::class$order->getTransactions());
        static::assertCount(1, $order->getTransactions());

        $paymentTransaction = $order->getTransactions()->first();

        static::assertNotNull($paymentTransaction);

        return new RecurringPaymentTransactionStruct($paymentTransaction$order);
    }
}
$billingAddressId = $shippingAddresses[$customerAddressId]['id'];
            } else {
                $billingAddress = AddressTransformer::transform($activeBillingAddress);
                $data['addresses'] = [$billingAddress];
                $billingAddressId = $billingAddress['id'];
            }
            $data['billingAddressId'] = $billingAddressId;
        }

        if ($conversionContext->shouldIncludeTransactions()) {
            $data['transactions'] = TransactionTransformer::transformCollection(
                $cart->getTransactions(),
                $this->initialStateIdLoader->get(OrderTransactionStates::STATE_MACHINE),
                $context->getContext()
            );
        }

        $data['lineItems'] = array_values($convertedLineItems);

        foreach ($this->downloadLoader->load($data['lineItems']$context->getContext()) as $key => $downloads) {
            if (!\array_key_exists($key$data['lineItems'])) {
                continue;
            }

            
$preparedTransactionStruct = $this->paymentTransactionStructFactory->prepared($transaction$order);
            $paymentHandler->capture($preparedTransactionStruct$dataBag$salesChannelContext$preOrderStruct);
        } catch (PaymentProcessException $e) {
            $this->logger->error('An error occurred during processing the capture of the payment. The order has been placed.', ['orderId' => $order->getId(), 'exceptionMessage' => $e->getMessage()]);

            throw $e;
        }
    }

    private function getTransaction(OrderEntity $order, SalesChannelContext $salesChannelContext): ?OrderTransactionEntity
    {
        $transactions = $order->getTransactions();
        if ($transactions === null) {
            throw PaymentException::invalidOrder($order->getId());
        }

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

        return $transactions->last();
    }

    
'operator' => RuleConstraints::uuidOperators(false),
            'stateIds' => RuleConstraints::uuids(),
        ];
    }

    public function match(RuleScope $scope): bool
    {
        if (!$scope instanceof FlowRuleScope || $this->stateIds === null) {
            return false;
        }

        if (!$transactions = $scope->getOrder()->getTransactions()) {
            return false;
        }

        /** @var OrderTransactionEntity $last */
        $last = $transactions->last();
        $paymentMethodId = $last->getStateId();

        foreach ($transactions->getElements() as $transaction) {
            $technicalName = $transaction->getStateMachineState()?->getTechnicalName();
            if ($technicalName !== null
                && $technicalName !== OrderTransactionStates::STATE_FAILED
                
$this->orderConverter->assembleSalesChannelContext($order$context->getContext()),
            $event->getCriteria()
        )->getPaymentMethods();

        $paymentMethods->sortPaymentMethodsByPreference($context);

        return $paymentMethods;
    }

    private function isOrderPaid(OrderEntity $order): bool
    {
        $transactions = $order->getTransactions();

        if ($transactions === null) {
            return false;
        }

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

        $stateMachineState = $transaction->getStateMachineState();
        
$response = json_decode((string) $this->browser->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);

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

        
'ruleIds' => $this->getOrderRules($order$salesChannelContext),
        ];

        $context->scope(
            Context::SYSTEM_SCOPE,
            function D) use ($payload$context): void {
                $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,
            
public function testOrderTransactionStateTransition(): void
    {
        $orderId = $this->performOrder();

        // getting the id of the order transaction         $criteria = new Criteria([$orderId]);

        $criteria->addAssociation('transactions.stateMachineState');

        /** @var OrderEntity $order */
        $order = $this->orderRepository->search($criteria$this->salesChannelContext->getContext())->first();
        static::assertNotNull($transactions = $order->getTransactions());
        static::assertNotNull($transaction = $transactions->first());
        $orderTransactionId = $transaction->getId();

        $this->orderService->orderTransactionStateTransition(
            $orderTransactionId,
            'remind',
            new RequestDataBag(),
            $this->salesChannelContext->getContext()
        );

        /** @var OrderEntity $updatedOrder */
        
$criteria->getAssociation('transactions')->addSorting(new FieldSorting('createdAt'));

        $this->eventDispatcher->dispatch(new PayPaymentOrderCriteriaEvent($orderId$criteria$salesChannelContext));

        /** @var OrderEntity|null $order */
        $order = $this->orderRepository->search($criteria$salesChannelContext->getContext())->first();

        if (!$order) {
            throw PaymentException::invalidOrder($orderId);
        }

        $transactions = $order->getTransactions();
        if ($transactions === null) {
            throw PaymentException::invalidOrder($orderId);
        }

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

        $transaction = $transactions->last();
        if ($transaction === null) {
            return null;
        }
$toPlace = $stateMachineStates->get('toPlace');

        if (!$toPlace) {
            throw StateMachineException::stateMachineStateNotFound('order_transaction', $transition);
        }

        return $toPlace;
    }

    public function isPaymentChangeableByTransactionState(OrderEntity $order): bool
    {
        if ($order->getTransactions() === null) {
            return true;
        }

        $transaction = $order->getTransactions()->last();

        if ($transaction === null || $transaction->getStateMachineState() === null) {
            return true;
        }

        $state = $transaction->getStateMachineState()->getTechnicalName();

        


    private function setOrderToTransactionState(
        string $orderId,
        SalesChannelContext $context,
        string $transactionState
    ): void {
        $order = $this->getOrder($orderId$context);

        $stateMachineRegistry = $this->getContainer()->get(StateMachineRegistry::class);

        static::assertInstanceOf(OrderTransactionCollection::class$order->getTransactions());

        $orderTransactionEntity = $order->getTransactions()->last();
        static::assertInstanceOf(OrderTransactionEntity::class$orderTransactionEntity);

        $stateMachineRegistry->transition(
            new Transition(
                OrderTransactionDefinition::ENTITY_NAME,
                $orderTransactionEntity->getId(),
                $transactionState,
                'stateId'
            ),
            
$orderEntity = $this->orderRepository->search($criteria$context)
            ->get($orderId);

        return $orderEntity;
    }

    /** * @throws InconsistentCriteriaIdsException */
    private function getPaymentMethodId(OrderEntity $order): ?string
    {
        $transactions = $order->getTransactions();
        if ($transactions === null) {
            throw OrderException::missingAssociation('transactions');
        }

        foreach ($transactions as $transaction) {
            if ($transaction->getStateMachineState() !== null
                && ($transaction->getStateMachineState()->getTechnicalName() === OrderTransactionStates::STATE_CANCELLED
                    || $transaction->getStateMachineState()->getTechnicalName() === OrderTransactionStates::STATE_FAILED)
            ) {
                continue;
            }

            
 $context->getContext());

        /** @var AccountOverviewPageLoadedEvent $event */
        $event = null;
        $this->catchEvent(AccountOverviewPageLoadedEvent::class$event);

        $page = $this->getPageLoader()->load($request$context$this->createCustomer());

        static::assertInstanceOf(AccountOverviewPage::class$page);
        $order = $page->getNewestOrder();
        static::assertInstanceOf(OrderEntity::class$order);
        $transactions = $order->getTransactions();
        static::assertCount(2, $transactions);
        $transaction = $transactions->last();
        static::assertNotNull($transaction);
        static::assertSame(self::LAST_TRANSACTION_ID, $transaction->getId());
        self::assertPageEvent(AccountOverviewPageLoadedEvent::class$event$context$request$page);
    }

    public function testSalesChannelRestriction(): void
    {
        $request = new Request();
        $context = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();
        
$this->paymentMethodChangedCriteriaEventResult = null;
        $this->catchEvent(OrderPaymentMethodChangedCriteriaEvent::class$this->paymentMethodChangedCriteriaEventResult);

        $this->transactionStateEventResult = null;
        $this->catchEvent(StateMachineTransitionEvent::class$this->transactionStateEventResult);
    }

    public function testSetPaymentMethodOwnOrderOtherPaymentMethodOpen(): void
    {
        $this->sendValidRequest($this->ids->get('order-1')$this->getAvailablePaymentMethodId(1));
        $transactions = $this->getTransactions($this->ids->get('order-1'));
        static::assertCount(2, $transactions);
        $firstTransaction = $transactions->first();
        static::assertNotNull($firstTransaction);
        $lastTransaction = $transactions->last();
        static::assertNotNull($lastTransaction);
        static::assertNotSame($firstTransaction->getId()$lastTransaction->getId());

        static::assertNotNull($firstTransaction->getStateMachineState());
        static::assertNotNull($lastTransaction->getStateMachineState());
        static::assertSame('cancelled', $firstTransaction->getStateMachineState()->getTechnicalName());
        static::assertSame('open', $lastTransaction->getStateMachineState()->getTechnicalName());

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