Skip to content

Commit

Permalink
Merge pull request #20 from michielgerritsen/release
Browse files Browse the repository at this point in the history
Bugfix: Only show active cards
  • Loading branch information
Marvin-Magmodules authored Mar 6, 2024
2 parents c1a3e12 + 5a4efe0 commit c791260
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Mollie_HyvaCheckout/Service/Vault/GetSavedCards.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,29 @@

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
{
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;
}

/**
Expand All @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions src/Mollie_HyvaCheckout/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
</arguments>
</type>

<type name="Mollie\HyvaCheckout\Service\Vault\GetSavedCards">
<arguments>
<argument name="customerSession" xsi:type="object">Magento\Customer\Model\Session\Proxy</argument>
</arguments>
</type>

<virtualType name="Mollie\HyvaCheckout\Magewire\Checkout\Payment\Method\Ideal"
type="Mollie\HyvaCheckout\Magewire\Checkout\Payment\Method\WithIssuer"
>
Expand Down

0 comments on commit c791260

Please sign in to comment.