public function testBuildWithSwitchedOffVault()
 {
     $expectedResult = [];
     $buildSubject = [];
     $this->vaultPaymentMock->expects(self::once())->method('isActiveForPayment')->willReturn(false);
     static::assertEquals($expectedResult, $this->builder->build($buildSubject));
 }
Example #2
0
 /**
  * Retrieve assoc array of checkout configuration
  *
  * @return array
  */
 public function getConfig()
 {
     $vaultPayments = [];
     $customerId = $this->session->getCustomerId();
     if (!$customerId) {
         return $vaultPayments;
     }
     $storeId = $this->storeManager->getStore()->getId();
     if (!$this->vaultPayment->isActive($storeId)) {
         return $vaultPayments;
     }
     $vaultProviderCode = $this->vaultPayment->getProviderCode($storeId);
     $componentProvider = $this->getComponentProvider($vaultProviderCode);
     if (null === $componentProvider) {
         return $vaultPayments;
     }
     $filters[] = $this->filterBuilder->setField(PaymentTokenInterface::CUSTOMER_ID)->setValue($customerId)->create();
     $filters[] = $this->filterBuilder->setField(PaymentTokenInterface::IS_VISIBLE)->setValue(1)->create();
     $filters[] = $this->filterBuilder->setField(PaymentTokenInterface::PAYMENT_METHOD_CODE)->setValue($vaultProviderCode)->create();
     $searchCriteria = $this->searchCriteriaBuilder->addFilters($filters)->create();
     foreach ($this->paymentTokenRepository->getList($searchCriteria)->getItems() as $index => $token) {
         $component = $componentProvider->getComponentForToken($token);
         $vaultPayments[VaultPaymentInterface::CODE . '_item_' . $index] = ['config' => $component->getConfig(), 'component' => $component->getName()];
     }
     return ['payment' => [VaultPaymentInterface::CODE => $vaultPayments]];
 }
 /**
  * @return PaymentTokenRepositoryInterface
  */
 private function getInstance()
 {
     if (!$this->vaultPayment->isActive()) {
         return $this->nullRepository;
     }
     $methodCode = $this->config->getValue(VaultProvidersMap::VALUE_CODE);
     return isset($this->repositories[$methodCode]) ? $this->objectManager->get($this->repositories[$methodCode]) : $this->nullRepository;
 }
Example #4
0
 /**
  * @inheritdoc
  */
 public function build(array $buildSubject)
 {
     $result = [];
     $isActiveVaultModule = $this->vaultPayment->isActiveForPayment(ConfigProvider::CODE);
     if ($isActiveVaultModule) {
         $result[self::OPTIONS][self::STORE_IN_VAULT_ON_SUCCESS] = true;
     }
     return $result;
 }
 /**
  * @param int $customerId
  * @param bool $vaultEnabled
  * @dataProvider customerIdProvider
  */
 public function testGetConfig($customerId, $vaultEnabled)
 {
     $storeId = 1;
     $vaultPaymentCode = 'vault_payment';
     $expectedConfiguration = ['vault' => [$vaultPaymentCode => ['is_enabled' => $vaultEnabled]]];
     $this->session->expects(static::once())->method('getCustomerId')->willReturn($customerId);
     $this->storeManager->expects(static::exactly(2))->method('getStore')->willReturn($this->store);
     $this->store->expects(static::exactly(2))->method('getId')->willReturn($storeId);
     $this->paymentDataHelper->expects(static::once())->method('getStoreMethods')->with($storeId)->willReturn([$this->vaultPayment]);
     $this->vaultPayment->expects(static::once())->method('getCode')->willReturn($vaultPaymentCode);
     $this->vaultPayment->expects($customerId !== null ? static::once() : static::never())->method('isActive')->with($storeId)->willReturn($vaultEnabled);
     static::assertEquals($expectedConfiguration, $this->vaultConfigProvider->getConfig());
 }
 /**
  * Returns list of payment tokens for current customer session
  *
  * @return PaymentTokenInterface[]
  */
 public function getCustomerSessionTokens()
 {
     $vaultPayments = [];
     $customerId = $this->session->getCustomerId();
     if (!$customerId) {
         return $vaultPayments;
     }
     $storeId = $this->storeManager->getStore()->getId();
     if (!$this->vaultPayment->isActive($storeId)) {
         return $vaultPayments;
     }
     $providerCode = $this->vaultPayment->getProviderCode($storeId);
     return $this->tokenManagement->getVisibleAvailableTokens($customerId, $providerCode);
 }
 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());
 }
