-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpayrequest.php
More file actions
83 lines (63 loc) · 2.36 KB
/
payrequest.php
File metadata and controls
83 lines (63 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
require 'vendor/autoload.php';
require 'functions.php';
use function GuzzleHttp\json_encode;
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__); //Notice the Namespace and Class name
$dotenv->load();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// get posted data
$data = json_decode(file_get_contents("php://input"));
$request_id = uniqid(time(), true);
$token = $data->token;
$otp = $data->otp;
$api_key = $_ENV['API_KEY'];
$api_auth = $_ENV['API_AUTH'];
$client = new GuzzleHttp\Client();
// Define array of request body.
$request_body = array(
'app_key'=> $api_key ,
'auth_key'=> $api_auth,
'key_type'=> 'business',
'request_id'=> $request_id,
'token'=> $token,
'otp'=> $otp,
'method'=> 'mobile_money',
);
try {
$response = $client->request('POST',BASE_URL.'ra_mmpayrequest', array(
'json' => $request_body
)
);
print_r($response->getBody()->getContents());
} catch (\GuzzleHttp\Exception\RequestException $e) {
// handle exception or api errors.
print_r($e->getMessage());
}
}else{
echo json_encode(array("message" => "Request is not accepted"));
}
function get_uuid()
{
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
// 16 bits for "time_mid"
mt_rand(0, 0xffff),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand(0, 0x0fff) | 0x4000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand(0, 0x3fff) | 0x8000,
// 48 bits for "node"
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
);
}
?>