1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace HenryEjemuta\LaravelClubKonnect; |
4
|
|
|
|
5
|
|
|
use HenryEjemuta\LaravelClubKonnect\Classes\ClubKonnectResponse; |
6
|
|
|
use HenryEjemuta\LaravelClubKonnect\Enums\NetworkEnum; |
7
|
|
|
use Illuminate\Support\Facades\Http; |
8
|
|
|
|
9
|
|
|
class ClubKonnect |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* base url |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
private $baseUrl; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* the session key |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $instanceName; |
24
|
|
|
|
25
|
|
|
protected $config; |
26
|
|
|
|
27
|
|
|
public function __construct($baseUrl, $instanceName, $config) |
28
|
|
|
{ |
29
|
|
|
$this->baseUrl = $baseUrl; |
30
|
|
|
$this->instanceName = $instanceName; |
31
|
|
|
$this->config = $config; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* get instance name of the cart |
36
|
|
|
* |
37
|
|
|
* @return string |
38
|
|
|
*/ |
39
|
|
|
public function getInstanceName() |
40
|
|
|
{ |
41
|
|
|
return $this->instanceName; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $endpoint |
46
|
|
|
* @param array $params |
47
|
|
|
* @return ClubKonnectResponse |
48
|
|
|
*/ |
49
|
|
|
public function withAuth(string $endpoint, array $params = []): ClubKonnectResponse |
50
|
|
|
{ |
51
|
|
|
$params['UserID'] = $this->config['user_id']; |
52
|
|
|
$params['APIKey'] = urldecode($this->config['api_key']); |
53
|
|
|
$response = Http::get("{$this->baseUrl}$endpoint", $params); |
54
|
|
|
$responseObject = json_decode($response->body()); |
55
|
|
|
|
56
|
|
|
if ($response->getStatusCode() == 200) |
|
|
|
|
57
|
|
|
return new ClubKonnectResponse($responseObject); |
58
|
|
|
return new ClubKonnectResponse(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Check your Server IP |
63
|
|
|
* @return ClubKonnectResponse |
64
|
|
|
*/ |
65
|
|
|
public function checkYourServerIP(): ClubKonnectResponse |
66
|
|
|
{ |
67
|
|
|
return $this->withAuth('APIServerIPV1.asp'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get Your wallet available balance, Wallet is identified by username set in clubkonnect config or environmental variable |
72
|
|
|
* @return ClubKonnectResponse |
73
|
|
|
*/ |
74
|
|
|
public function getWalletBalance(): ClubKonnectResponse |
75
|
|
|
{ |
76
|
|
|
return $this->withAuth('APIWalletBalanceV1.asp'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param NetworkEnum $mobileNetwork |
81
|
|
|
* @param int $amount |
82
|
|
|
* @param $phoneNumber |
83
|
|
|
* @param $requestID |
84
|
|
|
* @param $callbackUrl |
85
|
|
|
* @return ClubKonnectResponse |
86
|
|
|
*/ |
87
|
|
View Code Duplication |
public function purchaseAirtime(NetworkEnum $mobileNetwork, int $amount, $phoneNumber, $requestID, $callbackUrl): ClubKonnectResponse |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
return $this->withAuth('APIAirtimeV1.asp', [ |
90
|
|
|
'MobileNetwork' => $mobileNetwork->getCode(), |
91
|
|
|
'Amount' => $amount, |
92
|
|
|
'MobileNumber' => $phoneNumber, |
93
|
|
|
'RequestID' => $requestID, |
94
|
|
|
'CallBackURL' => $callbackUrl |
95
|
|
|
]); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
private $transaction; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* ClubKonnect API Transaction handler to access: |
102
|
|
|
* CableTv()->queryByOrderID(string $orderID); |
103
|
|
|
* CableTv()->queryByRequestID(string $requestID); |
104
|
|
|
* CableTv()->cancelTransaction(string $orderID); |
105
|
|
|
* |
106
|
|
|
* @return Transaction |
107
|
|
|
*/ |
108
|
|
|
public function Transaction(): Transaction |
109
|
|
|
{ |
110
|
|
|
if (is_null($this->transaction)) |
111
|
|
|
$this->transaction = new class($this) extends Transaction { |
112
|
|
|
}; |
113
|
|
|
return $this->transaction; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
private $smile; |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Smile Bill handler to access: |
120
|
|
|
* CableTv()->getDataBundles(); |
121
|
|
|
* CableTv()->verifySmileAccountID($phoneNumber); |
122
|
|
|
* CableTv()->purchaseBundle(string $plan, string $phoneNumber, $requestID, $callbackUrl = null); |
123
|
|
|
* |
124
|
|
|
* @return Smile |
125
|
|
|
*/ |
126
|
|
|
public function Smile(): Smile |
127
|
|
|
{ |
128
|
|
|
if (is_null($this->smile)) |
129
|
|
|
$this->smile = new class($this, $this->config) extends Smile { |
130
|
|
|
}; |
131
|
|
|
return $this->smile; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
private $cableTv; |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Cable TV Bill handler to access: |
138
|
|
|
* CableTv()->getTvPackages(); |
139
|
|
|
* CableTv()->verifyCustomerID(CableTvEnum $cableTv, $smartCardNo); |
140
|
|
|
* CableTv()->purchasePackage(CableTvEnum $cableTv, string $package, $smartCardNo, $requestID, $callbackUrl = null); |
141
|
|
|
* |
142
|
|
|
* @return CableTv |
143
|
|
|
*/ |
144
|
|
|
public function CableTv(): CableTv |
145
|
|
|
{ |
146
|
|
|
if (is_null($this->cableTv)) |
147
|
|
|
$this->cableTv = new class($this, $this->config) extends CableTv { |
148
|
|
|
}; |
149
|
|
|
return $this->cableTv; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
private $rechargeCardPrinting; |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Recharge Card Printing handler to access: |
156
|
|
|
* RechargeCardPrinting()->getEPinNetworks(); |
157
|
|
|
* RechargeCardPrinting()->buyEPins(NetworkEnum $network, $amount, int $quantity, $requestID, $callbackUrl = null); |
158
|
|
|
* |
159
|
|
|
* @return RechargeCardPrinting |
160
|
|
|
*/ |
161
|
|
|
public function RechargeCardPrinting(): RechargeCardPrinting |
162
|
|
|
{ |
163
|
|
|
if (is_null($this->rechargeCardPrinting)) |
164
|
|
|
$this->rechargeCardPrinting = new class($this, $this->config) extends RechargeCardPrinting { |
165
|
|
|
}; |
166
|
|
|
return $this->rechargeCardPrinting; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Get all Data Bundles |
172
|
|
|
* @return ClubKonnectResponse |
173
|
|
|
*/ |
174
|
|
|
public function getDataBundles(): ClubKonnectResponse |
175
|
|
|
{ |
176
|
|
|
return $this->withAuth('APIDatabundlePlansV1.asp', []); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @param NetworkEnum $network |
182
|
|
|
* @param string $plan |
183
|
|
|
* @param string $phoneNumber |
184
|
|
|
* @param $requestID |
185
|
|
|
* @param $callbackUrl |
186
|
|
|
* @return ClubKonnectResponse |
187
|
|
|
*/ |
188
|
|
View Code Duplication |
public function purchaseDataBundle(NetworkEnum $network, string $plan, string $phoneNumber, $requestID, $callbackUrl): ClubKonnectResponse |
|
|
|
|
189
|
|
|
{ |
190
|
|
|
return $this->withAuth('APIDatabundleV1.asp', [ |
191
|
|
|
'MobileNetwork' => $network->getCode(), |
192
|
|
|
'DataPlan' => $plan, |
193
|
|
|
'MobileNumber' => $phoneNumber, |
194
|
|
|
'RequestID' => $requestID, |
195
|
|
|
'CallBackURL' => $callbackUrl |
196
|
|
|
]); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
|
200
|
|
|
private $electricity; |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Electricity Bills payment handler to access: |
204
|
|
|
* Electricity()->getDiscosAndMinMax(); |
205
|
|
|
* Electricity()->verifyMeterNumber(DiscoEnum $disco, $meterNumber): ClubKonnectResponse |
206
|
|
|
* Electricity()->buyElectricity(DiscoEnum $disco, $meterNumber, $amount, MeterTypeEnum $meterType, $requestID, $callbackUrl = null): ClubKonnectResponse |
207
|
|
|
* |
208
|
|
|
* @return Electricity |
209
|
|
|
*/ |
210
|
|
|
public function Electricity(): Electricity |
211
|
|
|
{ |
212
|
|
|
if (is_null($this->electricity)) |
213
|
|
|
$this->electricity = new class($this, $this->config) extends Electricity { |
214
|
|
|
}; |
215
|
|
|
return $this->electricity; |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.