1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace HenryEjemuta\LaravelVtuDotNG; |
4
|
|
|
|
5
|
|
|
use HenryEjemuta\LaravelVtuDotNG\Classes\VtuDotNGResponse; |
6
|
|
|
use HenryEjemuta\LaravelVtuDotNG\Exceptions\VtuDotNGErrorException; |
7
|
|
|
use Illuminate\Support\Facades\Http; |
8
|
|
|
|
9
|
|
|
class VtuDotNG |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* base url |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
private $baseUrl; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* the cart session key |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $instanceName; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Flexible handle to the VTPass Configuration |
27
|
|
|
* |
28
|
|
|
* @var |
29
|
|
|
*/ |
30
|
|
|
protected $config; |
31
|
|
|
|
32
|
|
|
public function __construct($baseUrl, $instanceName, $config) |
33
|
|
|
{ |
34
|
|
|
$this->baseUrl = $baseUrl; |
35
|
|
|
$this->instanceName = $instanceName; |
36
|
|
|
$this->config = $config; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* get instance name of the cart |
41
|
|
|
* |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
|
|
public function getInstanceName() |
45
|
|
|
{ |
46
|
|
|
return $this->instanceName; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $endpoint |
51
|
|
|
* @param array $params |
52
|
|
|
* @return VtuDotNGResponse |
53
|
|
|
* @throws VtuDotNGErrorException |
54
|
|
|
*/ |
55
|
|
|
private function withAuth(string $endpoint, array $params = []): VtuDotNGResponse |
56
|
|
|
{ |
57
|
|
|
$params['username'] = $this->config['username']; |
58
|
|
|
$params['password'] = urldecode($this->config['password']); |
59
|
|
|
$response = Http::get("{$this->baseUrl}$endpoint", $params); |
60
|
|
|
|
61
|
|
|
$responseObject = json_decode($response->body()); |
62
|
|
|
if (isset($responseObject->code) && isset($responseObject->message)) |
63
|
|
|
return new VtuDotNGResponse($responseObject->code, $responseObject->message, isset($responseObject->data) ? $responseObject->data : null); |
64
|
|
|
return new VtuDotNGResponse(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get Your wallet available balance, Wallet is identified by username set in vtung config or environmental variable |
69
|
|
|
* @return VtuDotNGResponse |
70
|
|
|
* @throws VtuDotNGErrorException |
71
|
|
|
*/ |
72
|
|
|
public function getWalletBalance(): VtuDotNGResponse |
73
|
|
|
{ |
74
|
|
|
return $this->withAuth('balance'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Purchase Airtime with py specifying the network (i.e. mtn, glo, airtel, or 9mobile to buy airtime corresponding the provided telco service code) |
79
|
|
|
* @param string $network The network_id is used to make each network unique. They include mtn, glo, airtel and etisalat. Notice that they are all in small letters. |
80
|
|
|
* @param int $amount The amount you wish to topup |
81
|
|
|
* @param string $phoneNumber The phone number that will receive the airtime |
82
|
|
|
* @return VtuDotNGResponse |
83
|
|
|
* |
84
|
|
|
* @throws VtuDotNGErrorException |
85
|
|
|
*/ |
86
|
|
|
public function purchaseAirtime(string $network, int $amount, $phoneNumber): VtuDotNGResponse |
87
|
|
|
{ |
88
|
|
|
return $this->withAuth('airtime', [ |
89
|
|
|
'network_id' => $network, |
90
|
|
|
'amount' => $amount, |
91
|
|
|
'phone' => $phoneNumber |
92
|
|
|
]); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Purchase Data Bundle |
98
|
|
|
* @param string $network The network_id is used to make each network unique. They include mtn, glo, airtel and etisalat. Notice that they are all in small letters. |
99
|
|
|
* @param string $plan The variation ID of the data plan you want to purchase. |
100
|
|
|
* @param string $phone The phone number that will receive the data |
101
|
|
|
* @return VtuDotNGResponse |
102
|
|
|
* @throws VtuDotNGErrorException |
103
|
|
|
*/ |
104
|
|
|
public function purchaseDataBundle(string $network, string $plan, string $phone): VtuDotNGResponse |
105
|
|
|
{ |
106
|
|
|
return $this->withAuth('data', [ |
107
|
|
|
'network_id' => $network, |
108
|
|
|
'variation_id' => $plan, |
109
|
|
|
'phone' => $phone |
110
|
|
|
]); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* We advise that you always verify the customer’s details before submitting requests to purchase the service (cable TV or electricity). The VTU.ng customer verification endpoint allows you to get the customer’s full name. |
116
|
|
|
* @param string $customerId This is either the customer’s smartcard number or the meter number |
117
|
|
|
* @param string $serviceId The service_id is unique for all cable TV and electricity services. They include dstv, gotv, startimes, abuja-electric, eko-electric, ibadan-electric, ikeja-electric, jos-electric, kaduna-electric, kano-electric and portharcout-electric. Notice that they are all in small letters. |
118
|
|
|
* @param string|null $variationId The meter type of the electricity company. This is only required for verifying the electricity customers and not required for cable TV customer verification. |
119
|
|
|
* @return VtuDotNGResponse |
120
|
|
|
* @throws VtuDotNGErrorException |
121
|
|
|
*/ |
122
|
|
|
private function verifyCustomer(string $customerId, string $serviceId, string $variationId = null): VtuDotNGResponse |
123
|
|
|
{ |
124
|
|
|
$params = [ |
125
|
|
|
'customer_id' => $customerId, |
126
|
|
|
'service_id' => $serviceId, |
127
|
|
|
]; |
128
|
|
|
if (!is_null($variationId)) |
129
|
|
|
$params['variation_id'] = $variationId; |
130
|
|
|
return $this->withAuth('verify-customer', $params); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Verify Customer Smart Card Number/IUC/Decoder Number verification |
136
|
|
|
* You need to verify your customer unique number before purchasing. |
137
|
|
|
* |
138
|
|
|
* @param string $cableTvType The $cableTvType is used to make each cable TV unique. They include dstv, gotv, and startimes. Notice that they are all in small letters. |
139
|
|
|
* @param string $smartCardNumber The smartcard/IUC number of the decoder that should be subscribed |
140
|
|
|
* @return VtuDotNGResponse |
141
|
|
|
* @throws VtuDotNGErrorException |
142
|
|
|
*/ |
143
|
|
|
public function verifyCableSmartCardNumber(string $cableTvType, string $smartCardNumber): VtuDotNGResponse |
144
|
|
|
{ |
145
|
|
|
return $this->verifyCustomer($smartCardNumber, $cableTvType); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Purchase DSTV or GoTv Cable Tv Plan |
150
|
|
|
* |
151
|
|
|
* |
152
|
|
|
* @param string $cableTvType The $cableTvType is used to make each cable TV unique. They include dstv, gotv, and startimes. Notice that they are all in small letters. |
153
|
|
|
* @param string $smartCardNumber The smartcard/IUC number of the decoder that should be subscribed |
154
|
|
|
* @param string $plan The $plan ID of the cable TV package/bouquet you want to purchase. They are as follows: |
155
|
|
|
* |
156
|
|
|
* dstv-padi = DStv Padi |
157
|
|
|
* dstv-yanga = DStv Yanga |
158
|
|
|
* dstv-confam = DStv Confam |
159
|
|
|
* dstv6 = DStv Asian |
160
|
|
|
* dstv79 = DStv Compact |
161
|
|
|
* dstv7 = DStv Compact Plus |
162
|
|
|
* dstv3 = DStv Premium |
163
|
|
|
* dstv10 = DStv Premium Asia |
164
|
|
|
* gotv-smallie = GOtv Smallie |
165
|
|
|
* gotv-jinja = GOtv Jinja |
166
|
|
|
* gotv-jolli = GOtv Jolli |
167
|
|
|
* gotv-max = GOtv Max |
168
|
|
|
* nova = Startimes Nova |
169
|
|
|
* basic = Startimes Basic |
170
|
|
|
* smart = Startimes Smart |
171
|
|
|
* classic = Startimes Classic |
172
|
|
|
* super = Startimes Super |
173
|
|
|
* |
174
|
|
|
* @param string $customerPhoneNumber The phone number that will be stored for reference |
175
|
|
|
* @return VtuDotNGResponse |
176
|
|
|
* @throws VtuDotNGErrorException |
177
|
|
|
*/ |
178
|
|
|
public function purchaseCableTvPlan(string $cableTvType, string $smartCardNumber, string $plan, string $customerPhoneNumber): VtuDotNGResponse |
179
|
|
|
{ |
180
|
|
|
return $this->withAuth('tv', [ |
181
|
|
|
"service_id" => $cableTvType, |
182
|
|
|
"smartcard_number" => $smartCardNumber, |
183
|
|
|
"variation_id" => $plan, |
184
|
|
|
"phone" => $customerPhoneNumber, |
185
|
|
|
]); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* We advise that you always verify the customer’s details before submitting requests to purchase the service (cable TV or electricity). The VTU.ng customer verification endpoint allows you to get the customer’s full name. |
190
|
|
|
* |
191
|
|
|
* Please note the service_id below: |
192
|
|
|
* Ikaja Electricity = <strong>ikeja-electric</strong> |
193
|
|
|
* Eko Electricity = <strong>eko-electric</strong> |
194
|
|
|
* Kano Electricity = <strong>kano-electric</strong> |
195
|
|
|
* Kaduna Electricity = <strong>Kaduna-electric</strong> |
196
|
|
|
* Port Harcourt Electricity = <strong>phed</strong> |
197
|
|
|
* Jos Electricity = <strong>jos-electric</strong> |
198
|
|
|
* Abuja Electricity = <strong>abuja-electric</strong> |
199
|
|
|
* Ibadan Electricity = <strong>ibadan-electric</strong> |
200
|
|
|
* |
201
|
|
|
* |
202
|
|
|
* @param string $disco The service_id is unique for all cable TV and electricity services. |
203
|
|
|
* @param string $meterNumber Meter Number to verify |
204
|
|
|
* @param string $meterType Meter type i.e. <strong>prepaid</strong> or <strong>postpaid</strong> |
205
|
|
|
* @return VtuDotNGResponse |
206
|
|
|
* @throws VtuDotNGErrorException |
207
|
|
|
*/ |
208
|
|
|
public function verifyMeterNumber(string $disco, string $meterNumber, string $meterType): VtuDotNGResponse |
209
|
|
|
{ |
210
|
|
|
return $this->verifyCustomer($meterNumber, $disco, $meterType); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Purchase Electricity |
215
|
|
|
* You can purchase electricity through our API and get instant token for prepaid meters. |
216
|
|
|
* |
217
|
|
|
* @param string $disco Unique code of the Electricity distribution company the meter number is for |
218
|
|
|
* The discos unique service_id is used to make each electricity company unique. They are as follows: |
219
|
|
|
* Ikaja Electricity = <strong>ikeja-electric</strong> |
220
|
|
|
* Eko Electricity = <strong>eko-electric</strong> |
221
|
|
|
* Kano Electricity = <strong>kano-electric</strong> |
222
|
|
|
* Kaduna Electricity = <strong>Kaduna-electric</strong> |
223
|
|
|
* Port Harcourt Electricity = <strong>phed</strong> |
224
|
|
|
* Jos Electricity = <strong>jos-electric</strong> |
225
|
|
|
* Abuja Electricity = <strong>abuja-electric</strong> |
226
|
|
|
* Ibadan Electricity = <strong>ibadan-electric</strong> |
227
|
|
|
* |
228
|
|
|
* @param string $meterNumber The meter number you want to purchase electricity for |
229
|
|
|
* @param string $meterType The meter type of electricity company you want to purchase. It is either prepaid or postpaid |
230
|
|
|
* @param int $amount The meter type of electricity company you want to purchase. It is either prepaid or postpaid |
231
|
|
|
* @param string $customerPhoneNumber The phone number that will be stored for reference |
232
|
|
|
* @return VtuDotNGResponse |
233
|
|
|
* @throws VtuDotNGErrorException |
234
|
|
|
*/ |
235
|
|
|
public function purchaseElectricity(string $disco, string $meterNumber, string $meterType, $amount, string $customerPhoneNumber): VtuDotNGResponse |
236
|
|
|
{ |
237
|
|
|
return $this->withAuth('electricity', [ |
238
|
|
|
"service_id" => $disco, |
239
|
|
|
"meter_number" => $meterNumber, |
240
|
|
|
"variation_id" => $meterType, |
241
|
|
|
"amount" => $amount, |
242
|
|
|
"phone" => $customerPhoneNumber, |
243
|
|
|
]); |
244
|
|
|
} |
245
|
|
|
} |
246
|
|
|
|