Example #8
0
 /**
  * @inheritdoc
  */
 public function handle(array $handlingSubject, array $response)
 {
     $isActiveVaultModule = $this->vaultPayment->isActiveForPayment(ConfigProvider::CODE);
     if (!$isActiveVaultModule) {
         return;
     }
     $paymentDO = $this->subjectReader->readPayment($handlingSubject);
     $transaction = $this->subjectReader->readTransaction($response);
     $payment = $paymentDO->getPayment();
     // add vault payment token entity to extension attributes
     $paymentToken = $this->getVaultPaymentToken($transaction);
     if (null !== $paymentToken) {
         $extensionAttributes = $this->getExtensionAttributes($payment);
         $extensionAttributes->setVaultPaymentToken($paymentToken);
     }
 }
 /**
  * Get store id for current active vault payment
  * @return int|null
  */
 private function getStoreId()
 {
     $storeId = $this->storeManager->getStore()->getId();
     if (!$this->vaultPayment->isActive($storeId)) {
         return null;
     }
     return $storeId;
 }
 /**
  * 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());
 }
 public function testGetConfigNoActiveVaultProvider()
 {
     $customerId = 1;
     $storeId = 1;
     $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(false);
     $this->paymentTokenRepositoryMock->expects(self::never())->method('getList');
     $configProvider = new TokensConfigProvider($this->customerSessionMock, $this->paymentTokenRepositoryMock, $this->filterBuilderMock, $this->searchCriteriaBuilderMock, $this->storeManager, $this->vaultPayment);
     $config = $configProvider->getConfig();
     self::assertEmpty($config);
 }
 /**
  * @covers \Magento\Vault\Model\Ui\Adminhtml\TokensConfigProvider::getTokensComponents
  */
 public function testGetTokensComponentsEmptyComponentProvider()
 {
     $storeId = 1;
     $customerId = 2;
     $code = 'vault_payment';
     $this->session->expects(static::once())->method('getCustomerId')->willReturn($customerId);
     $this->initStoreMock();
     $this->vaultPayment->expects(static::once())->method('isActive')->with($storeId)->willReturn(true);
     $this->vaultPayment->expects(static::once())->method('getProviderCode')->with($storeId)->willReturn($code);
     $this->paymentTokenRepository->expects(static::never())->method('getList');
     $configProvider = new TokensConfigProvider($this->session, $this->paymentTokenRepository, $this->filterBuilder, $this->searchCriteriaBuilder, $this->storeManager, $this->vaultPayment, $this->dateTimeFactory);
     static::assertEmpty($configProvider->getTokensComponents());
 }
 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());
 }
 /**
  * @covers \Magento\Vault\Model\Ui\Adminhtml\TokensConfigProvider::getTokensComponents
  */
 public function testGetTokensComponentsEmptyComponentProvider()
 {
     $storeId = 1;
     $customerId = 2;
     $vaultPaymentCode = 'vault_payment';
     $this->session->expects(static::once())->method('getCustomerId')->willReturn($customerId);
     $this->initStoreMock();
     $this->paymentDataHelper->expects(static::once())->method('getMethodInstance')->with($vaultPaymentCode)->willReturn($this->vaultPayment);
     $this->vaultPayment->expects(static::once())->method('isActive')->with($storeId)->willReturn(false);
     $this->paymentTokenRepository->expects(static::never())->method('getList');
     $configProvider = new TokensConfigProvider($this->session, $this->paymentTokenRepository, $this->filterBuilder, $this->searchCriteriaBuilder, $this->storeManager, $this->dateTimeFactory);
     $this->objectManager->setBackwardCompatibleProperty($configProvider, 'paymentDataHelper', $this->paymentDataHelper);
     static::assertEmpty($configProvider->getTokensComponents($vaultPaymentCode));
 }
 /**
  * Run test for proxy methods
  */
 public function testProxyCall()
 {
     /** @var SearchCriteria|\PHPUnit_Framework_MockObject_MockObject $searchCriteriaMock */
     $searchCriteriaMock = $this->getMockBuilder(SearchCriteria::class)->getMockForAbstractClass();
     /** @var PaymentTokenSearchResultsInterface|\PHPUnit_Framework_MockObject_MockObject $searchResultMock */
     $searchResultMock = $this->getMockBuilder(PaymentTokenSearchResultsInterface::class)->getMockForAbstractClass();
     /** @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject $tokenMock */
     $tokenMock = $this->getMockBuilder(PaymentTokenInterface::class)->getMockForAbstractClass();
     /** @var PaymentTokenRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject $proxyCallsMock */
     $proxyCallsMock = $this->getMockBuilder(PaymentTokenRepositoryInterface::class)->getMockForAbstractClass();
     $this->vaultPaymentMock->expects(self::once())->method('isActive')->willReturn(1);
     $this->configMock->expects(self::once())->method('getValue')->with(VaultProvidersMap::VALUE_CODE)->willReturn('code');
     $this->objectManagerMock->expects(self::once())->method('get')->with(get_class($proxyCallsMock))->willReturn($proxyCallsMock);
     $proxy = new PaymentTokenRepositoryProxy($this->nullRepositoryMock, $this->vaultPaymentMock, $this->configMock, $this->objectManagerMock, ['code' => get_class($proxyCallsMock)]);
     $proxyCallsMock->expects(self::once())->method('delete')->with($tokenMock)->willReturn(self::DELETE_RESULT);
     $proxyCallsMock->expects(self::once())->method('getById')->with(1)->willReturn($tokenMock);
     $proxyCallsMock->expects(self::once())->method('getList')->with($searchCriteriaMock)->willReturn($searchResultMock);
     $proxyCallsMock->expects(self::once())->method('save')->with($tokenMock)->willReturn(self::SAVE_RESULT);
     self::assertEquals(self::DELETE_RESULT, $proxy->delete($tokenMock));
     self::assertEquals($tokenMock, $proxy->getById(1));
     self::assertEquals($searchResultMock, $proxy->getList($searchCriteriaMock));
     self::assertEquals(self::SAVE_RESULT, $proxy->save($tokenMock));
 }
 /**
  * @covers \Magento\BraintreeTwo\Gateway\Response\VaultDetailsHandler::handle
  */
 public function testHandle()
 {
     $this->vaultPayment->expects(self::once())->method('isActiveForPayment')->willReturn(true);
     $this->paymentExtension->expects(self::once())->method('setVaultPaymentToken')->with($this->paymentToken);
     $this->paymentExtension->expects(self::once())->method('getVaultPaymentToken')->willReturn($this->paymentToken);
     $paymentData = $this->getPaymentDataObjectMock();
     $transaction = $this->getBraintreeTransaction();
     $subject = ['payment' => $paymentData];
     $response = ['object' => $transaction];
     $this->subjectReader->expects(self::once())->method('readPayment')->with($subject)->willReturn($paymentData);
     $this->subjectReader->expects(self::once())->method('readTransaction')->with($response)->willReturn($transaction);
     $this->paymentToken->expects(static::once())->method('setGatewayToken')->with('rh3gd4');
     $this->paymentHandler->handle($subject, $response);
     $this->assertSame($this->paymentToken, $this->payment->getExtensionAttributes()->getVaultPaymentToken());
 }
 /**
  * Check if vault enabled
  * @return bool
  */
 public function isVaultEnabled()
 {
     return $this->vaultService->isActiveForPayment(ConfigProvider::CODE);
 }
Example #19
0
 public function testIsVaultEnabled()
 {
     $this->vaultService->expects(static::once())->method('isActiveForPayment')->with(ConfigProvider::CODE)->willReturn(true);
     static::assertTrue($this->block->isVaultEnabled());
 }
 /**
  * Retrieve assoc array of checkout configuration
  *
  * @return array
  */
 public function getConfig()
 {
     $storeId = $this->storeManager->getStore()->getId();
     $customerId = $this->session->getCustomerId();
     return [VaultPaymentInterface::CODE => ['vault_provider_code' => $this->vault->getProviderCode($storeId), 'is_enabled' => $customerId !== null && $this->vault->isActive($storeId)]];
 }
Example #21
0
 /**
  * Check if vault enabled
  * @return bool
  */
 public function isVaultEnabled()
 {
     return $this->vaultService->isActiveForPayment(\Magento\Paypal\Model\Config::METHOD_PAYFLOWPRO);
 }