Пример #1
0
 function process($name, $phone, $amount, $receipt)
 {
     $this->response_arr = array('RESULT' => 0, 'RESPONCE' => '', 'id' => 0);
     try {
         $pesa = new PLUSPEOPLE\PesaPi\PesaPi();
         $transactions = $pesa->locateByReceipt($receipt);
         dmp($transactions[0]);
         if (count($transactions) == 0) {
             $this->response_arr = array('RESULT' => '1', 'RESPONCE' => 'Pending, Incoming Mobile Money Transaction Not found ');
             throw new Exception('Pending, Incoming Mobile Money Transaction Not found ');
         } else {
             $transaction = $transactions[0];
             if ($transaction->getPhonenumber() != $phone) {
                 $this->response_arr = array('RESULT' => '8', 'RESPONCE' => 'Invalid phone');
                 throw new Exception('Invalid phone');
             } else {
                 if ($transaction->getName() != $name) {
                     $this->response_arr = array('RESULT' => '7', 'RESPONCE' => 'Invalid name');
                     throw new Exception('Invalid name');
                 } else {
                     if ($transaction->getAmount() < $amount) {
                         $this->response_arr = array('RESULT' => '3', 'RESPONCE' => 'Pending, Incoming Mobile Money Transaction Not found ');
                         throw new Exception('Pending, Incoming Mobile Money Transaction Not found');
                     } else {
                         if ($transaction->getAmount() > $amount) {
                             $this->response_arr = array('RESULT' => '4', 'RESPONCE' => 'Pending, Incoming Mobile Money Transaction Not found ');
                             throw new Exception('Pending, Incoming Mobile Money Transaction Not found');
                         }
                     }
                 }
             }
             $this->response_arr['id'] = $transaction->getId();
         }
     } catch (Exception $e) {
         throw $e;
     }
     return $this->response_arr;
 }
Пример #2
0
    // $_SESSION["phone"] = "phone";
}
//draw the receipt input box
?>
<html>
	<body>
		<form method="POST"	action="buy2.php">
			<input type="text" name="receipt" value=""><br>
			<input type= submit id="confirmation" value="Confirm">
		</form>
	</body>
</html>
<?php 
//check whether the receipt matches with database and conforms with the selected package
if (isset($_POST["receipt"])) {
    $transactions = $pesa->locateByReceipt($_POST["receipt"], "");
    if (count($transactions) > 0) {
        //connect to ticket database & give username and password based on the chosen package
        $con = mysqli_connect('localhost', 'root', '', '');
        $con2 = mysqli_connect('localhost', 'root', '', '');
        //check connection
        if (mysqli_connect_errno()) {
            echo "Failed to connect to MySQL: " . mysqli_connect_error();
        }
        //read receipt
        $package_receipt = mysqli_real_escape_string($con, $_POST['receipt']);
        //confirm that the package selected conforms with the amount received
        $package_query = "SELECT amount FROM pesapi_payment \n\t\t\t\t\t\t\t\tWHERE pesapi_payment.receipt = '{$package_receipt}'";
        $result_amount = mysqli_query($con2, $package_query);
        $result_amount2 = mysqli_fetch_object($result_amount);
        //echo $result_amount2->amount;