-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulate.php
52 lines (41 loc) · 1.68 KB
/
simulate.php
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
<?php
$headers = ['Content-Type:application/json; charset=utf8'];
$consumerKey = 'wdykjM693gdgMmzHOGAdA4A50fGsTPM7';
$consumerSecret = 'iiGI1SzEyJscEETW';
$access_token_url = 'https://sandbox.safaricom.co.ke/oauth/v1/generate?grant_type=client_credentials';
$curl = curl_init($access_token_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_USERPWD, $consumerKey.':'.$consumerSecret);
$result = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$result = json_decode($result);
$access_token = $result->access_token;
//echo($access_token);
curl_close($curl);
$url = 'https://sandbox.safaricom.co.ke/mpesa/c2b/v1/simulate';
// $access_token= '9OwXhaSHOjYg1pwNgekbYQ0Bs0Bc';
$ShortCode = '174739';
$amount = '500';
$msisdn = '254708374149';
$billRef = 'TEST009';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json','Authorization:Bearer '.$access_token)); //setting custom header
$curl_post_data = array(
//Fill in the request parameters with valid values
'ShortCode' => $ShortCode,
'CommandID' => 'CustomerPayBillOnline',
'Amount' => $amount,
'Msisdn' => $msisdn,
'BillRefNumber' => $billRef
);
$data_string = json_encode($curl_post_data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
$curl_response = curl_exec($curl);
print_r($curl_response);
echo $curl_response;
?>