SyncPaymentTransactionStruct example

$order->setId(Uuid::randomHex());
        $order->setTransactions(new OrderTransactionCollection([$transaction]));
        $context = Generator::createSalesChannelContext();
        $requestDataBag = new RequestDataBag();

        $eventDispatcher = $this->createMock(EventDispatcherInterface::class);
        $eventDispatcher->expects(static::once())->method('dispatch')->with(static::isInstanceOf(PayPaymentOrderCriteriaEvent::class));

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

        

#[Package('checkout')] class SyncPaymentTransactionStructTest extends TestCase
{
    public function testGetters(): void
    {
        $transaction = new OrderTransactionEntity();
        $order = new OrderEntity();
        $recurring = new RecurringDataStruct('foo', new \DateTime());

        $struct = new SyncPaymentTransactionStruct($transaction$order$recurring);

        static::assertSame($transaction$struct->getOrderTransaction());
        static::assertSame($order$struct->getOrder());
        static::assertSame($recurring$struct->getRecurring());
        static::assertTrue($struct->isRecurring());
    }
}
#[Package('checkout')] class PaymentTransactionStructFactory extends AbstractPaymentTransactionStructFactory
{
    public function getDecorated(): AbstractPaymentTransactionStructFactory
    {
        throw new DecorationPatternException(self::class);
    }

    public function sync(OrderTransactionEntity $orderTransaction, OrderEntity $order): SyncPaymentTransactionStruct
    {
        return new SyncPaymentTransactionStruct($orderTransaction$order);
    }

    public function async(OrderTransactionEntity $orderTransaction, OrderEntity $order, string $returnUrl): AsyncPaymentTransactionStruct
    {
        return new AsyncPaymentTransactionStruct($orderTransaction$order$returnUrl);
    }

    public function prepared(OrderTransactionEntity $orderTransaction, OrderEntity $order): PreparedPaymentTransactionStruct
    {
        return new PreparedPaymentTransactionStruct($orderTransaction$order);
    }

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