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
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected const COMPUTOP_PAYMENT_METHOD = 'computop'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var \SprykerEco\Zed\Computop\ComputopConfig |
25
|
|
|
*/ |
26
|
|
|
protected $config; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param \SprykerEco\Zed\Computop\ComputopConfig $config |
30
|
|
|
*/ |
31
|
|
|
public function __construct(ComputopConfig $config) |
32
|
|
|
{ |
33
|
|
|
$this->config = $config; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param \Generated\Shared\Transfer\PaymentMethodsTransfer $paymentMethodsTransfer |
38
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
39
|
|
|
* |
40
|
|
|
* @return \Generated\Shared\Transfer\PaymentMethodsTransfer |
41
|
|
|
*/ |
42
|
|
|
public function filterPaymentMethods(PaymentMethodsTransfer $paymentMethodsTransfer, QuoteTransfer $quoteTransfer): PaymentMethodsTransfer |
43
|
|
|
{ |
44
|
|
|
$currencyCode = $quoteTransfer->getCurrencyOrFail()->getCodeOrFail(); |
45
|
|
|
$availableCurrencies = $this->config->getComputopPaymentMethodCurrencyFilterMap(); |
46
|
|
|
|
47
|
|
|
$applicablePaymentMethods = new ArrayObject(); |
48
|
|
|
foreach ($paymentMethodsTransfer->getMethods() as $paymentMethod) { |
49
|
|
|
if ($this->isComputopAvailableMethod($paymentMethod, $currencyCode, $availableCurrencies)) { |
50
|
|
|
$applicablePaymentMethods->append($paymentMethod); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $paymentMethodsTransfer->setMethods($applicablePaymentMethods); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param \Generated\Shared\Transfer\PaymentMethodTransfer $paymentMethodTransfer |
59
|
|
|
* @param string $currencyCode |
60
|
|
|
* @param array $availableCurrencies |
61
|
|
|
* |
62
|
|
|
* @return bool |
63
|
|
|
*/ |
64
|
|
|
protected function isComputopAvailableMethod( |
65
|
|
|
PaymentMethodTransfer $paymentMethodTransfer, |
66
|
|
|
string $currencyCode, |
67
|
|
|
array $availableCurrencies |
68
|
|
|
): bool { |
69
|
|
|
if (substr($paymentMethodTransfer->getPaymentMethodKeyOrFail(), 0, 8) !== static::COMPUTOP_PAYMENT_METHOD) { |
70
|
|
|
return true; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$availableCurrencyForSelectedPaymentMethod = $availableCurrencies[$paymentMethodTransfer->getPaymentMethodKey()] ?? null; |
74
|
|
|
if (!$availableCurrencyForSelectedPaymentMethod) { |
75
|
|
|
return true; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return in_array(strtoupper($currencyCode), $availableCurrencyForSelectedPaymentMethod, true); |
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