<?php
    $data = json_decode(file_get_contents('php://input'), true);
    
    $body = $data;
    $phone = $data['SenderMSISDN'];
    $amount = $data['TransactionAmount'];
    $code =$data['TransactionID'];
    
    file_put_contents('file.txt', json_encode($data));
   
   //consume the responses

 
$servername = "localhost";
$username = "candlest_tax";
$password = "candlest_tax";
$dbname = "candlest_tax";

//Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);


// Check connection
if (!$conn) {
  die("Connection failed: " . mysqli_connect_error());
}


  
 
     //update user who is already active

        $update = "UPDATE users SET balance = balance + $amount WHERE phone = '$phone'";

        $conn->query($update);






$conn->close();



mysqli_close($conn);
 

   
?>


<?php

 
// {
// 	"Body":
// 	{
// 		"pvpCallback":
// 		{
// 			"RequestID": "689734",
// 			"CheckoutRequestID": "ws_CO_100220202302034801",
// 			"CallbackMetadata":
// 			{
// 				"TransactionTime": "20200210230214",
// 				"TransactionID": "OBA0Z6O54H",
// 				"TransactionAmount": 10,
// 				"BusinessShortcode": "123456",
// 				"AccountReference": "689734",
// 				"SenderMSISDN": "254722000111",
// 				"SenderFirstName": "JOHN",
// 				"SenderMiddleName": null,
// 				"SenderLastName": "DOE",
// 				"DueDate": 1582477758,
// 				"Signature": "fS1APn44Uo...3vJYYwQSXc=",
// 				"PublicKey": "-----BEGIN RSA PUBLIC KEY-----\r\nMIGJAoGBAM...rVNAgMBAAE=\r\n-----END RSA PUBLIC KEY-----"
// 			}
// 		}
// 	}
// }

?>
