PaymentMethodCollection example



    public function getGroups(): CustomerGroupCollection
    {
        return new CustomerGroupCollection(
            $this->fmap(fn (CustomerEntity $customer) => $customer->getGroup())
        );
    }

    public function getDefaultPaymentMethods(): PaymentMethodCollection
    {
        return new PaymentMethodCollection(
            $this->fmap(fn (CustomerEntity $customer) => $customer->getDefaultPaymentMethod())
        );
    }

    public function getSalesChannels(): SalesChannelCollection
    {
        return new SalesChannelCollection(
            $this->fmap(fn (CustomerEntity $customer) => $customer->getSalesChannel())
        );
    }

    
new PaymentMethodEntity(),
            new ShippingMethodEntity(),
            new ShippingLocation(new CountryEntity(), null, null),
            new CustomerEntity(),
            new CashRoundingConfig(1, 1.1, true),
            new CashRoundingConfig(1, 1.1, true)
        );
        $this->response = new PaymentMethodRouteResponse(
            new EntitySearchResult(
                'entity',
                1,
                new PaymentMethodCollection(),
                null,
                new Criteria(),
                Context::createDefaultContext()
            )
        );

        $this->cachedRoute = new CachedPaymentMethodRoute(
            $this->decorated,
            $this->cache,
            $this->createMock(EntityCacheKeyGenerator::class),
            $this->createMock(AbstractCacheTracer::class),
            
$page = $checkoutConfirmPageLoader->load(
            new Request(),
            $this->getContextWithDummyCustomer()
        );

        static::assertInstanceOf(CheckoutConfirmPage::class$page);
        static::assertNull($page->getMetaInformation());
    }

    public function testPaymentAndShippingMethodsAreSetToPage(): void
    {
        $paymentMethods = new PaymentMethodCollection([
            (new PaymentMethodEntity())->assign(['_uniqueIdentifier' => Uuid::randomHex()]),
            (new PaymentMethodEntity())->assign(['_uniqueIdentifier' => Uuid::randomHex()]),
        ]);

        $shippingMethods = new ShippingMethodCollection([
            (new ShippingMethodEntity())->assign(['_uniqueIdentifier' => Uuid::randomHex()]),
            (new ShippingMethodEntity())->assign(['_uniqueIdentifier' => Uuid::randomHex()]),
        ]);

        $paymentMethodResponse = new PaymentMethodRouteResponse(
            new EntitySearchResult(
                
'paymentMethods' => [
                $additionalPaymentMethod,
            ],
        ]]$defaultContext);

        $criteria = new Criteria([$rule[0]['id']]);
        $criteria->addAssociation('paymentMethods');

        $searchedRule = $this->ruleRepository->search($criteria$defaultContext)->getEntities()->first();
        static::assertNotNull($searchedRule);

        static::assertCount(2, $searchedRule->getPaymentMethods() ?? new PaymentMethodCollection());
    }

    public function testIfRuleWithAssocCanNotBeRemoved(): void
    {
        $defaultContext = Context::createDefaultContext();
        $rule = $this->createSimpleRule();
        $this->ruleRepository->create($rule$defaultContext);

        static::expectException(RestrictDeleteViolationException::class);
        $this->ruleRepository->delete([['id' => $rule[0]['id']]]$defaultContext);
    }

    

class BlockedPaymentMethodSwitcherTest extends TestCase
{
    private PaymentMethodCollection $paymentMethodCollection;

    private SalesChannelContext $salesChannelContext;

    private BlockedPaymentMethodSwitcher $switcher;

    protected function setUp(): void
    {
        $this->paymentMethodCollection = new PaymentMethodCollection([
            (new PaymentMethodEntity())->assign([
                'id' => 'original-payment-method-id',
                'name' => 'original-payment-method-name',
                'translated' => ['name' => 'original-payment-method-name'],
            ]),
            (new PaymentMethodEntity())->assign([
                'id' => 'any-other-payment-method-id',
                'name' => 'any-other-payment-method-name',
                'translated' => ['name' => 'any-other-payment-method-name'],
            ]),
            (new PaymentMethodEntity())->assign([
                
array $entitySearchResult,
        ?string $exceptionMessage = null
    ): void {
        if ($exceptionMessage !== null) {
            static::expectExceptionMessage($exceptionMessage);
        }

        $currencyRepository = new StaticEntityRepository([new CurrencyCollection($entitySearchResult[CurrencyDefinition::ENTITY_NAME] ?? [])]);
        $customerGroupRepository = new StaticEntityRepository([new CustomerGroupCollection($entitySearchResult[CustomerGroupDefinition::ENTITY_NAME] ?? [])]);
        $countryRepository = new StaticEntityRepository([new CountryCollection($entitySearchResult[CountryDefinition::ENTITY_NAME] ?? [])]);
        $taxRepository = new StaticEntityRepository([new TaxCollection($entitySearchResult[TaxDefinition::ENTITY_NAME] ?? [])]);
        $paymentMethodRepository = new StaticEntityRepository([new PaymentMethodCollection($entitySearchResult[PaymentMethodDefinition::ENTITY_NAME] ?? [])]);
        $shippingMethodRepository = new StaticEntityRepository([new ShippingMethodCollection($entitySearchResult[ShippingMethodDefinition::ENTITY_NAME] ?? [])]);
        $salesChannelRepository = new StaticEntityRepository([new SalesChannelCollection($entitySearchResult[SalesChannelDefinition::ENTITY_NAME] ?? [])]);
        $countryStateRepository = new StaticEntityRepository([new CountryStateCollection($entitySearchResult[CountryStateDefinition::ENTITY_NAME] ?? [])]);
        $currencyCountryRepository = new StaticEntityRepository([new CurrencyCountryRoundingCollection($entitySearchResult[CurrencyCountryRoundingDefinition::ENTITY_NAME] ?? [])]);

        $connection = $this->createMock(Connection::class);
        $connection->expects(static::once())->method('fetchAssociative')->willReturn($fetchDataResult);

        if ($fetchDataResult === false) {
            $connection->expects(static::never())->method('createQueryBuilder');
        }

        
$paymentMethod,
            new ShippingMethodEntity(),
            new ShippingLocation(new CountryEntity(), null, null),
            new CustomerEntity(),
            new CashRoundingConfig(1, 1.1, true),
            new CashRoundingConfig(1, 1.1, true),
        );
        $this->response = new PaymentMethodRouteResponse(
            new EntitySearchResult(
                'entity',
                1,
                new PaymentMethodCollection([$paymentMethod]),
                null,
                new Criteria(),
                Context::createDefaultContext()
            )
        );
        $this->sortedRoute = new SortedPaymentMethodRoute($this->decorated, $this->executor);
    }

    public function testTriggersScriptHookExecution(): void
    {
        $this->decorated
            
Home | Imprint | This part of the site doesn't use cookies.