|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file has been created by developers from BitBag. |
|
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
|
6
|
|
|
* another great project. |
|
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
|
8
|
|
|
* an email on [email protected]. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
declare(strict_types=1); |
|
12
|
|
|
|
|
13
|
|
|
namespace BitBag\SyliusMolliePlugin\Resolver; |
|
14
|
|
|
|
|
15
|
|
|
use BitBag\SyliusMolliePlugin\Entity\MollieGatewayConfigInterface; |
|
16
|
|
|
|
|
17
|
|
|
final class MollieCountriesRestrictionResolver implements MollieCountriesRestrictionResolverInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var MolliePaymentMethodImageResolverInterface */ |
|
20
|
|
|
private $imageResolver; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct(MolliePaymentMethodImageResolverInterface $imageResolver) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->imageResolver = $imageResolver; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function resolve(MollieGatewayConfigInterface $paymentMethod, array $methods, string $countryCode): ?array |
|
28
|
|
|
{ |
|
29
|
|
|
if ($paymentMethod->getCountryRestriction() === MollieGatewayConfigInterface::ALL_COUNTRIES) { |
|
30
|
|
|
return $this->excludeCountryLevel($paymentMethod, $methods, $countryCode); |
|
31
|
|
|
} |
|
32
|
|
|
if ($paymentMethod->getCountryRestriction() === MollieGatewayConfigInterface::SELECTED_COUNTRIES) { |
|
33
|
|
|
return $this->allowCountryLevel($paymentMethod, $methods, $countryCode); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
return $methods; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
private function allowCountryLevel(MollieGatewayConfigInterface $paymentMethod, array $methods, string $countryCode): array |
|
40
|
|
|
{ |
|
41
|
|
|
if (is_array($paymentMethod->getCountryLevelAllowed()) && |
|
42
|
|
|
in_array($countryCode, $paymentMethod->getCountryLevelAllowed())) { |
|
43
|
|
|
return $this->setData($methods, $paymentMethod); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return $methods; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
private function excludeCountryLevel(MollieGatewayConfigInterface $paymentMethod, array $methods, string $countryCode): array |
|
50
|
|
|
{ |
|
51
|
|
|
if (is_array($paymentMethod->getCountryLevelExcluded()) && |
|
52
|
|
|
in_array($countryCode, $paymentMethod->getCountryLevelExcluded())) { |
|
53
|
|
|
return $methods; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return $this->setData($methods, $paymentMethod); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
private function setData(array $methods, MollieGatewayConfigInterface $paymentMethod): array |
|
60
|
|
|
{ |
|
61
|
|
|
$methods['data'][$paymentMethod->getName()] = $paymentMethod->getMethodId(); |
|
|
|
|
|
|
62
|
|
|
$methods['image'][$paymentMethod->getMethodId()] = $this->imageResolver->resolve($paymentMethod); |
|
63
|
|
|
$methods['issuers'][$paymentMethod->getMethodId()] = $paymentMethod->getIssuers(); |
|
64
|
|
|
$methods['paymentFee'][$paymentMethod->getMethodId()] = $paymentMethod->getPaymentSurchargeFee()->getType() |
|
65
|
|
|
? $paymentMethod->getPaymentSurchargeFee() : []; |
|
66
|
|
|
|
|
67
|
|
|
return $methods; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|