|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* MIT License |
|
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace SprykerEco\Zed\Computop\Business\Payment; |
|
9
|
|
|
|
|
10
|
|
|
use ArrayObject; |
|
11
|
|
|
use Generated\Shared\Transfer\PaymentMethodsTransfer; |
|
|
|
|
|
|
12
|
|
|
use Generated\Shared\Transfer\PaymentMethodTransfer; |
|
|
|
|
|
|
13
|
|
|
use Generated\Shared\Transfer\QuoteTransfer; |
|
|
|
|
|
|
14
|
|
|
use SprykerEco\Zed\Computop\ComputopConfig; |
|
15
|
|
|
|
|
16
|
|
|
class PaymentMethodByCurrencyFilter implements PaymentMethodFilterInterface |
|
17
|
|
|
{ |
|
18
|
|
|
protected const COMPUTOP_PAYMENT_METHOD = 'computop'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var \SprykerEco\Zed\Computop\ComputopConfig |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $config; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param \SprykerEco\Zed\Computop\ComputopConfig $config |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(ComputopConfig $config) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->config = $config; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param \Generated\Shared\Transfer\PaymentMethodsTransfer $paymentMethodsTransfer |
|
35
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
|
36
|
|
|
* |
|
37
|
|
|
* @return \Generated\Shared\Transfer\PaymentMethodsTransfer |
|
38
|
|
|
*/ |
|
39
|
|
|
public function filterPaymentMethods(PaymentMethodsTransfer $paymentMethodsTransfer, QuoteTransfer $quoteTransfer): PaymentMethodsTransfer |
|
40
|
|
|
{ |
|
41
|
|
|
$currencyCode = $quoteTransfer->getCurrency()->getCode(); |
|
42
|
|
|
$availableCurrencies = $this->config->getComputopPaymentMethodCurrencyFilterMap(); |
|
43
|
|
|
|
|
44
|
|
|
$applicablePaymentMethods = new ArrayObject(); |
|
45
|
|
|
foreach ($paymentMethodsTransfer->getMethods() as $paymentMethod) { |
|
46
|
|
|
if ($this->isComputopAvailableMethod($paymentMethod, $currencyCode, $availableCurrencies)) { |
|
47
|
|
|
$applicablePaymentMethods->append($paymentMethod); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return $paymentMethodsTransfer->setMethods($applicablePaymentMethods); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param \Generated\Shared\Transfer\PaymentMethodTransfer $paymentMethodTransfer |
|
56
|
|
|
* @param string $currencyCode |
|
57
|
|
|
* @param array $availableCurrencies |
|
58
|
|
|
* |
|
59
|
|
|
* @return bool |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function isComputopAvailableMethod( |
|
62
|
|
|
PaymentMethodTransfer $paymentMethodTransfer, |
|
63
|
|
|
string $currencyCode, |
|
64
|
|
|
array $availableCurrencies |
|
65
|
|
|
): bool { |
|
66
|
|
|
if (strpos($paymentMethodTransfer->getPaymentMethodKey(), static::COMPUTOP_PAYMENT_METHOD) === false) { |
|
67
|
|
|
return true; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if (!isset($availableCurrencies[$paymentMethodTransfer->getPaymentMethodKey()])) { |
|
71
|
|
|
return true; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
if (in_array(strtoupper($currencyCode), $availableCurrencies[$paymentMethodTransfer->getPaymentMethodKey()], true)) { |
|
75
|
|
|
return true; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return false; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths