public function testGetCustomerSessionTokens() { $customerId = 1; $token = $this->getMock(PaymentTokenInterface::class); $expectation = [$token]; $this->customerSession->expects(static::once())->method('getCustomerId')->willReturn($customerId); $this->paymentTokenManagement->expects(static::once())->method('getVisibleAvailableTokens')->with($customerId)->willReturn($expectation); static::assertEquals($expectation, $this->tokenManagement->getCustomerSessionTokens()); }
public function testGetCustomerSessionTokens() { $customerId = 1; $providerCode = 'vault_provider'; $storeId = 1; $token = $this->getMock(PaymentTokenInterface::class); $expectation = [$token]; $this->customerSessionMock->expects(self::once())->method('getCustomerId')->willReturn($customerId); $this->storeManager->expects(static::once())->method('getStore')->with(null)->willReturn($this->store); $this->store->expects(static::once())->method('getId')->willReturn($storeId); $this->vaultPayment->expects(static::once())->method('isActive')->with($storeId)->willReturn(true); $this->vaultPayment->expects(static::once())->method('getProviderCode')->with($storeId)->willReturn($providerCode); $this->paymentTokenManagementMock->expects(static::once())->method('getVisibleAvailableTokens')->with($customerId, $providerCode)->willReturn($expectation); static::assertEquals($expectation, $this->tokenManagement->getCustomerSessionTokens()); }
/** * Retrieve assoc array of checkout configuration * * @return array */ public function getConfig() { $vaultPayments = []; $storeId = $this->storeManager->getStore()->getId(); if (!$this->vaultPayment->isActive($storeId)) { return $vaultPayments; } $providerCode = $this->vaultPayment->getProviderCode($storeId); $componentProvider = $this->getComponentProvider($providerCode); if (null === $componentProvider) { return $vaultPayments; } foreach ($this->customerTokenManagement->getCustomerSessionTokens() as $i => $token) { $component = $componentProvider->getComponentForToken($token); $vaultPayments[VaultPaymentInterface::CODE . '_item_' . $i] = ['config' => $component->getConfig(), 'component' => $component->getName()]; } return ['payment' => [VaultPaymentInterface::CODE => $vaultPayments]]; }
public function testGetConfig() { $storeId = 1; $vaultProviderCode = 'vault_provider_code'; $expectedConfig = ['payment' => [VaultPaymentInterface::CODE => [VaultPaymentInterface::CODE . '_item_' . '0' => ['config' => ['token_code' => 'code'], 'component' => 'Vendor_Module/js/vault_component']]]]; $tokenMock = $this->getMockBuilder(PaymentTokenInterface::class)->getMockForAbstractClass(); $tokenUiComponentProvider = $this->getMock(TokenUiComponentProviderInterface::class); $tokenUiComponent = $this->getMock(TokenUiComponentInterface::class); $this->vaultPayment->expects(static::once())->method('getProviderCode')->with($storeId)->willReturn($vaultProviderCode); $this->storeManager->expects(static::once())->method('getStore')->with(null)->willReturn($this->store); $this->store->expects(static::once())->method('getId')->willReturn($storeId); $this->vaultPayment->expects(static::once())->method('isActive')->with($storeId)->willReturn(true); $this->customerTokenManagement->expects(self::once())->method('getCustomerSessionTokens')->willReturn([$tokenMock]); $tokenUiComponentProvider->expects(static::once())->method('getComponentForToken')->with($tokenMock)->willReturn($tokenUiComponent); $tokenUiComponent->expects(static::once())->method('getConfig')->willReturn(['token_code' => 'code']); $tokenUiComponent->expects(static::once())->method('getName')->willReturn('Vendor_Module/js/vault_component'); $configProvider = new TokensConfigProvider($this->storeManager, $this->vaultPayment, $this->customerTokenManagement, [$vaultProviderCode => $tokenUiComponentProvider]); static::assertEquals($expectedConfig, $configProvider->getConfig()); }
/** * Retrieve assoc array of checkout configuration * * @return array */ public function getConfig() { $vaultPayments = []; $providers = $this->getComponentProviders(); if (empty($providers)) { return $vaultPayments; } $tokens = $this->customerTokenManagement->getCustomerSessionTokens(); foreach ($tokens as $i => $token) { $paymentCode = $token->getPaymentMethodCode(); if (!isset($providers[$paymentCode])) { continue; } $componentProvider = $providers[$paymentCode]; $component = $componentProvider->getComponentForToken($token); $vaultPayments[$paymentCode . '_item_' . $i] = ['config' => $component->getConfig(), 'component' => $component->getName()]; } return ['payment' => [self::$vaultCode => $vaultPayments]]; }
public function testGetConfig() { $storeId = 1; $vaultProviderCode = 'vault_provider_code'; $expectedConfig = ['payment' => ['vault' => [$vaultProviderCode . '_item_' . '0' => ['config' => ['token_code' => 'code'], 'component' => 'Vendor_Module/js/vault_component']]]]; $token = $this->getMockForAbstractClass(PaymentTokenInterface::class); $tokenUiComponentProvider = $this->getMockForAbstractClass(TokenUiComponentProviderInterface::class); $tokenUiComponent = $this->getMockForAbstractClass(TokenUiComponentInterface::class); $this->storeManager->expects(static::once())->method('getStore')->willReturn($this->store); $this->store->expects(static::once())->method('getId')->willReturn($storeId); $this->paymentDataHelper->expects(static::once())->method('getStoreMethods')->with($storeId)->willReturn([$this->vaultPayment]); $this->vaultPayment->expects(static::once())->method('isActive')->with($storeId)->willReturn(true); $this->vaultPayment->expects(static::once())->method('getProviderCode')->willReturn($vaultProviderCode); $this->customerTokenManagement->expects(static::once())->method('getCustomerSessionTokens')->willReturn([$token]); $token->expects(static::once())->method('getPaymentMethodCode')->willReturn($vaultProviderCode); $tokenUiComponentProvider->expects(static::once())->method('getComponentForToken')->with($token)->willReturn($tokenUiComponent); $tokenUiComponent->expects(static::once())->method('getConfig')->willReturn(['token_code' => 'code']); $tokenUiComponent->expects(static::once())->method('getName')->willReturn('Vendor_Module/js/vault_component'); $configProvider = new TokensConfigProvider($this->storeManager, $this->customerTokenManagement, [$vaultProviderCode => $tokenUiComponentProvider]); $this->objectManager->setBackwardCompatibleProperty($configProvider, 'paymentDataHelper', $this->paymentDataHelper); static::assertEquals($expectedConfig, $configProvider->getConfig()); }
/** * @return PaymentTokenInterface[] */ public function getPaymentTokens() { return $this->customerTokenManagement->getCustomerSessionTokens(); }