|
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\AfterPay\Business\Api\Adapter\ApiCall; |
|
9
|
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\AfterPayApiResponseTransfer; |
|
|
|
|
|
|
11
|
|
|
use Generated\Shared\Transfer\AfterPayAuthorizeRequestTransfer; |
|
|
|
|
|
|
12
|
|
|
use SprykerEco\Shared\AfterPay\AfterPayApiRequestConfig; |
|
13
|
|
|
use SprykerEco\Shared\AfterPay\AfterPayConfig as SharedAfterPayConfig; |
|
14
|
|
|
use SprykerEco\Zed\AfterPay\AfterPayConfig; |
|
15
|
|
|
use SprykerEco\Zed\AfterPay\Business\Api\Adapter\Client\ClientInterface; |
|
16
|
|
|
use SprykerEco\Zed\AfterPay\Business\Api\Adapter\Converter\TransferToCamelCaseArrayConverterInterface; |
|
17
|
|
|
use SprykerEco\Zed\AfterPay\Business\Exception\ApiHttpRequestException; |
|
18
|
|
|
use SprykerEco\Zed\AfterPay\Dependency\Service\AfterPayToUtilEncodingServiceInterface; |
|
19
|
|
|
|
|
20
|
|
|
class AuthorizePaymentCall extends AbstractApiCall implements AuthorizePaymentCallInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var \SprykerEco\Zed\AfterPay\Business\Api\Adapter\Client\ClientInterface |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $client; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var \SprykerEco\Zed\AfterPay\AfterPayConfig |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $config; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param \SprykerEco\Zed\AfterPay\Business\Api\Adapter\Client\ClientInterface $client |
|
34
|
|
|
* @param \SprykerEco\Zed\AfterPay\Business\Api\Adapter\Converter\TransferToCamelCaseArrayConverterInterface $transferConverter |
|
35
|
|
|
* @param \SprykerEco\Zed\AfterPay\Dependency\Service\AfterPayToUtilEncodingServiceInterface $utilEncoding |
|
36
|
|
|
* @param \SprykerEco\Zed\AfterPay\AfterPayConfig $config |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct( |
|
39
|
|
|
ClientInterface $client, |
|
40
|
|
|
TransferToCamelCaseArrayConverterInterface $transferConverter, |
|
41
|
|
|
AfterPayToUtilEncodingServiceInterface $utilEncoding, |
|
42
|
|
|
AfterPayConfig $config |
|
43
|
|
|
) { |
|
44
|
|
|
$this->client = $client; |
|
45
|
|
|
$this->transferConverter = $transferConverter; |
|
46
|
|
|
$this->utilEncoding = $utilEncoding; |
|
47
|
|
|
$this->config = $config; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param \Generated\Shared\Transfer\AfterPayAuthorizeRequestTransfer $requestTransfer |
|
52
|
|
|
* |
|
53
|
|
|
* @return \Generated\Shared\Transfer\AfterPayApiResponseTransfer |
|
54
|
|
|
*/ |
|
55
|
|
|
public function execute(AfterPayAuthorizeRequestTransfer $requestTransfer): AfterPayApiResponseTransfer |
|
56
|
|
|
{ |
|
57
|
|
|
$jsonRequest = $this->buildJsonRequestFromTransferObject($requestTransfer); |
|
58
|
|
|
|
|
59
|
|
|
try { |
|
60
|
|
|
$jsonResponse = $this->client->sendPost( |
|
61
|
|
|
$this->config->getAuthorizeApiEndpointUrl(), |
|
62
|
|
|
$jsonRequest |
|
63
|
|
|
); |
|
64
|
|
|
} catch (ApiHttpRequestException $apiHttpRequestException) { |
|
65
|
|
|
$this->logApiException($apiHttpRequestException); |
|
66
|
|
|
$jsonResponse = '[]'; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return $this->buildAuthorizeResponseTransfer($jsonResponse); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param string $jsonResponse |
|
74
|
|
|
* |
|
75
|
|
|
* @return \Generated\Shared\Transfer\AfterPayApiResponseTransfer |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function buildAuthorizeResponseTransfer(string $jsonResponse): AfterPayApiResponseTransfer |
|
78
|
|
|
{ |
|
79
|
|
|
$jsonResponseArray = $this->utilEncoding->decodeJson($jsonResponse, true); |
|
80
|
|
|
|
|
81
|
|
|
return (new AfterPayApiResponseTransfer()) |
|
82
|
|
|
->setOutcome($jsonResponseArray[AfterPayApiRequestConfig::TRANSACTION_OUTCOME] ?? SharedAfterPayConfig::API_TRANSACTION_OUTCOME_REJECTED) |
|
83
|
|
|
->setReservationId($jsonResponseArray[AfterPayApiRequestConfig::TRANSACTION_RESERVATION_ID] ?? null) |
|
84
|
|
|
->setCheckoutId($jsonResponseArray[AfterPayApiRequestConfig::TRANSACTION_CHECKOUT_ID] ?? null) |
|
85
|
|
|
->setCustomerNumber($this->findCustomerNumber($jsonResponseArray)) |
|
|
|
|
|
|
86
|
|
|
->setResponsePayload($jsonResponse); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param array $response |
|
91
|
|
|
* |
|
92
|
|
|
* @return string|null |
|
93
|
|
|
*/ |
|
94
|
|
|
protected function findCustomerNumber(array $response): ?string |
|
95
|
|
|
{ |
|
96
|
|
|
$customerData = $response[AfterPayApiRequestConfig::CUSTOMER] ?? []; |
|
97
|
|
|
|
|
98
|
|
|
return $customerData[AfterPayApiRequestConfig::CUSTOMER_NUMBER] ?? null; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
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