Guest User

Untitled

a guest
Jul 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. <?php
  2.  
  3. //$data is the json encoded pqyload from mpesa.
  4. // $data = json_decode(file_get_contents('php://input'));
  5. $data = file_get_contents('php://input');
  6. var_dump($data);
  7.  
  8. // $tmp = $data->Body->stkCallback;
  9. // $master = array();
  10. $con=mysqli_connect("localhost","id6518439_main","law46peri39","id6518439_daraja");
  11.  
  12. if (mysqli_connect_errno())
  13. {
  14. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  15. }
  16. else {
  17. echo "Connected Successfully to : localhost";
  18. }
  19. foreach($data->Body->stkCallback->CallbackMetadata->Item as $item){
  20. echo "data is the json encoded pqyload from mpesa.";
  21.  
  22. $amount = $item['Amount'];
  23. $receipt = $item['MpesaReceiptNumber'];
  24. $transactionDate = $item['TransactionDate'];
  25. $phone = $item['PhoneNumber'];
  26.  
  27. //Insert into table qr and transactions
  28.  
  29. $transact = "INSERT INTO transactions (phonenumber,amount,receipt,transday)
  30. VALUES ('$phone','$amount','$receipt','$transactionDate')";
  31.  
  32. // $qr =
  33. $exec = mysqli_query($con,$transact);
  34.  
  35. if($exec){
  36. echo "Data inserted";
  37. }else{
  38. echo "There was an error " . mysqli_error($con);
  39. }
  40.  
  41.  
  42. mysqli_close($con);
  43.  
  44. // $item = (array) $item;
  45. // $master[$item['Name']] = ((isset($item['Value'])) ? $item['Value'] : NULL);
  46.  
  47. }
  48. // var_damp($data);
  49. // $master = (object) $master;
  50. // $master->ResultCode = $tmp->ResultCode;
  51. // $master->MerchantRequestID = $tmp->MerchantRequestID;
  52. // $master->CheckoutRequestID = $tmp->CheckoutRequestID;
  53. // $master->ResultDesc = $tmp->ResultDesc;
  54.  
  55. // //Returns an object
  56. // return $master;
  57. // echo $master;
  58.  
  59. ?>
Add Comment
Please, Sign In to add comment