-
Notifications
You must be signed in to change notification settings - Fork 74
/
MFCallback.php
executable file
·55 lines (41 loc) · 1.63 KB
/
MFCallback.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
//Require dependencies
require_once('dbConnector.php');
require_once('AfricasTalkingGateway.php');
require_once('config.php');
$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
// Process the data...
$category = $data["category"];
$status = $data["status"];
if ( $category == "MobileCheckout" && $status == "Success" ) {
// We have been paid by one of our customers!!
$phoneNumber = $data["source"];
$value = $data["value"];
$account = $data["clientAccount"];
$valueArray=explode(' ', $value);
$valAmt=trim(end($valueArray));
//string to int
$valAmt=+0;
//Find and update Creditor
$sql11d = "SELECT * FROM account WHERE phoneNumber LIKE '%".$phoneNumber."%' LIMIT 1";
$balQuery=$db->query($sql11d);
$balAvailable=$balQuery->fetch_assoc();
// Manage balance
if($balAvailable=$balQuery->fetch_assoc()){
$newBal = $valAmt + $balAvailable['balance'];
}
// Update the DBs
$sql11e = "UPDATE `account` SET `balance`='".$newBal."' WHERE `phonenumber` = '". $phoneNumber ."'";
$db->query($sql11e);
$sql11f = "UPDATE `checkout` SET `status`='received' WHERE `phonenumber` = '". $phoneNumber ."'";
$db->query($sql11f);
// SMS New Balance
$code = '20880';
$recipients = $phoneNumber;
$message = "We have sent ".$value." via".$userResponse." to Nerd Sacco. Your new balance is ".$newBal.". Thank you.";
$gateway = new AfricasTalkingGateway($username, $apikey);
try { $results = $gateway->sendMessage($recipients, $message, $code); }
catch ( AfricasTalkingGatewayException $e ) {echo "Encountered an error while sending: ".$e->getMessage(); }
}
?>