-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PAYOSWXP-158: Add PayPal v2 payment methods
- Loading branch information
1 parent
38b2173
commit bcfb143
Showing
50 changed files
with
1,973 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PayonePayment\Components\Helper; | ||
|
||
use Psr\Cache\CacheItemPoolInterface; | ||
use Shopware\Core\Framework\Context; | ||
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\ContainsFilter; | ||
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter; | ||
use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepository; | ||
use Shopware\Core\System\SalesChannel\SalesChannelContext; | ||
|
||
class ActivePaymentMethodsLoader implements ActivePaymentMethodsLoaderInterface | ||
{ | ||
public function __construct( | ||
private readonly CacheItemPoolInterface $cachePool, | ||
private readonly SalesChannelRepository $paymentMethodRepository, | ||
private readonly EntityRepository $salesChannelRepository | ||
) { | ||
} | ||
|
||
public function getActivePaymentMethodIds(SalesChannelContext $salesChannelContext): array | ||
{ | ||
$cacheKey = $this->generateCacheKey($salesChannelContext->getSalesChannelId()); | ||
|
||
$activePaymentMethods = $this->cachePool->getItem($cacheKey); | ||
|
||
if ($activePaymentMethods->get() === null) { | ||
$activePaymentMethods->set( | ||
$this->collectActivePayonePaymentMethodIds( | ||
$salesChannelContext | ||
) | ||
); | ||
|
||
$this->cachePool->save($activePaymentMethods); | ||
} | ||
|
||
return $activePaymentMethods->get(); | ||
} | ||
|
||
public function clearCache(Context $context): void | ||
{ | ||
$cacheKeys = []; | ||
|
||
/** @var string[] $salesChannelIds */ | ||
$salesChannelIds = $this->salesChannelRepository->searchIds(new Criteria(), $context)->getIds(); | ||
|
||
foreach ($salesChannelIds as $salesChannelId) { | ||
$cacheKeys[] = $this->generateCacheKey($salesChannelId); | ||
} | ||
|
||
if ($cacheKeys === []) { | ||
return; | ||
} | ||
|
||
$this->cachePool->deleteItems($cacheKeys); | ||
} | ||
|
||
private function collectActivePayonePaymentMethodIds(SalesChannelContext $salesChannelContext): array | ||
{ | ||
$criteria = new Criteria(); | ||
|
||
$criteria->addFilter(new ContainsFilter('handlerIdentifier', 'PayonePayment')); | ||
$criteria->addFilter(new EqualsFilter('active', true)); | ||
|
||
return $this->paymentMethodRepository->searchIds($criteria, $salesChannelContext)->getIds(); | ||
} | ||
|
||
private function generateCacheKey(string $salesChannelId): string | ||
{ | ||
return 'payone_payment.active_payment_methods.' . $salesChannelId; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Components/Helper/ActivePaymentMethodsLoaderInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PayonePayment\Components\Helper; | ||
|
||
use Shopware\Core\Framework\Context; | ||
use Shopware\Core\System\SalesChannel\SalesChannelContext; | ||
|
||
interface ActivePaymentMethodsLoaderInterface | ||
{ | ||
public function getActivePaymentMethodIds(SalesChannelContext $salesChannelContext): array; | ||
|
||
public function clearCache(Context $context): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.