Code Duplication    Length = 126-126 lines in 2 locations

src/Concrete/FpeVtu.php 1 location

@@ 12-137 (lines=126) @@
9
use GuzzleHttp\Psr7\Request;
10
use Illuminate\Support\Str;
11
12
class FpeVtu extends Vtu
13
{
14
    private $baseUrl = 'https://fpevtu.com/';
15
    private $orderId = 0;
16
17
18
    public function __construct($username = null, $password = null)
19
    {
20
        $this->username = $username ?? config('laravel-vtu.fpe_vtu.username');
21
        $this->password = $password ?? config('laravel-vtu.fpe_vtu.password');
22
23
        $this->client = $this->getInstance();
24
    }
25
26
    /**
27
     * @inheritDoc
28
     */
29
    public function buyAirtime($amount, $mobileNumber, $mobileNetwork, $callBackUrl): bool
30
    {
31
32
        $this->request = new Request('GET', $this->baseUrl . "client/httpvtu");
33
34
        try {
35
            $response = $this->client->send($this->request, [
36
                'query_params' => [
37
                    'userid' => $this->username,
38
                    'pass' => $this->password,
39
                    'amount' => $amount,
40
                    'network' => $mobileNetwork,
41
                    'phone' => $mobileNumber,
42
                ],
43
            ]);
44
45
            $response = json_decode($response->getBody()->getContents(), true);
46
            $this->response = explode('|', $response);
47
48
            return $this->response[0] == '1000' ? true : false;
49
        } catch (ClientException $e) {
50
            $this->httpError = $e;
51
52
            return false;
53
        } catch (\Exception $e) {
54
            $this->httpError = $e;
55
56
            return false;
57
58
        }
59
    }
60
61
    /**
62
     * @inheritDoc
63
     */
64
    public function buyData($mobileNumber, $mobileNetwork, $dataPlan, $callBackUrl): bool
65
    {
66
        $this->request = new Request('GET', $this->baseUrl . "client/http");
67
68
        try {
69
            $response = $this->client->send($this->request, [
70
                'query_params' => [
71
                    'userid' => $this->username,
72
                    'pass' => $this->password,
73
                    'datasize' => $dataPlan,
74
                    'network' => $mobileNetwork,
75
                    'phone' => $mobileNumber,
76
                ],
77
            ]);
78
79
            $response = json_decode($response->getBody()->getContents(), true);
80
            $this->response = explode('|', $response);
81
            $this->orderId = $this->response[1] ?? 0;
82
83
            return $this->response[0] == '1000' ? true : false;
84
        } catch (ClientException $e) {
85
            $this->httpError = $e;
86
87
            return false;
88
        } catch (\Exception $e) {
89
            $this->httpError = $e;
90
91
            return false;
92
        }
93
    }
94
95
    /**
96
     * @inheritDoc
97
     */
98
    public function payUtility($smartCardNumber, $cableTv, $package, $callBackUrl): bool
99
    {
100
        // TODO: Implement payUtility() method.
101
    }
102
103
    public function getOrderId()
104
    {
105
        return $this->orderId;
106
    }
107
108
    public function queryOrder($orderId)
109
    {
110
        $this->request = new Request('GET', $this->baseUrl . "/client/status");
111
112
        try {
113
            $response = $this->client->send($this->request, [
114
                'query_params' => [
115
                    'userid' => $this->username,
116
                    'pass' => $this->password,
117
                    'tid' => $orderId,
118
119
                ],
120
            ]);
121
122
            $response = json_decode($response->getBody()->getContents(), true);
123
            $this->response = explode('|', $response);
124
125
            return $this->response ? true : false;
126
        } catch (ClientException $e) {
127
            $this->httpError = $e;
128
129
            return false;
130
        } catch (\Exception $e) {
131
            $this->httpError = $e;
132
133
            return false;
134
135
        }
136
    }
137
}

src/Concrete/UnikMobileNig.php 1 location

@@ 12-137 (lines=126) @@
9
use GuzzleHttp\Psr7\Request;
10
use Illuminate\Support\Str;
11
12
class UnikMobileNig extends Vtu
13
{
14
    private $baseUrl = 'https://unikmobileng.com/';
15
    private $orderId = 0;
16
17
18
    public function __construct($username = null, $password = null)
19
    {
20
        $this->username = $username ?? config('laravel-vtu.unik_mobile.username');
21
        $this->password = $password ?? config('laravel-vtu.unik_mobile.password');
22
23
        $this->client = $this->getInstance();
24
    }
25
26
    /**
27
     * @inheritDoc
28
     */
29
    public function buyAirtime($amount, $mobileNumber, $mobileNetwork, $callBackUrl): bool
30
    {
31
32
        $this->request = new Request('GET', $this->baseUrl . "client/httpvtu");
33
34
        try {
35
            $response = $this->client->send($this->request, [
36
                'query_params' => [
37
                    'userid' => $this->username,
38
                    'pass' => $this->password,
39
                    'amount' => $amount,
40
                    'network' => $mobileNetwork,
41
                    'phone' => $mobileNumber,
42
                ],
43
            ]);
44
45
            $response = json_decode($response->getBody()->getContents(), true);
46
            $this->response = explode('|', $response);
47
48
            return $this->response[0] == '1000' ? true : false;
49
        } catch (ClientException $e) {
50
            $this->httpError = $e;
51
52
            return false;
53
        } catch (\Exception $e) {
54
            $this->httpError = $e;
55
56
            return false;
57
58
        }
59
    }
60
61
    /**
62
     * @inheritDoc
63
     */
64
    public function buyData($mobileNumber, $mobileNetwork, $dataPlan, $callBackUrl): bool
65
    {
66
        $this->request = new Request('GET', $this->baseUrl . "client/http");
67
68
        try {
69
            $response = $this->client->send($this->request, [
70
                'query_params' => [
71
                    'userid' => $this->username,
72
                    'pass' => $this->password,
73
                    'datasize' => $dataPlan,
74
                    'network' => $mobileNetwork,
75
                    'phone' => $mobileNumber,
76
                ],
77
            ]);
78
79
            $response = json_decode($response->getBody()->getContents(), true);
80
            $this->response = explode('|', $response);
81
            $this->orderId = $this->response[1] ?? 0;
82
83
            return $this->response[0] == '1000' ? true : false;
84
        } catch (ClientException $e) {
85
            $this->httpError = $e;
86
87
            return false;
88
        } catch (\Exception $e) {
89
            $this->httpError = $e;
90
91
            return false;
92
        }
93
    }
94
95
    /**
96
     * @inheritDoc
97
     */
98
    public function payUtility($smartCardNumber, $cableTv, $package, $callBackUrl): bool
99
    {
100
        // TODO: Implement payUtility() method.
101
    }
102
103
    public function getOrderId()
104
    {
105
        return $this->orderId;
106
    }
107
108
    public function queryOrder($orderId)
109
    {
110
        $this->request = new Request('GET', $this->baseUrl . "/client/status");
111
112
        try {
113
            $response = $this->client->send($this->request, [
114
                'query_params' => [
115
                    'userid' => $this->username,
116
                    'pass' => $this->password,
117
                    'tid' => $orderId,
118
119
                ],
120
            ]);
121
122
            $response = json_decode($response->getBody()->getContents(), true);
123
            $this->response = explode('|', $response);
124
125
            return $this->response ? true : false;
126
        } catch (ClientException $e) {
127
            $this->httpError = $e;
128
129
            return false;
130
        } catch (\Exception $e) {
131
            $this->httpError = $e;
132
133
            return false;
134
135
        }
136
    }
137
}