Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //$data is the json encoded pqyload from mpesa.
- // $data = json_decode(file_get_contents('php://input'));
- $data = file_get_contents('php://input');
- var_dump($data);
- // $tmp = $data->Body->stkCallback;
- // $master = array();
- $con=mysqli_connect("localhost","id6518439_main","law46peri39","id6518439_daraja");
- if (mysqli_connect_errno())
- {
- echo "Failed to connect to MySQL: " . mysqli_connect_error();
- }
- else {
- echo "Connected Successfully to : localhost";
- }
- foreach($data->Body->stkCallback->CallbackMetadata->Item as $item){
- echo "data is the json encoded pqyload from mpesa.";
- $amount = $item['Amount'];
- $receipt = $item['MpesaReceiptNumber'];
- $transactionDate = $item['TransactionDate'];
- $phone = $item['PhoneNumber'];
- //Insert into table qr and transactions
- $transact = "INSERT INTO transactions (phonenumber,amount,receipt,transday)
- VALUES ('$phone','$amount','$receipt','$transactionDate')";
- // $qr =
- $exec = mysqli_query($con,$transact);
- if($exec){
- echo "Data inserted";
- }else{
- echo "There was an error " . mysqli_error($con);
- }
- mysqli_close($con);
- // $item = (array) $item;
- // $master[$item['Name']] = ((isset($item['Value'])) ? $item['Value'] : NULL);
- }
- // var_damp($data);
- // $master = (object) $master;
- // $master->ResultCode = $tmp->ResultCode;
- // $master->MerchantRequestID = $tmp->MerchantRequestID;
- // $master->CheckoutRequestID = $tmp->CheckoutRequestID;
- // $master->ResultDesc = $tmp->ResultDesc;
- // //Returns an object
- // return $master;
- // echo $master;
- ?>
Add Comment
Please, Sign In to add comment