|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Djunehor\Vtu\Concrete; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use GuzzleHttp\Exception\ClientException; |
|
7
|
|
|
use GuzzleHttp\Psr7\Request; |
|
8
|
|
|
|
|
9
|
|
|
class CowrieSys extends Vtu |
|
10
|
|
|
{ |
|
11
|
|
|
private $baseUrl ='https://api.cowriesys.com'; |
|
12
|
|
|
|
|
13
|
1 |
|
public function __construct($clientId = null, $clientKey = null) |
|
14
|
|
|
{ |
|
15
|
1 |
|
$this->username = $clientId ?? config('laravel-vtu.cowriesys.client_id'); |
|
16
|
1 |
|
$this->password = $clientKey ?? config('laravel-vtu.cowriesys.client_key'); |
|
17
|
|
|
|
|
18
|
1 |
|
$this->client = $this->getInstance(); |
|
19
|
|
|
|
|
20
|
1 |
|
} |
|
21
|
|
|
|
|
22
|
1 |
|
function sign($message) { |
|
|
|
|
|
|
23
|
1 |
|
return base64_encode(hash_hmac('sha256', $message, base64_decode($this->password), true)); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
1 |
View Code Duplication |
public function buyAirtime($amount, $mobileNumber, $mobileNetwork, $callbackUrl = null) : bool { |
|
|
|
|
|
|
27
|
1 |
|
$nonce = uniqid(); |
|
28
|
1 |
|
$queryString = '?net='.$mobileNetwork.'&msisdn='.$mobileNumber.'&amount='.$amount.'&xref='.$nonce; |
|
29
|
1 |
|
$signature = $this->sign($nonce.$queryString); |
|
30
|
|
|
$headers = [ |
|
31
|
1 |
|
'ClientId: '.$this->username, |
|
32
|
1 |
|
'Signature: '.$signature, |
|
33
|
1 |
|
'Nonce: '.$nonce |
|
34
|
|
|
]; |
|
35
|
1 |
|
$api = '/airtime/Credit'; |
|
36
|
1 |
|
$this->request = new Request('GET', $this->baseUrl.$api, $headers); |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
try { |
|
40
|
1 |
|
$response = $this->client->send($this->request, [ |
|
41
|
|
|
'query' => [ |
|
42
|
1 |
|
'net' => $mobileNetwork, |
|
43
|
1 |
|
'msisdn' => $mobileNumber, |
|
44
|
1 |
|
'amount' => $amount, |
|
45
|
1 |
|
'xref' => $nonce, |
|
46
|
|
|
], |
|
47
|
|
|
]); |
|
48
|
|
|
|
|
49
|
|
|
$response = json_decode($response->getBody()->getContents(), true); |
|
50
|
|
|
$this->response = $response; |
|
51
|
|
|
|
|
52
|
|
|
return $response ? true : false; |
|
53
|
1 |
|
} catch (ClientException $e) { |
|
54
|
1 |
|
$this->httpError = $e; |
|
55
|
|
|
|
|
56
|
1 |
|
return false; |
|
57
|
|
|
} catch (\Exception $e) { |
|
58
|
|
|
$this->httpError = $e; |
|
59
|
|
|
|
|
60
|
|
|
return false; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
View Code Duplication |
public function buyData($amount, $mobileNumber, $mobileNetwork, $callbackUrl = null) : bool { |
|
|
|
|
|
|
65
|
|
|
$nonce = uniqid(); |
|
66
|
|
|
$queryString = '?net='.$mobileNetwork.'&msisdn='.$mobileNumber.'&amount='.$amount.'&xref='.$nonce; |
|
67
|
|
|
$signature = $this->sign($nonce.$queryString); |
|
68
|
|
|
$headers = [ |
|
69
|
|
|
'ClientId: '.$this->username, |
|
70
|
|
|
'Signature: '.$signature, |
|
71
|
|
|
'Nonce: '.$nonce |
|
72
|
|
|
]; |
|
73
|
|
|
$api = '/data/Credit'; |
|
74
|
|
|
$this->request = new Request('GET', $this->baseUrl.$api, $headers); |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
try { |
|
78
|
|
|
$response = $this->client->send($this->request, [ |
|
79
|
|
|
'query' => [ |
|
80
|
|
|
'net' => $mobileNetwork, |
|
81
|
|
|
'msisdn' => $mobileNumber, |
|
82
|
|
|
'amount' => $amount, |
|
83
|
|
|
'xref' => $nonce, |
|
84
|
|
|
], |
|
85
|
|
|
]); |
|
86
|
|
|
|
|
87
|
|
|
$response = json_decode($response->getBody()->getContents(), true); |
|
88
|
|
|
$this->response = $response; |
|
89
|
|
|
|
|
90
|
|
|
return $response ? true : false; |
|
91
|
|
|
} catch (ClientException $e) { |
|
92
|
|
|
$this->httpError = $e; |
|
93
|
|
|
|
|
94
|
|
|
return false; |
|
95
|
|
|
} catch (\Exception $e) { |
|
96
|
|
|
$this->httpError = $e; |
|
97
|
|
|
|
|
98
|
|
|
return false; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @inheritDoc |
|
104
|
|
|
*/ |
|
105
|
|
|
public function payUtility($smartCardNumber, $cableTv, $package, $callBackUrl): bool |
|
106
|
|
|
{ |
|
107
|
|
|
return false; |
|
108
|
|
|
} |
|
109
|
|
|
} |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.