forked from bnjunge/MPESA-API-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulate.php
31 lines (25 loc) · 1.18 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
<?php
$url = 'https://sandbox.safaricom.co.ke/mpesa/c2b/v1/simulate';
$access_token = ''; // check file mpesa_accesstoken.php.
$ShortCode = ''; // Shortcode. Same as the one on register_url.php
$amount = ''; // amount the client/we are paying to the paybill
$msisdn = ''; // phone number paying
$billRef = ''; // This is anything that helps identify the specific transaction. Can be a clients ID, Account Number, Invoice amount, cart no.. etc
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json','Authorization:Bearer '.$access_token));
$curl_post_data = array(
'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;
?>