1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MIT License |
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerEco\Zed\FirstData\Business\Checker; |
9
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\CheckoutErrorTransfer; |
|
|
|
|
11
|
|
|
use Generated\Shared\Transfer\CheckoutResponseTransfer; |
|
|
|
|
12
|
|
|
use Generated\Shared\Transfer\QuoteTransfer; |
|
|
|
|
13
|
|
|
use SprykerEco\Client\FirstData\FirstDataClientInterface; |
14
|
|
|
use SprykerEco\Zed\FirstData\FirstDataConfig; |
15
|
|
|
|
16
|
|
|
class FirstDataResponseValidator implements FirstDataResponseValidatorInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var \SprykerEco\Client\FirstData\FirstDataClientInterface |
20
|
|
|
*/ |
21
|
|
|
protected $firstDataClient; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var \SprykerEco\Zed\FirstData\FirstDataConfig |
25
|
|
|
*/ |
26
|
|
|
protected $firstDataConfig; |
27
|
|
|
|
28
|
|
|
protected const GLOSSARY_KEY_FIRST_DATA_TRANSACTION_DATA_MISSING = 'first_data.transaction_data_is_missing'; |
29
|
|
|
protected const GLOSSARY_KEY_FIRST_DATA_RESPONSE_HASH_INVALID = 'first_data.response_hash_invalid'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param \SprykerEco\Client\FirstData\FirstDataClientInterface $firstDataClient |
33
|
|
|
* @param \SprykerEco\Zed\FirstData\FirstDataConfig $firstDataConfig |
34
|
|
|
*/ |
35
|
|
|
public function __construct( |
36
|
|
|
FirstDataClientInterface $firstDataClient, |
37
|
|
|
FirstDataConfig $firstDataConfig |
38
|
|
|
) { |
39
|
|
|
$this->firstDataClient = $firstDataClient; |
40
|
|
|
$this->firstDataConfig = $firstDataConfig; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
45
|
|
|
* @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponseTransfer |
46
|
|
|
* |
47
|
|
|
* @return bool |
48
|
|
|
*/ |
49
|
|
|
public function validateFirstDataResponse(QuoteTransfer $quoteTransfer, CheckoutResponseTransfer $checkoutResponseTransfer): bool |
50
|
|
|
{ |
51
|
|
|
if ($quoteTransfer->getPayments()->count()) { |
52
|
|
|
foreach ($quoteTransfer->getPayments() as $selectedPaymentMethod) { |
53
|
|
|
if ($selectedPaymentMethod->getPaymentMethod() === $this->firstDataConfig::PAYMENT_METHOD_KEY_CREDIT_CARD) { |
54
|
|
|
return $this->validateResponseHash($quoteTransfer, $checkoutResponseTransfer); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if ($quoteTransfer->getPaymentOrFail()->getPaymentMethod() === $this->firstDataConfig::PAYMENT_METHOD_KEY_CREDIT_CARD) { |
60
|
|
|
return $this->validateResponseHash($quoteTransfer, $checkoutResponseTransfer); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return true; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
68
|
|
|
* @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponseTransfer |
69
|
|
|
* |
70
|
|
|
* @return bool |
71
|
|
|
*/ |
72
|
|
|
protected function validateResponseHash(QuoteTransfer $quoteTransfer, CheckoutResponseTransfer $checkoutResponseTransfer): bool |
73
|
|
|
{ |
74
|
|
|
$firstDataCreditCard = $quoteTransfer->getPayment() ? |
75
|
|
|
$quoteTransfer->getPaymentOrFail()->getFirstDataCreditCard() : |
76
|
|
|
null; |
77
|
|
|
$firstDataTransactionData = $firstDataCreditCard ? $firstDataCreditCard->getFirstDataTransactionData() : null; |
78
|
|
|
|
79
|
|
|
if (!$firstDataTransactionData) { |
80
|
|
|
$checkoutErrorTransfer = (new CheckoutErrorTransfer()) |
81
|
|
|
->setMessage(static::GLOSSARY_KEY_FIRST_DATA_TRANSACTION_DATA_MISSING); |
82
|
|
|
|
83
|
|
|
$checkoutResponseTransfer->addError($checkoutErrorTransfer); |
84
|
|
|
$checkoutResponseTransfer->setIsSuccess(false); |
85
|
|
|
|
86
|
|
|
return false; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return true; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
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