|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use PagaMasTarde\ModuleUtils\Model\Log\LogEntry; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class AbstractController |
|
7
|
|
|
*/ |
|
8
|
|
|
abstract class AbstractController extends ModuleFrontController |
|
|
|
|
|
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* PMT_CODE |
|
12
|
|
|
*/ |
|
13
|
|
|
const PMT_CODE = 'paylater'; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* EXCEPTION RESPONSES |
|
17
|
|
|
*/ |
|
18
|
|
|
const CC_ERR_MSG = 'Unable to block resource'; |
|
19
|
|
|
const CC_NO_MERCHANT_ORDERID = 'Merchant Order Id (cart_id) not found'; |
|
20
|
|
|
const CC_NO_CONFIG = 'Unable to load module configuration'; |
|
21
|
|
|
const CC_MALFORMED = 'Bad request, module may not be enabled'; |
|
22
|
|
|
|
|
23
|
|
|
const GMO_ERR_MSG = 'Unable to find merchant Order'; |
|
24
|
|
|
const GMO_CART_NOT_LOADED = 'Unable to load cart'; |
|
25
|
|
|
|
|
26
|
|
|
const GPOI_ERR_MSG = 'Pmt Order Not Found'; |
|
27
|
|
|
const GPOI_NO_ORDERID = 'We can not get the PagaMasTarde identification in database.'; |
|
28
|
|
|
|
|
29
|
|
|
const GPO_ERR_MSG = 'Unable to get Order'; |
|
30
|
|
|
const GPO_ERR_TYPEOF = 'The requested PMT Order is not a valid PMTOrder object'; |
|
31
|
|
|
|
|
32
|
|
|
const COS_ERR_MSG = 'Order status is not authorized'; |
|
33
|
|
|
const COS_WRONG_STATUS = 'Invalid Pmt status'; |
|
34
|
|
|
|
|
35
|
|
|
const CMOS_ERR_MSG = 'Merchant Order status is invalid'; |
|
36
|
|
|
const CMOS_WRONG_CURRENT_STATUS = 'The status of the merchant order is not correct'; |
|
37
|
|
|
const CMOS_WRONG_PREVIOUS_STATUS = 'Previous merchant status order is not correct'; |
|
38
|
|
|
const CMOS_PREVIOUSLY_PROCESSED = 'The merchant order has been already processed at least once'; |
|
39
|
|
|
|
|
40
|
|
|
const VA_ERR_MSG = 'Amount conciliation error'; |
|
41
|
|
|
const VA_WRONG_AMOUNT = 'Wrong order amount'; |
|
42
|
|
|
|
|
43
|
|
|
const PMO_ERR_MSG = 'Unknown Error'; |
|
44
|
|
|
|
|
45
|
|
|
const CPO_ERR_MSG = 'Order not confirmed'; |
|
46
|
|
|
const CPO_OK_MSG = 'Order confirmed'; |
|
47
|
|
|
|
|
48
|
|
|
const RMO_OK_MSG = 'Order process rollback successfully'; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var integer $statusCode |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $statusCode = 200; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var string $errorMessage |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $errorMessage = ''; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var string $errorDetail |
|
62
|
|
|
*/ |
|
63
|
|
|
protected $errorDetail = ''; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @var array $headers |
|
67
|
|
|
*/ |
|
68
|
|
|
protected $headers; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @var string $format |
|
72
|
|
|
*/ |
|
73
|
|
|
protected $format = 'json'; |
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Return a printable response of the request |
|
78
|
|
|
* |
|
79
|
|
|
* @param array $extraOutput |
|
80
|
|
|
* @return mixed |
|
81
|
|
|
*/ |
|
82
|
|
|
// public function response($extraOutput = array()) |
|
83
|
|
|
// { |
|
84
|
|
|
// $response = $this->getResponse(); |
|
85
|
|
|
// |
|
86
|
|
|
// $output = array(); |
|
87
|
|
|
// if (!empty($this->errorMessage)) { |
|
88
|
|
|
// $output['errorMessage'] = $this->errorMessage; |
|
89
|
|
|
// } |
|
90
|
|
|
// if (!empty($this->errorDetail)) { |
|
91
|
|
|
// $output['errorDetail'] = $this->errorDetail; |
|
92
|
|
|
// } |
|
93
|
|
|
// if (count($extraOutput)) { |
|
94
|
|
|
// $output = array_merge($output, $extraOutput); |
|
95
|
|
|
// } |
|
96
|
|
|
// if ($this->format == 'json') { |
|
97
|
|
|
// $output = json_encode($output); |
|
98
|
|
|
// $response->setHeader('Content-Type', 'application/json'); |
|
99
|
|
|
// $response->setHeader('Content-Length', strlen($output)); |
|
100
|
|
|
// } |
|
101
|
|
|
// |
|
102
|
|
|
// $protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'); |
|
103
|
|
|
// $response->setHeader($protocol, $this->statusCode, $this->getHttpStatusCode($this->statusCode)); |
|
104
|
|
|
// $response->setBody($output); |
|
105
|
|
|
// |
|
106
|
|
|
// foreach ($this->headers as $key => $value) { |
|
107
|
|
|
// $response->setHeader($key, $value); |
|
108
|
|
|
// } |
|
109
|
|
|
// return $response; |
|
110
|
|
|
// } |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Configure redirection |
|
114
|
|
|
* |
|
115
|
|
|
* @param bool $error |
|
116
|
|
|
* @param string $url |
|
117
|
|
|
* @param array $parameters |
|
118
|
|
|
*/ |
|
119
|
|
|
public function redirect($error = true, $url = '', $parameters = array()) |
|
120
|
|
|
{ |
|
121
|
|
|
if ($error) { |
|
122
|
|
|
Tools::redirect($url); |
|
|
|
|
|
|
123
|
|
|
return; |
|
124
|
|
|
} |
|
125
|
|
|
$parsedUrl = parse_url($url); |
|
126
|
|
|
$separator = ($parsedUrl['query'] == null) ? '?' : '&'; |
|
127
|
|
|
$redirectUrl = $url. $separator . http_build_query($parameters); |
|
128
|
|
|
Tools::redirect($redirectUrl); |
|
129
|
|
|
return; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Return the HttpStatusCode description |
|
134
|
|
|
* |
|
135
|
|
|
* @param int $statusCode |
|
136
|
|
|
* @return string |
|
137
|
|
|
*/ |
|
138
|
|
|
public function getHttpStatusCode($statusCode = 200) |
|
139
|
|
|
{ |
|
140
|
|
|
$httpStatusCodes = array( |
|
141
|
|
|
200 => "OK", |
|
142
|
|
|
201 => "Created", |
|
143
|
|
|
202 => "Accepted", |
|
144
|
|
|
400 => "Bad Request", |
|
145
|
|
|
401 => "Unauthorized", |
|
146
|
|
|
402 => "Payment Required", |
|
147
|
|
|
403 => "Forbidden", |
|
148
|
|
|
404 => "Not Found", |
|
149
|
|
|
405 => "Method Not Allowed", |
|
150
|
|
|
406 => "Not Acceptable", |
|
151
|
|
|
407 => "Proxy Authentication Required", |
|
152
|
|
|
408 => "Request Timeout", |
|
153
|
|
|
409 => "Conflict", |
|
154
|
|
|
429 => "Too Many Requests", |
|
155
|
|
|
500 => "Internal Server Error", |
|
156
|
|
|
); |
|
157
|
|
|
return isset($httpStatusCodes)? $httpStatusCodes[$statusCode] : $httpStatusCodes[200]; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* Save log in SQL database |
|
162
|
|
|
* |
|
163
|
|
|
* @param array $data |
|
164
|
|
|
*/ |
|
165
|
|
|
public function saveLog($data = array()) |
|
166
|
|
|
{ |
|
167
|
|
|
try { |
|
168
|
|
|
$data = array_merge($data, array( |
|
169
|
|
|
'timestamp' => time(), |
|
170
|
|
|
'date' => date("Y-m-d H:i:s"), |
|
171
|
|
|
)); |
|
172
|
|
|
|
|
173
|
|
|
Db::getInstance()->insert('pmt_logs', array( |
|
|
|
|
|
|
174
|
|
|
'log' => json_encode(str_replace('\'', '`', $data)), |
|
175
|
|
|
)); |
|
176
|
|
|
} catch (\Exception $exception) { |
|
177
|
|
|
// Do nothing |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
} |
|
181
|
|
|
|
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