diff --git a/src/Mollie_HyvaCheckout/Service/Vault/GetSavedCards.php b/src/Mollie_HyvaCheckout/Service/Vault/GetSavedCards.php
index 7d8bf82..e75bdc2 100644
--- a/src/Mollie_HyvaCheckout/Service/Vault/GetSavedCards.php
+++ b/src/Mollie_HyvaCheckout/Service/Vault/GetSavedCards.php
@@ -8,8 +8,10 @@
namespace Mollie\HyvaCheckout\Service\Vault;
+use Magento\Customer\Model\Session;
use Magento\Framework\Api\SearchCriteriaBuilderFactory;
use Magento\Framework\Serialize\SerializerInterface;
+use Magento\Vault\Api\Data\PaymentTokenInterface;
use Magento\Vault\Api\PaymentTokenRepositoryInterface;
class GetSavedCards
@@ -17,15 +19,18 @@ class GetSavedCards
private SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory;
private PaymentTokenRepositoryInterface $paymentTokenRepository;
private SerializerInterface $serializer;
+ private Session $customerSession;
public function __construct(
SearchCriteriaBuilderFactory $searchCriteriaBuilderFactory,
PaymentTokenRepositoryInterface $paymentTokenRepository,
- SerializerInterface $serializer
+ SerializerInterface $serializer,
+ Session $customerSession
) {
$this->searchCriteriaBuilderFactory = $searchCriteriaBuilderFactory;
$this->paymentTokenRepository = $paymentTokenRepository;
$this->serializer = $serializer;
+ $this->customerSession = $customerSession;
}
/**
@@ -40,8 +45,15 @@ public function __construct(
*/
public function execute(): array
{
+ if (!$this->customerSession->isLoggedIn()) {
+ return [];
+ }
+
$search = $this->searchCriteriaBuilderFactory->create();
- $search->addFilter('payment_method_code', 'mollie_methods_creditcard');
+ $search->addFilter(PaymentTokenInterface::IS_VISIBLE, 1);
+ $search->addFilter(PaymentTokenInterface::IS_ACTIVE, 1);
+ $search->addFilter(PaymentTokenInterface::CUSTOMER_ID, $this->customerSession->getCustomerId());
+ $search->addFilter(PaymentTokenInterface::PAYMENT_METHOD_CODE, 'mollie_methods_creditcard');
$output = [];
$items = $this->paymentTokenRepository->getList($search->create())->getItems();
diff --git a/src/Mollie_HyvaCheckout/etc/di.xml b/src/Mollie_HyvaCheckout/etc/di.xml
index 7ee96b7..6bb6328 100644
--- a/src/Mollie_HyvaCheckout/etc/di.xml
+++ b/src/Mollie_HyvaCheckout/etc/di.xml
@@ -16,6 +16,12 @@
+
+
+ Magento\Customer\Model\Session\Proxy
+
+
+