| @@ 26-62 (lines=37) @@ | ||
| 23 | return base64_encode(hash_hmac('sha256', $message, base64_decode($this->password), true)); |
|
| 24 | } |
|
| 25 | ||
| 26 | public function buyAirtime($amount, $mobileNumber, $mobileNetwork, $callbackUrl = null) : bool { |
|
| 27 | $nonce = uniqid(); |
|
| 28 | $queryString = '?net='.$mobileNetwork.'&msisdn='.$mobileNumber.'&amount='.$amount.'&xref='.$nonce; |
|
| 29 | $signature = $this->sign($nonce.$queryString); |
|
| 30 | $headers = [ |
|
| 31 | 'ClientId: '.$this->username, |
|
| 32 | 'Signature: '.$signature, |
|
| 33 | 'Nonce: '.$nonce |
|
| 34 | ]; |
|
| 35 | $api = '/airtime/Credit'; |
|
| 36 | $this->request = new Request('GET', $this->baseUrl.$api, $headers); |
|
| 37 | ||
| 38 | ||
| 39 | try { |
|
| 40 | $response = $this->client->send($this->request, [ |
|
| 41 | 'query' => [ |
|
| 42 | 'net' => $mobileNetwork, |
|
| 43 | 'msisdn' => $mobileNumber, |
|
| 44 | 'amount' => $amount, |
|
| 45 | 'xref' => $nonce, |
|
| 46 | ], |
|
| 47 | ]); |
|
| 48 | ||
| 49 | $response = json_decode($response->getBody()->getContents(), true); |
|
| 50 | $this->response = $response; |
|
| 51 | ||
| 52 | return $response ? true : false; |
|
| 53 | } catch (ClientException $e) { |
|
| 54 | $this->httpError = $e; |
|
| 55 | ||
| 56 | return false; |
|
| 57 | } catch (\Exception $e) { |
|
| 58 | $this->httpError = $e; |
|
| 59 | ||
| 60 | return false; |
|
| 61 | } |
|
| 62 | } |
|
| 63 | ||
| 64 | public function buyData($amount, $mobileNumber, $mobileNetwork, $callbackUrl = null) : bool { |
|
| 65 | $nonce = uniqid(); |
|
| @@ 64-100 (lines=37) @@ | ||
| 61 | } |
|
| 62 | } |
|
| 63 | ||
| 64 | 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 |
|