-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathPayPalPaymentMethodProvider.php
More file actions
45 lines (36 loc) · 1.5 KB
/
PayPalPaymentMethodProvider.php
File metadata and controls
45 lines (36 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\PayPalPlugin\Provider;
use Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface;
use Sylius\Component\Core\Model\PaymentMethodInterface;
use Sylius\Component\Core\Repository\PaymentMethodRepositoryInterface;
use Sylius\PayPalPlugin\DependencyInjection\SyliusPayPalExtension;
use Sylius\PayPalPlugin\Exception\PayPalPaymentMethodNotFoundException;
final readonly class PayPalPaymentMethodProvider implements PayPalPaymentMethodProviderInterface
{
/** @param PaymentMethodRepositoryInterface<PaymentMethodInterface> $paymentMethodRepository */
public function __construct(private PaymentMethodRepositoryInterface $paymentMethodRepository)
{
}
public function provide(): PaymentMethodInterface
{
$paymentMethods = $this->paymentMethodRepository->findBy(['enabled' => true]);
/** @var PaymentMethodInterface $paymentMethod */
foreach ($paymentMethods as $paymentMethod) {
/** @var GatewayConfigInterface $gatewayConfig */
$gatewayConfig = $paymentMethod->getGatewayConfig();
if ($gatewayConfig->getFactoryName() === SyliusPayPalExtension::PAYPAL_FACTORY_NAME) {
return $paymentMethod;
}
}
throw new PayPalPaymentMethodNotFoundException();
}
}