resourceModel = $resourceModel; $this->paymentTokenFactory = $paymentTokenFactory; $this->filterBuilder = $filterBuilder; $this->searchCriteriaBuilder = $searchCriteriaBuilder; $this->searchResultsFactory = $searchResultsFactory; $this->collectionFactory = $collectionFactory; $this->collectionProcessor = $collectionProcessor ?: $this->getCollectionProcessor(); } /** * Lists payment tokens that match specified search criteria. * * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria The search criteria. * @return \Magento\Vault\Api\Data\PaymentTokenSearchResultsInterface Payment token search result interface. */ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) { /** @var \Magento\Vault\Model\ResourceModel\PaymentToken\Collection $collection */ $collection = $this->collectionFactory->create(); $this->collectionProcessor->process($searchCriteria, $collection); /** @var \Magento\Vault\Api\Data\PaymentTokenSearchResultsInterface $searchResults */ $searchResults = $this->searchResultsFactory->create(); $searchResults->setSearchCriteria($searchCriteria); $searchResults->setItems($collection->getItems()); $searchResults->setTotalCount($collection->getSize()); return $searchResults; } /** * Loads a specified payment token. * * @param int $entityId The payment token entity ID. * @return \Magento\Vault\Api\Data\PaymentTokenInterface Payment token interface. */ public function getById($entityId) { $tokenModel = $this->paymentTokenFactory->create(); $this->resourceModel->load($tokenModel, $entityId); return $tokenModel; } /** * Deletes a specified payment token. * * @param \Magento\Vault\Api\Data\PaymentTokenInterface $paymentToken The invoice. * @return bool */ public function delete(Data\PaymentTokenInterface $paymentToken) { /** @var PaymentToken $tokenModel */ $tokenModel = $this->getById($paymentToken->getEntityId()); if (empty($tokenModel->getPublicHash())) { return false; } $tokenModel->setIsActive(false); $tokenModel->setIsVisible(false); $tokenModel->save(); return true; } /** * Performs persist operations for a specified payment token. * * @param \Magento\Vault\Api\Data\PaymentTokenInterface $paymentToken The payment token. * @return \Magento\Vault\Api\Data\PaymentTokenInterface Saved payment token data. */ public function save(Data\PaymentTokenInterface $paymentToken) { /** @var PaymentToken $paymentToken */ $this->resourceModel->save($paymentToken); return $paymentToken; } /** * Helper function that adds a FilterGroup to the collection. * * @param FilterGroup $filterGroup * @param Collection $collection * @return void * @deprecated 101.0.0 * @throws \Magento\Framework\Exception\InputException */ protected function addFilterGroupToCollection(FilterGroup $filterGroup, Collection $collection) { foreach ($filterGroup->getFilters() as $filter) { $condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq'; $collection->addFieldToFilter($filter->getField(), [$condition => $filter->getValue()]); } } /** * Retrieve collection processor * * @deprecated 101.0.0 * @return CollectionProcessorInterface */ private function getCollectionProcessor() { if (!$this->collectionProcessor) { $this->collectionProcessor = \Magento\Framework\App\ObjectManager::getInstance()->get( \Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface::class ); } return $this->collectionProcessor; } }