User1191534073 posted
Hi, I have the simple code below here, can anyone help me to write this simple function of php in c#... I will appreciate...
public function Process()
{
$amount = 1;
$phone = '0720068822';
$account='123';
$phone2= '254'.substr($phone, 1);
$url = 'https://sandbox.safaricom.co.ke/mpesa/stkpush/v1/processrequest';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
$app_consumer_key = 'T3PUFNac2pCObhtQgIStX485Depa4bqR';
$app_consumer_secret = 'rr3DqquSy3frc3GD';
$token='d2GrLikTPafLwVAGt0miKbgDCIZs';
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json','Authorization:Bearer '.$token)); //setting custom header
$timestamp =date('YmdHis');
// dd($timestamp);
$passkey = "bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919";
$short_code = "174379";
$password = base64_encode($short_code . $passkey . $timestamp);
$callback_url="enter your callback url here"';
$curl_post_data = array(
//Fill in the request parameters with valid values
"BusinessShortCode" => $short_code,
"Password" => $password,
"Timestamp" => $timestamp,
"TransactionType" => "CustomerPayBillOnline",
"Amount" => $amount,
"PartyA" => $phone2,
"PartyB" => $short_code,
"PhoneNumber" => $phone2,
"CallBackURL" => $callback_url,
"AccountReference" => $account,
"TransactionDesc" => "Paybill Online"
);
$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);
$merchant_info=json_decode($curl_response);
$merchant_id=$merchant_info->MerchantRequestID;
return $merchant_id;
}