Completed
Push — master ( fdad74...9a9afe )
by Henry
28s queued 13s
created

ClubKonnectStatusCodeEnum::getStatusCode()   A

Complexity

Conditions 6
Paths 7

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.0444
c 0
b 0
f 0
cc 6
nc 7
nop 1
1
<?php
2
/**
3
 * Created By: Henry Ejemuta
4
 * PC: Enrico Systems
5
 * Project: laravel-clubkonnect
6
 * Company: Stimolive Technologies Limited
7
 * Class Name: ClubKonnectStatusCode.php
8
 * Date Created: 5/14/21
9
 * Time Created: 12:12 PM
10
 */
11
12
namespace HenryEjemuta\LaravelClubKonnect\Enums;
13
14
15
/**
16
 * Process flow for dispute resolution is outlined below
17
 *
18
 * 1. Initiate a transaction by calling the appropriate end point. An OrderID is generated which is returned as part of the JSON response.
19
 *
20
 * 2. Retrieve the OrderID and pass it as a parameter to our Query API to get the status of the order.
21
 *
22
 * 3. If the order fails, then pass the OrderID retrieved in stage two(2) above to our CANCEL API  to cancel the transaction.
23
 *
24
 * Class ClubKonnectStatusCodeEnum
25
 * @package HenryEjemuta\LaravelClubKonnect\Classes
26
 */
27
class ClubKonnectStatusCodeEnum
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
28
{
29
    public static $successCodes = [100, 199, 300, 200, 201];
30
    private static $statusCodes = [
31
        '100' => [
32
            'code' => 100,
33
            'status' => 'ORDER_RECEIVED',
34
            'remark' => 'Awaiting Processing',
35
            'description' => 'Order has been received and is awaiting processing'
36
        ],
37
        '199' => [
38
            'code' => 199,
39
            'status' => 'ORDER_RECEIVED',
40
            'remark' => 'Unspecified Error',
41
            'description' => ''
42
        ],
43
        '300' => [
44
            'code' => 300,
45
            'status' => 'ORDER_PROCESSED',
46
            'remark' => 'Awaiting Network Response',
47
            'description' => 'Transaction was sent and is awaiting response from mobile network operator'
48
        ],
49
        '399' => [
50
            'code' => 399,
51
            'status' => 'ORDER_PROCESSED',
52
            'remark' => 'Unspecified Error',
53
            'description' => ''
54
        ],
55
        '200' => [
56
            'code' => 200,
57
            'status' => 'ORDER_COMPLETED',
58
            'remark' => 'Success',
59
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was successful'
60
        ],
61
        '201' => [
62
            'code' => 201,
63
            'status' => 'ORDER_COMPLETED',
64
            'remark' => 'Network Unresponsive',
65
            'description' => 'Transaction was sent but no response was received from mobile network operator after 60seconds. All transaction that returns network unresponsive will be retried every 5min for a maximum of 1hour before it is cancelled.
66
67
N.B. network issues with the provider and can sometimes be resolved when tried later'
68
        ],
69
        '299' => [
70
            'code' => 299,
71
            'status' => 'ORDER_COMPLETED',
72
            'remark' => 'Unspecified Error',
73
            'description' => ''
74
        ],
75
        '400' => [
76
            'code' => 400,
77
            'status' => 'ORDER_ERROR',
78
            'remark' => 'INVALID_CREDENTIALS',
79
            'description' => 'The UserID and API key combination is not correct.'
80
        ],
81
        '401' => [
82
            'code' => 401,
83
            'status' => 'ORDER_ERROR',
84
            'remark' => 'MISSING_CREDENTIALS',
85
            'description' => 'The URL format is not valid.'
86
        ],
87
        '402' => [
88
            'code' => 402,
89
            'status' => 'ORDER_ERROR',
90
            'remark' => 'MISSING_USERID',
91
            'description' => 'Username field is empty'
92
        ],
93
        '403' => [
94
            'code' => 403,
95
            'status' => 'ORDER_ERROR',
96
            'remark' => 'MISSING_APIKEY',
97
            'description' => 'API Key field is empty'
98
99
        ],
100
        '404' => [
101
            'code' => 404,
102
            'status' => 'ORDER_ERROR',
103
            'remark' => 'MISSING_MOBILENETWORK',
104
            'description' => 'Mobile network is empty'
105
        ],
106
        '405' => [
107
            'code' => 405,
108
            'status' => 'ORDER_ERROR',
109
            'remark' => 'MISSING_AMOUNT',
110
            'description' => 'Amount is empty'
111
        ],
112
        '406' => [
113
            'code' => 406,
114
            'status' => 'ORDER_ERROR',
115
            'remark' => 'INVALID_AMOUNT',
116
            'description' => 'Amount is not valid'
117
        ],
118
        '407' => [
119
            'code' => 407,
120
            'status' => 'ORDER_ERROR',
121
            'remark' => 'MINIMUM_100',
122
            'description' => 'Minimum amount is 100'
123
        ],
124
        '408' => [
125
            'code' => 408,
126
            'status' => 'ORDER_ERROR',
127
            'remark' => 'MINIMUM_50000',
128
            'description' => 'Minimum amount is 50,000'
129
        ],
130
        '409' => [
131
            'code' => 409,
132
            'status' => 'ORDER_ERROR',
133
            'remark' => 'INVALID_RECIPIENT',
134
            'description' => 'An invalid mobile phone number was entered'
135
        ],
136
        '410' => [
137
            'code' => 410,
138
            'status' => 'ORDER_ERROR',
139
            'remark' => 'INVALID_API_ERROR1',
140
            'description' => 'API error'
141
        ],
142
        '411' => [
143
            'code' => 411,
144
            'status' => 'ORDER_ERROR',
145
            'remark' => 'INVALID_API_ERROR2',
146
            'description' => 'API error'
147
        ],
148
        '412' => [
149
            'code' => 412,
150
            'status' => 'ORDER_ERROR',
151
            'remark' => 'INSUFFICIENT_APIAMOUNT',
152
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful but was placed on hold by our system. All transaction that is placed on hold will be retried every 5min for a maximum of 1hour, before it is cancelled.
153
154
N.B. Transactions are usually placed on hold due to network issues with the provider and can sometimes be resolved when tried later'
155
        ],
156
        '413' => [
157
            'code' => 413,
158
            'status' => 'ORDER_ERROR',
159
            'remark' => 'INVALID_API',
160
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful but was placed on hold by our system. All transaction that is placed on hold will be retried every 5min for a maximum of 1hour, before it is cancelled.
161
162
N.B. Transactions are usually placed on hold due to network issues with the provider and can sometimes be resolved when tried later'
163
        ],
164
        '414' => [
165
            'code' => 414,
166
            'status' => 'ORDER_ERROR',
167
            'remark' => 'INVALID_PAYMENT_OPTION',
168
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful but was placed on hold by our system. All transaction that is placed on hold will be retried every 5min for a maximum of 1hour, before it is cancelled.
169
170
N.B. Transactions are usually placed on hold due to network issues with the provider and can sometimes be resolved when tried later'
171
        ],
172
        '415' => [
173
            'code' => 415,
174
            'status' => 'ORDER_ERROR',
175
            'remark' => 'INSUFFICIENT_APISTOREDEALERAMOUNT',
176
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful but was placed on hold by our system. All transaction that is placed on hold will be retried every 5min for a maximum of 1hour, before it is cancelled.
177
178
N.B. Transactions are usually placed on hold due to network issues with the provider and can sometimes be resolved when tried later'
179
        ],
180
        '416' => [
181
            'code' => 416,
182
            'status' => 'ORDER_ERROR',
183
            'remark' => 'INSUFFICIENT_APISTOREAMOUNT',
184
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful but was placed on hold by our system. All transaction that is placed on hold will be retried every 5min for a maximum of 1hour, before it is cancelled.
185
186
N.B. Transactions are usually placed on hold due to network issues with the provider and can sometimes be resolved when tried later'
187
        ],
188
        '417' => [
189
            'code' => 417,
190
            'status' => 'ORDER_ERROR',
191
            'remark' => 'INSUFFICIENT_BALANCE',
192
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful but was placed on hold by our system. All transaction that is placed on hold will be retried every 5min for a maximum of 1hour, before it is cancelled.
193
194
            N.B. Transactions are usually placed on hold due to network issues with the provider and can sometimes be resolved when tried later'
195
        ],
196
        '418' => [
197
            'code' => 418,
198
            'status' => 'ORDER_ERROR',
199
            'remark' => 'INVALID_MOBILENETWORK',
200
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful but was placed on hold by our system. All transaction that is placed on hold will be retried every 5min for a maximum of 1hour, before it is cancelled.
201
202
            N.B. Transactions are usually placed on hold due to network issues with the provider and can sometimes be resolved when tried later'
203
        ],
204
        '499' => [
205
            'code' => 499,
206
            'status' => 'ORDER_ERROR',
207
            'remark' => 'Unspecified Error',
208
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful but was placed on hold by our system. All transaction that is placed on hold will be retried every 5min for a maximum of 1hour, before it is cancelled.
209
210
            N.B. Transactions are usually placed on hold due to network issues with the provider and can sometimes be resolved when tried later'
211
        ],
212
        '600' => [
213
            'code' => 600,
214
            'status' => 'ORDER_ONHOLD',
215
            'remark' => 'Network Error',
216
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful but was placed on hold by our system. All transaction that is placed on hold will be retried every 5min for a maximum of 1hour, before it is cancelled.
217
218
N.B. Transactions are usually placed on hold due to network issues with the provider and can sometimes be resolved when tried later'
219
        ],
220
        '601' => [
221
            'code' => 601,
222
            'status' => 'ORDER_ONHOLD',
223
            'remark' => 'Your request cannot be processed at this time',
224
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful but was placed on hold by our system. All transaction that is placed on hold will be retried every 5min for a maximum of 1hour, before it is cancelled.
225
226
N.B. Transactions are usually placed on hold due to network issues with the provider and can sometimes be resolved when tried later'
227
        ],
228
        '602' => [
229
            'code' => 602,
230
            'status' => 'ORDER_ONHOLD',
231
            'remark' => 'Your account has been credited back for failed Txn',
232
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful but was placed on hold by our system. All transaction that is placed on hold will be retried every 5min for a maximum of 1hour, before it is cancelled.
233
234
N.B. Transactions are usually placed on hold due to network issues with the provider and can sometimes be resolved when tried later'
235
        ],
236
        '603' => [
237
            'code' => 603,
238
            'status' => 'ORDER_ONHOLD',
239
            'remark' => 'the process failed',
240
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful but was placed on hold by our system. All transaction that is placed on hold will be retried every 5min for a maximum of 1hour, before it is cancelled.
241
242
N.B. Transactions are usually placed on hold due to network issues with the provider and can sometimes be resolved when tried later'
243
        ],
244
        '604' => [
245
            'code' => 604,
246
            'status' => 'ORDER_ONHOLD',
247
            'remark' => 'Transaction Failure',
248
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful but was placed on hold by our system. All transaction that is placed on hold will be retried every 5min for a maximum of 1hour, before it is cancelled.
249
250
N.B. Transactions are usually placed on hold due to network issues with the provider and can sometimes be resolved when tried later'
251
        ],
252
        '605' => [
253
            'code' => 605,
254
            'status' => 'ORDER_ONHOLD',
255
            'remark' => 'Failed recharge',
256
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful but was placed on hold by our system. All transaction that is placed on hold will be retried every 5min for a maximum of 1hour, before it is cancelled.
257
258
N.B. Transactions are usually placed on hold due to network issues with the provider and can sometimes be resolved when tried later'
259
        ],
260
        '606' => [
261
            'code' => 606,
262
            'status' => 'ORDER_ONHOLD',
263
            'remark' => 'By APIUser',
264
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful but was placed on hold by our system. All transaction that is placed on hold will be retried every 5min for a maximum of 1hour, before it is cancelled.
265
266
N.B. Transactions are usually placed on hold due to network issues with the provider and can sometimes be resolved when tried later'
267
        ],
268
        '699' => [
269
            'code' => 699,
270
            'status' => 'ORDER_ONHOLD',
271
            'remark' => 'Unspecified Error',
272
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful and as such was cancelled by our system'
273
        ],
274
        '500' => [
275
            'code' => 500,
276
            'status' => 'ORDER_CANCELLED',
277
            'remark' => 'By APIUser',
278
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful and as such was cancelled by our system'
279
        ],
280
        '501' => [
281
            'code' => 501,
282
            'status' => 'ORDER_CANCELLED',
283
            'remark' => 'By Server',
284
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful and as such was cancelled by our system'
285
        ],
286
        '506' => [
287
            'code' => 506,
288
            'status' => 'ORDER_CANCELLED',
289
            'remark' => 'Server Busy',
290
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful and as such was cancelled by our system'
291
        ],
292
        '507' => [
293
            'code' => 507,
294
            'status' => 'ORDER_CANCELLED',
295
            'remark' => 'Network Error',
296
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful and as such was cancelled by our system'
297
        ],
298
        '508' => [
299
            'code' => 508,
300
            'status' => 'ORDER_CANCELLED',
301
            'remark' => 'Your request cannot be processed at this time',
302
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful and as such was cancelled by our system'
303
        ],
304
        '509' => [
305
            'code' => 509,
306
            'status' => 'ORDER_CANCELLED',
307
            'remark' => 'Your account has been credited back for failed Txn',
308
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful and as such was cancelled by our system'
309
        ],
310
        '510' => [
311
            'code' => 510,
312
            'status' => 'ORDER_CANCELLED',
313
            'remark' => 'The process failed',
314
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful and as such was cancelled by our system'
315
        ],
316
        '511' => [
317
            'code' => 511,
318
            'status' => 'ORDER_CANCELLED',
319
            'remark' => 'Transaction Failure',
320
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful and as such was cancelled by our system'
321
        ],
322
        '512' => [
323
            'code' => 512,
324
            'status' => 'ORDER_CANCELLED',
325
            'remark' => 'request is not valid',
326
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful and as such was cancelled by our system'
327
        ],
328
        '513' => [
329
            'code' => 513,
330
            'status' => 'ORDER_CANCELLED',
331
            'remark' => 'Failed recharge',
332
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful and as such was cancelled by our system'
333
        ],
334
        '514' => [
335
            'code' => 514,
336
            'status' => 'ORDER_CANCELLED',
337
            'remark' => 'Transaction rejected',
338
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful and as such was cancelled by our system'
339
        ],
340
        '515' => [
341
            'code' => 515,
342
            'status' => 'ORDER_CANCELLED',
343
            'remark' => 'The receivers account is in the wrong state',
344
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful and as such was cancelled by our system'
345
        ],
346
        '516' => [
347
            'code' => 516,
348
            'status' => 'ORDER_CANCELLED',
349
            'remark' => 'is not a valid MTN Subscriber',
350
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful and as such was cancelled by our system'
351
        ],
352
        '517' => [
353
            'code' => 517,
354
            'status' => 'ORDER_CANCELLED',
355
            'remark' => 'is not eligible for this offer',
356
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful and as such was cancelled by our system'
357
        ],
358
        '518' => [
359
            'code' => 518,
360
            'status' => 'ORDER_CANCELLED',
361
            'remark' => 'the subscriber you are trying to Buy data for is not eligible',
362
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful and as such was cancelled by our system'
363
        ],
364
        '519' => [
365
            'code' => 519,
366
            'status' => 'ORDER_CANCELLED',
367
            'remark' => 'You already have a Data Plan yet to be activated',
368
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful and as such was cancelled by our system'
369
        ],
370
        '520' => [
371
            'code' => 520,
372
            'status' => 'ORDER_CANCELLED',
373
            'remark' => 'you are not gifting to a valid Globacom user',
374
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful and as such was cancelled by our system'
375
        ],
376
        '521' => [
377
            'code' => 521,
378
            'status' => 'ORDER_CANCELLED',
379
            'remark' => 'Order already completed, cancelled or refunded',
380
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful and as such was cancelled by our system'
381
        ],
382
        '599' => [
383
            'code' => 599,
384
            'status' => 'ORDER_CANCELLED',
385
            'remark' => 'Unspecified Error',
386
            'description' => 'Transaction was sent and response received from mobile network operator that the transaction was unsuccessful and as such was cancelled by our system'
387
        ],
388
        '999' => [
389
            'code' => 999,
390
            'status' => 'NAVSC',
391
            'remark' => '',
392
            'description' => 'Invalide status code, this might be as a result of inablity to communicate with ClubKonnect API Server.'
393
        ],
394
    ];
395
    private static $cache = [];
396
397
    private $object;
398
399
    private function __construct(array $statusCode)
400
    {
401
        $this->object = (object)$statusCode;
402
    }
403
404
    public function getCode(): int
405
    {
406
        return $this->object->code;
407
    }
408
409
    public function getStatus(): string
410
    {
411
        return strtoupper($this->object->status);
412
    }
413
414
    public function getRemark(): string
415
    {
416
        return strtoupper($this->object->remark);
417
    }
418
419
    public function getDescription(): string
420
    {
421
        return strtoupper($this->object->description);
422
    }
423
424
    public function toArray(): array
425
    {
426
        return [
427
            'code' => $this->getCode(),
428
            'status' => $this->getStatus(),
429
            'remark' => $this->getRemark(),
430
            'description' => $this->getDescription()
431
        ];
432
    }
433
434
    /**
435
     * @param $code
436
     * @return ClubKonnectStatusCodeEnum|null
437
     */
438
    public static function getByCode($code): ?ClubKonnectStatusCodeEnum
439
    {
440
        $code = trim($code);
441
        if (!key_exists($code, self::$statusCodes))
442
            self::$cache[$code] = new ClubKonnectStatusCodeEnum(self::$statusCodes[999]);
443
        if (!key_exists($code, self::$cache))
444
            self::$cache[$code] = new ClubKonnectStatusCodeEnum(self::$statusCodes[$code]);
445
        return self::$cache[$code];
446
    }
447
448
    /**
449
     * @param $status
450
     * @return ClubKonnectStatusCodeEnum|null
451
     */
452
    public static function getStatusCode($status): ?ClubKonnectStatusCodeEnum
453
    {
454
        $status = trim($status);
455
        if (!key_exists($status, self::$cache)) {
456
            $found = false;
457
            foreach (self::$statusCodes as $code => $statusCode) {
458
                if (($statusCode['status'] == $status) || ($statusCode['remark'] == $status)) {
459
                    self::$cache[$status] = new ClubKonnectStatusCodeEnum($statusCode);
460
                    $found = true;
461
                    break;
462
                }
463
            }
464
            if (!$found) {
465
                self::$cache[$status] = new ClubKonnectStatusCodeEnum(self::$statusCodes[999]);
466
            }
467
        }
468
        return self::$cache[$status];
469
    }
470
471
    /**
472
     * @param $remark
473
     * @return ClubKonnectStatusCodeEnum|null
474
     */
475
    public static function getByRemark($remark): ?ClubKonnectStatusCodeEnum
476
    {
477
        $remark = trim($remark);
478
        if (!key_exists($remark, self::$cache)) {
479
            $found = false;
480
            foreach (self::$statusCodes as $code => $statusCode) {
481
                if ($statusCode['remark'] == $remark) {
482
                    self::$cache[$remark] = new ClubKonnectStatusCodeEnum($statusCode);
483
                    $found = true;
484
                }
485
            }
486
            if (!$found) {
487
                self::$cache[$remark] = new ClubKonnectStatusCodeEnum(self::$statusCodes[999]);
488
            }
489
        }
490
        return self::$cache[$remark];
491
    }
492
493
    public function __toString(): string
494
    {
495
        return print_r($this->toArray(), true);
496
    }
497
498
}
499