IdCheck   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 21 2
1
<?php
2
3
namespace Samerior\MobileMoney\Mpesa\Library;
4
5
use Carbon\Carbon;
6
7
/**
8
 * Class IdCheck
9
 *
10
 * @package Samerior\MobileMoney\Mpesa\Library
11
 */
12
class IdCheck extends ApiCore
13
{
14
    /**
15
     * @param string      $number
16
     * @param string|null $callback
17
     * @return mixed
18
     * @throws \Exception
19
     * @throws \GuzzleHttp\Exception\GuzzleException
20
     */
21
    public function validate($number, $callback = null)
22
    {
23
        $number = $this->formatPhoneNumber($number);
24
        $time = Carbon::now()->format('YmdHis');
25
        $shortCode = \config('samerior.mpesa.c2b.short_code');
26
        $passkey = \config('samerior.mpesa.c2b.passkey');
27
        $defaultCallback = \config('samerior.mpesa.id_validation_callback');
28
        $initiator = \config('samerior.mpesa.initiator');
29
        $password = \base64_encode($shortCode . $passkey . $time);
30
        $body = [
31
            'Initiator' => $initiator,
32
            'BusinessShortCode' => $shortCode,
33
            'Password' => $password,
34
            'Timestamp' => $time,
35
            'TransactionType' => 'CheckIdentity',
36
            'PhoneNumber' => $number,
37
            'CallBackURL' => $callback ?: $defaultCallback,
38
            'TransactionDesc' => ' '
39
        ];
40
        return $this->sendRequest($body, 'id_check');
41
    }
42
}
43