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