1 | <?php |
||
5 | final class TerminalResponse |
||
6 | { |
||
7 | /** |
||
8 | * Payture error codes. |
||
9 | * |
||
10 | * @see https://payture.com/api#error-codes_ |
||
11 | */ |
||
12 | public const ERROR_NONE = 'NONE'; |
||
13 | public const ERROR_ORDER_TIME_OUT = 'ORDER_TIME_OUT'; |
||
14 | public const ERROR_ILLEGAL_ORDER_STATE = 'ILLEGAL_ORDER_STATE'; |
||
15 | public const ERROR_PROCESSING = 'PROCESSING_ERROR'; |
||
16 | public const ERROR_ISSUER_FAIL = 'ISSUER_FAIL'; |
||
17 | public const ERROR_AMOUNT = 'AMOUNT_ERROR'; |
||
18 | public const ERROR_PROCESSING_FRAUD = 'PROCESSING_FRAUD_ERROR'; |
||
19 | public const ERROR_ISSUER_BLOCKED_CARD = 'ISSUER_BLOCKED_CARD'; |
||
20 | |||
21 | private const STATUS_SUCCESS = 'True'; |
||
22 | |||
23 | private const STATE_NEW = 'New'; |
||
24 | private const STATE_PREAUTH_3DS = 'PreAuthorized3DS'; |
||
25 | private const STATE_PREAUTH_AF = 'PreAuthorizedAF'; |
||
26 | private const STATE_AUTHORIZED = 'Authorized'; |
||
27 | private const STATE_VOIDED = 'Voided'; // locked and unlocked |
||
28 | private const STATE_CHARGED = 'Charged'; |
||
29 | private const STATE_REFUNDED = 'Refunded'; |
||
30 | private const STATE_FORWARDED = 'Forwarded'; |
||
31 | private const STATE_ERROR = 'Error'; |
||
32 | |||
33 | // custom status, for case with error code NONE |
||
34 | private const STATE_PENDING = 'Pending'; |
||
35 | |||
36 | /** |
||
37 | * Operation success flag. |
||
38 | * |
||
39 | * @var bool |
||
40 | */ |
||
41 | private $success; |
||
42 | |||
43 | /** |
||
44 | * Payment ID in Merchant system. |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | private $orderId; |
||
49 | |||
50 | /** |
||
51 | * Operation amount. |
||
52 | * |
||
53 | * @var int |
||
54 | */ |
||
55 | private $amount = 0; |
||
56 | |||
57 | /** |
||
58 | * Payment status. |
||
59 | * |
||
60 | * @var string|null |
||
61 | */ |
||
62 | private $state; |
||
63 | |||
64 | /** |
||
65 | * Payment ID in Payture system. |
||
66 | * |
||
67 | * @var string |
||
68 | */ |
||
69 | private $sessionId = ''; |
||
70 | |||
71 | /** |
||
72 | * Unique transaction number assigned by the acquiring bank |
||
73 | * |
||
74 | * @var string|null |
||
75 | */ |
||
76 | private $rrn; |
||
77 | |||
78 | /** Error code. |
||
79 | * |
||
80 | * @var string |
||
81 | */ |
||
82 | private $errorCode = ''; |
||
83 | |||
84 | /** |
||
85 | * @param string $success Operation success flag |
||
86 | * @param mixed $orderId Payment ID in Merchant system |
||
87 | */ |
||
88 | 4 | public function __construct(string $success, string $orderId) |
|
93 | |||
94 | /** |
||
95 | * @return bool |
||
96 | */ |
||
97 | 1 | public function isSuccess(): bool |
|
101 | |||
102 | 1 | public function getOrderId(): string |
|
106 | |||
107 | 1 | public function getAmount(): int |
|
111 | |||
112 | 1 | public function setAmount(int $amount): void |
|
116 | |||
117 | 1 | public function getRrn(): ?string |
|
118 | { |
||
119 | 1 | return $this->rrn; |
|
120 | } |
||
121 | |||
122 | 1 | public function getSessionId(): string |
|
126 | |||
127 | 1 | public function setSessionId(string $sessionId): void |
|
131 | |||
132 | 3 | public function getErrorCode(): string |
|
136 | |||
137 | 3 | public function setErrorCode(string $errorCode): void |
|
154 | |||
155 | 1 | public function setState(string $state): void |
|
159 | |||
160 | 1 | public function setRrn(string $rrn): void |
|
161 | { |
||
162 | 1 | $this->rrn = $rrn; |
|
163 | 1 | } |
|
164 | |||
165 | 1 | public function isNewState(): bool |
|
169 | |||
170 | 1 | public function isPreAuthorized3DSState(): bool |
|
174 | |||
175 | 1 | public function isPreAuthorizedAFState(): bool |
|
179 | |||
180 | 1 | public function isAuthorizedState(): bool |
|
184 | |||
185 | 1 | public function isVoidedState(): bool |
|
189 | |||
190 | 1 | public function isChargedState(): bool |
|
194 | |||
195 | 1 | public function isRefundedState(): bool |
|
199 | |||
200 | 1 | public function isForwardedState(): bool |
|
204 | |||
205 | 1 | public function isErrorState(): bool |
|
209 | |||
210 | 1 | public function isTimeout(): bool |
|
214 | |||
215 | 1 | public function isIllegalOrderState(): bool |
|
219 | |||
220 | 1 | public function isProcessingError(): bool |
|
224 | |||
225 | 1 | public function isFraudError(): bool |
|
229 | |||
230 | 1 | public function isAmountError(): bool |
|
234 | |||
235 | 1 | public function isIssuerFail(): bool |
|
239 | |||
240 | 1 | private function isStateEqual($expectedState): bool |
|
244 | } |
||
245 |