1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Djunehor\Vtu\Concrete; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use Djunehor\Vtu\Contracts\VtuServiceInterface; |
8
|
|
|
use GuzzleHttp\Exception\ClientException; |
9
|
|
|
use GuzzleHttp\Psr7\Request; |
10
|
|
|
use Illuminate\Support\Str; |
11
|
|
|
|
12
|
|
View Code Duplication |
class FpeVtu extends Vtu |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
private $baseUrl = 'https://fpevtu.com/'; |
15
|
|
|
private $orderId = 0; |
16
|
|
|
|
17
|
|
|
|
18
|
1 |
|
public function __construct($username = null, $password = null) |
19
|
|
|
{ |
20
|
1 |
|
$this->username = $username ?? config('laravel-vtu.fpe_vtu.username'); |
21
|
1 |
|
$this->password = $password ?? config('laravel-vtu.fpe_vtu.password'); |
22
|
|
|
|
23
|
1 |
|
$this->client = $this->getInstance(); |
24
|
1 |
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @inheritDoc |
28
|
|
|
*/ |
29
|
1 |
|
public function buyAirtime($amount, $mobileNumber, $mobileNetwork, $callBackUrl): bool |
30
|
|
|
{ |
31
|
|
|
|
32
|
1 |
|
$this->request = new Request('GET', $this->baseUrl . "client/httpvtu"); |
33
|
|
|
|
34
|
|
|
try { |
35
|
1 |
|
$response = $this->client->send($this->request, [ |
36
|
|
|
'query_params' => [ |
37
|
1 |
|
'userid' => $this->username, |
38
|
1 |
|
'pass' => $this->password, |
39
|
1 |
|
'amount' => $amount, |
40
|
1 |
|
'network' => $mobileNetwork, |
41
|
1 |
|
'phone' => $mobileNumber, |
42
|
|
|
], |
43
|
|
|
]); |
44
|
|
|
|
45
|
1 |
|
$response = json_decode($response->getBody()->getContents(), true); |
46
|
1 |
|
$this->response = explode('|', $response); |
47
|
|
|
|
48
|
1 |
|
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
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.