public function stkpush(Request $request) { $url='https://sandbox.safaricom.co.ke/mpesa/stkpush/v1/processrequest'; $curl_post_data=[ 'BusinessShortCode'=>174379, 'Password'=>$this->lipanampesapassword(), 'Timestamp'=>Carbon::rawParse('now')->format('YmdHms'), 'TransactionType'=> "CustomerPayBillOnline", 'Amount'=>1, 'PartyA'=>254712345678, 'PartyB'=>174379, 'PhoneNumber'=>254712345678, 'CallBackURL'=>'https://89af-196-202-210-53.eu.ngrok.io/api/mpesa/callbackurl', 'AccountReference'=>'Waweru Enterprises', 'TransactionDesc'=>'Paying for Products Bought' ]; $data_string=json_encode($curl_post_data); $curl=curl_init(); curl_setopt($curl,CURLOPT_URL,$url); curl_setopt($curl,CURLOPT_HTTPHEADER,array('Content-Type:application/json','Authorization:Bearer '.$this->newaccesstoken())); curl_setopt($curl,CURLOPT_RETURNTRANSFER,true); curl_setopt($curl,CURLOPT_POST,true); curl_setopt($curl,CURLOPT_POSTFIELDS,$data_string); $curl_response=curl_exec($curl); return $curl_response; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter