-
Notifications
You must be signed in to change notification settings - Fork 20
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 (#331)
* PAYOSWXP-158: Add PayPal v2 payment methods * PAYOSWXP-158: Add keys to service arguments * PAYOSWXP-158: Add check for missing options * PAYOSWXP-158: Set 'commit' parameter of paypal script to 'false' * PAYOSWXP-158: Simplify the tests * PAYOSWXP-158: Fix creation of query string * PAYOSWXP-158: Remove 'v2' from name and description and add it to 'distinguishableName' via subscriber * PAYOSWXP-158: Improve customer registration process * PAYOSWXP-158: make methods more abstract (#341) * PAYOSWXP-158: Fix check for redirectUrl * PAYOSWXP-158: Improve address validation * PAYOSWXP-158: Fix extended class * PAYOSWXP-158: Improve logging of address violations * PAYOSWXP-158: Hide PayPal v1 if v2 is active --------- Co-authored-by: Frederik Rommel <[email protected]> Co-authored-by: Frederik Rommel <[email protected]>
- Loading branch information
1 parent
f3a0ada
commit b535f27
Showing
51 changed files
with
2,067 additions
and
282 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,72 @@ | ||
<?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()); | ||
|
||
$cacheItem = $this->cachePool->getItem($cacheKey); | ||
|
||
if ($cacheItem->get() === null) { | ||
$cacheItem->set($this->collectActivePayonePaymentMethodIds($salesChannelContext)); | ||
|
||
$this->cachePool->save($cacheItem); | ||
} | ||
|
||
return $cacheItem->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; | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Components/PaymentFilter/PaypalPaymentMethodFilter.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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PayonePayment\Components\PaymentFilter; | ||
|
||
use PayonePayment\Components\PaymentFilter\Exception\PaymentMethodNotAllowedException; | ||
use PayonePayment\PaymentMethod\PayonePaypal; | ||
use PayonePayment\PaymentMethod\PayonePaypalV2; | ||
use Shopware\Core\Checkout\Payment\PaymentMethodCollection; | ||
use Shopware\Core\Checkout\Payment\PaymentMethodEntity; | ||
|
||
class PaypalPaymentMethodFilter extends DefaultPaymentFilterService | ||
{ | ||
protected function additionalChecks(PaymentMethodCollection $methodCollection, PaymentFilterContext $filterContext): void | ||
{ | ||
$paypalV1 = $methodCollection->get(PayonePaypal::UUID); | ||
$paypalV2 = $methodCollection->get(PayonePaypalV2::UUID); | ||
|
||
if ($paypalV1 instanceof PaymentMethodEntity && $paypalV2 instanceof PaymentMethodEntity) { | ||
throw new PaymentMethodNotAllowedException('PayPal: PayPal v1 is not allowed if v2 is active.'); | ||
} | ||
} | ||
} |
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.