-
Notifications
You must be signed in to change notification settings - Fork 0
/
ussd.php
executable file
·195 lines (176 loc) · 11.2 KB
/
ussd.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
include('include/connect.php');
include('functions.php');
$TIME=date("Y/m/d h:i:s");
$today=date("Y-m-d");
$mobile_moneyApi="https://api.reddeonline.com/v1/receive";
$nickname="bakesidev2";
$welcome="Welcome to Bakeside Campaign Version 2\n Select your Option:\n^1. Donate ^2. Volunteer";
$data = @file_get_contents('php://input');
$dataobj = json_decode($data);
$DATA = $dataobj->userdata;
if(!empty($data) && is_object($dataobj))
{
//STEP ONE CHECK IF ITS START OF SESSION
if(strtolower($dataobj->mode) == 'start')
{
// var_dump($dataobj);
deleteTracking($dataobj->phonenumber);
insertTracking($dataobj->phonenumber,$dataobj->sessionid,$dataobj->mode,$dataobj->username,$TIME,'1','1');
$dataobj->mode = "more";
$dataobj->userdata = $welcome;
deleteProgress($dataobj->phonenumber);
insertProgress($dataobj->phonenumber,$dataobj->sessionid,'','','',$dataobj->network,'','','','');
}
else
{
$row =getTracking($dataobj->phonenumber);
$userData=$row['userData'];
$track=$row['track'];
$rowopt = getProgress($dataobj->phonenumber);
$option=$rowopt['option'];
$donor_name=$rowopt['donor_name'];
$amount=$rowopt['amount'];
$network=$rowopt['network'];
$walletno=$rowopt['walletno'];
$volunteer_name=$rowopt['volunteer_name'];
$age=$rowopt['age'];
$email=$rowopt['email'];
switch ($track)
{
case "1":
if($dataobj->userdata == '1'){
updateTracking($dataobj->phonenumber,$dataobj->sessionid,$dataobj->mode,$dataobj->username,$TIME,$DATA,'2');
$dataobj->mode = "more";
$dataobj->userdata = "Enter your Full Name (First - Middle - Surname) to donate:";
updateProgress($dataobj->phonenumber,$dataobj->sessionid,"option","Donate");
}
elseif ($dataobj->userdata == '2') {
updateTracking($dataobj->phonenumber,$dataobj->sessionid,$dataobj->mode,$dataobj->username,$TIME,$DATA,'2');
$dataobj->mode = "more";
$dataobj->userdata = "Enter your Full Name (First - Middle - Surname) to Volunteer:";
updateProgress($dataobj->phonenumber,$dataobj->sessionid,"option","Volunteer");
}
else{
updateTracking($dataobj->phonenumber,$dataobj->sessionid,$dataobj->mode,$dataobj->username,$TIME,$DATA,'1');
$dataobj->mode = "more";
$dataobj->userdata = $welcome;
}
break;
case "2":
if ($option == 'Donate') {
updateTracking($dataobj->phonenumber,$dataobj->sessionid,$dataobj->mode,$dataobj->username,$TIME,$dataobj->userdata,'3');
$dataobj->mode = "more";
$dataobj->userdata = "Enter Amount to Donate: ";
updateProgress($dataobj->phonenumber,$dataobj->sessionid,"donor_name",$DATA);
}
elseif($option == 'Volunteer') {
updateTracking($dataobj->phonenumber,$dataobj->sessionid,$dataobj->mode,$dataobj->username,$TIME,$dataobj->userdata,'3');
$dataobj->mode = "more";
$dataobj->userdata = "Enter Age: ";
updateProgress($dataobj->phonenumber,$dataobj->sessionid,"volunteer_name",$DATA);
}
break;
case "3":
if ($option == 'Donate') {
if(is_numeric($DATA)) {
$fetchdis = getProgress($dataobj->phonenumber);
$walletno=$fetchdis['ID'];
$donor_name=$fetchdis['donor_name'];
$network=$fetchdis['network'];
updateTracking($dataobj->phonenumber,$dataobj->sessionid,$dataobj->mode,$dataobj->username,$TIME,$dataobj->userdata,'4');
$dataobj->mode = "more";
$dataobj->userdata = "Confirm Donation Summary^Name: $donor_name ^Amount: GHS $DATA^$network Wallet Num: $walletno ^^1. Yes^2. No ";
updateProgress($dataobj->phonenumber,$dataobj->sessionid,"amount",$DATA);
}
else {
updateTracking($dataobj->phonenumber,$dataobj->sessionid,$dataobj->mode,$dataobj->username,$TIME,$dataobj->userdata,'3');
$dataobj->mode = "more";
$dataobj->userdata = "Invalid Amount inputted, Kindly ensure you enter a valid numeric amount. ";
updateProgress($dataobj->phonenumber,$dataobj->sessionid,"amount",$DATA);
}
}
elseif($option == 'Volunteer') {
if (is_numeric($DATA)) {
updateTracking($dataobj->phonenumber,$dataobj->sessionid,$dataobj->mode,$dataobj->username,$TIME,$DATA,'4');
$dataobj->mode = "more";
$dataobj->userdata = "Enter your Email Address: ";
updateProgress($dataobj->phonenumber,$dataobj->sessionid,"age",$DATA);
}
else{
updateTracking($dataobj->phonenumber,$dataobj->sessionid,$dataobj->mode,$dataobj->username,$TIME,$DATA,'3');
$dataobj->mode = "more";
$dataobj->userdata = "Invalid Age inputted, Kindly ensure you enter a valid Age. ";
updateProgress($dataobj->phonenumber,$dataobj->sessionid,"age",$DATA);
}
}
break;
case "4":
if ($option == 'Donate') {
if($DATA=='1'){
$fetchdis = getProgress($dataobj->phonenumber);
$walletno=$fetchdis['ID'];
$donor_name=$fetchdis['donor_name'];
$network=$fetchdis['network'];
$amount=$fetchdis['amount'];
updateTracking($dataobj->phonenumber,$dataobj->sessionid,$dataobj->mode,$dataobj->username,$TIME,$DATA,'5');
$dataobj->mode = "END";
$dataobj->userdata = "Your payment request has been initiated. Kindly approve the payment prompt from $network.";
echo json_encode($dataobj);
session_write_close(); //close the USSD seesion
fastcgi_finish_request(); //close the USSD seesion
sleep(5); //wait for 3 seconds to iniate the payment request
insertTransaction($amount,$donor_name,$walletno,$network,$dataobj->trafficid);
}
else{
updateTracking($dataobj->phonenumber,$dataobj->sessionid,$dataobj->mode,$dataobj->username,$TIME,$DATA,'5');
$dataobj->mode = "end";
$dataobj->userdata = "Payment Cancelled. Thanks for using our system ";
}
}
elseif($option== 'Volunteer') {
if (filter_var($DATA, FILTER_VALIDATE_EMAIL)) {
$fetchdis = getProgress($dataobj->phonenumber);
$volunteer_name=$fetchdis['volunteer_name'];
$age=$fetchdis['age'];
updateTracking($dataobj->phonenumber,$dataobj->sessionid,$dataobj->mode,$dataobj->username,$TIME,$DATA,'5');
$dataobj->mode = "more";
$dataobj->userdata = "Confirm Summary^Name: $volunteer_name ^Age: $age^Email: $DATA ^^1. Yes^2. No ";
updateProgress($dataobj->phonenumber,$dataobj->sessionid,"email",$DATA);
}
else{
updateTracking($dataobj->phonenumber,$dataobj->sessionid,$dataobj->mode,$dataobj->username,$TIME,$DATA,'4');
$dataobj->mode = "more";
$dataobj->userdata = "Invalid Email inputted, Kindly ensure you enter a valid Email. ";
updateProgress($dataobj->phonenumber,$dataobj->sessionid,"email",$DATA);
}
}
break;
case "5":
if ($option=='Volunteer') {
if($DATA=="1"){
$fetchdis = getProgress($dataobj->phonenumber);
$full_name=$fetchdis['volunteer_name'];
$mobile_number=$fetchdis['ID'];
$age=$fetchdis['age'];
$email=$fetchdis['email'];
$message= "Thank you $full_name with the email address $email for voluntering with Bakeside.";
updateTracking($dataobj->phonenumber,$dataobj->sessionid,$dataobj->mode,$dataobj->username,$TIME,$DATA,'6');
insertvolunteer($full_name,$mobile_number,$age,$email);
sendSMS($mobile_number,$message);
sendEmai($email,$message);
sendVoice($mobile_number,$message);
$dataobj->mode = "end";
$dataobj->userdata = "Thank you for Volunteering with Bakeside. ";
}else{
updateTracking($dataobj->phonenumber,$dataobj->sessionid,$dataobj->mode,$dataobj->username,$TIME,$DATA,'6');
$dataobj->mode = "end";
$dataobj->userdata = "Request Cancelled. Thanks for using our system. ";
}
}
break;
}
}
}
echo json_encode($dataobj);
?>