/** * Returns list of payment tokens for current customer session * * @return PaymentTokenInterface[] */ public function getCustomerSessionTokens() { $vaultPayments = []; $customerId = $this->session->getCustomerId(); if (!$customerId) { return $vaultPayments; } return $this->tokenManagement->getVisibleAvailableTokens($customerId); }
/** * 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 testGetVisibleAvailableTokens() { $customerId = 1; $searchCriteria = $this->getMockBuilder(SearchCriteria::class)->disableOriginalConstructor()->getMock(); $searchResult = $this->getMockForAbstractClass(PaymentTokenSearchResultsInterface::class); $token = $this->getMockForAbstractClass(PaymentTokenInterface::class); $customerFilter = $this->createExpectedFilter(PaymentTokenInterface::CUSTOMER_ID, $customerId, 0); $visibilityFilter = $this->createExpectedFilter(PaymentTokenInterface::IS_VISIBLE, true, 1); $isActiveFilter = $this->createExpectedFilter(PaymentTokenInterface::IS_ACTIVE, true, 2); // express at expectations $expiresAtFilter = $this->createExpectedFilter(PaymentTokenInterface::EXPIRES_AT, '2015-01-01 00:00:00', 3); $this->filterBuilder->expects(static::once())->method('setConditionType')->with('gt')->willReturnSelf(); $date = $this->getMockBuilder('DateTime')->disableOriginalConstructor()->getMock(); $this->dateTimeFactory->expects(static::once())->method('create')->with("now", new \DateTimeZone('UTC'))->willReturn($date); $date->expects(static::once())->method('format')->with('Y-m-d 00:00:00')->willReturn('2015-01-01 00:00:00'); $this->searchCriteriaBuilder->expects(self::once())->method('addFilters')->with([$customerFilter, $visibilityFilter, $isActiveFilter, $expiresAtFilter])->willReturnSelf(); $this->searchCriteriaBuilder->expects(self::once())->method('create')->willReturn($searchCriteria); $this->paymentTokenRepository->expects(self::once())->method('getList')->with($searchCriteria)->willReturn($searchResult); $searchResult->expects(self::once())->method('getItems')->willReturn([$token]); static::assertEquals([$token], $this->paymentTokenManagement->getVisibleAvailableTokens($customerId)); }