forked from wigalgh/smartussd_api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ussdflow.php
185 lines (161 loc) · 8.76 KB
/
ussdflow.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
<?php
include('include/connect.php');
include('functions.php');
$MSISDN = $_GET['msisdn'];
$SESSION_ID =$_GET['sessionid'];
$NETWORKID = $_GET['network'];
$MODE = $_GET['mode'];
$DATA = $_GET['userdata'];
$USERNAME= $_GET['username'];
$TRAFFIC_ID= $_GET['trafficid'];
$TIME=date("Y/m/d h:i:s");
$today=date("Y-m-d");
$RESPONSE_DATA = "";
$mobile_moneyApi="https://api.reddeonline.com/v1/receive";
$nickname="bakeside";
$welcome="Welcome to Bakeside Campaign.^Select your Option:^^1. Donate ^2. Volunteer";
//STEP ONE CHECK IF ITS START OF SESSION
if ($MODE=="start")
{
deleteTracking($MSISDN);
insertTracking($MSISDN,$SESSION_ID,$MODE,$USERNAME,$TIME,'1','1');
$RESPONSE_DATA = "$NETWORKID|MORE|$MSISDN|$SESSION_ID|$welcome|$USERNAME |$TRAFFIC_ID";
echo $RESPONSE_DATA;
deleteProgress($MSISDN);
insertProgress($MSISDN,$SESSION_ID,'','','',$NETWORKID,'','','','');
}
else
{
$row =getTracking($MSISDN);
$userData=$row['userData'];
$track=$row['track'];
$rowopt = getProgress($MSISDN);
$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'];
$constituency=$rowopt['constituency'];
switch ($track)
{
case "1":
if($DATA == '1'){
updateTracking($MSISDN,$SESSION_ID,$MODE,$USERNAME,$TIME,$DATA,'2');
$RESPONSE_DATA = "$NETWORKID|MORE|$MSISDN|$SESSION_ID|Enter your Full Name (First - Middle - Surname) to donate:|$USERNAME |$TRAFFIC_ID";
echo htmlspecialchars($RESPONSE_DATA);
updateProgress($MSISDN,$SESSION_ID,"option","Donate");
}
elseif ($DATA == '2') {
updateTracking($MSISDN,$SESSION_ID,$MODE,$USERNAME,$TIME,$DATA,'2');
$RESPONSE_DATA = "$NETWORKID|MORE|$MSISDN|$SESSION_ID|Enter your Full Name (First - Middle - Surname) to Volunteer:|$USERNAME |$TRAFFIC_ID";
echo htmlspecialchars($RESPONSE_DATA);
updateProgress($MSISDN,$SESSION_ID,"option","Volunteer");
}
else{
updateTracking($MSISDN,$SESSION_ID,$MODE,$USERNAME,$TIME,$DATA,'1');
$RESPONSE_DATA = "$NETWORKID|MORE|$MSISDN|$SESSION_ID|$welcome|$USERNAME |$TRAFFIC_ID";
echo htmlspecialchars($RESPONSE_DATA);
}
break;
case "2":
if ($option == 'Donate') {
updateTracking($MSISDN,$SESSION_ID,$MODE,$USERNAME,$TIME,$DATA,'3');
$RESPONSE_DATA = "$NETWORKID|MORE|$MSISDN|$SESSION_ID|Enter Amount to Donate: |$USERNAME |$TRAFFIC_ID";
echo htmlspecialchars($RESPONSE_DATA);
updateProgress($MSISDN,$SESSION_ID,"donor_name",$DATA);
}
elseif($option == 'Volunteer') {
updateTracking($MSISDN,$SESSION_ID,$MODE,$USERNAME,$TIME,$DATA,'3');
$RESPONSE_DATA = "$NETWORKID|MORE|$MSISDN|$SESSION_ID|Enter Age:|$USERNAME |$TRAFFIC_ID";
echo htmlspecialchars($RESPONSE_DATA);
updateProgress($MSISDN,$SESSION_ID,"volunteer_name",$DATA);
}
break;
case "3":
if ($option == 'Donate') {
if(is_numeric($DATA)) {
$fetchdis = getProgress($MSISDN);
$walletno=$fetchdis['ID'];
$donor_name=$fetchdis['donor_name'];
$network=$fetchdis['network'];
updateTracking($MSISDN,$SESSION_ID,$MODE,$USERNAME,$TIME,$DATA,'4');
$RESPONSE_DATA = "$NETWORKID|MORE|$MSISDN|$SESSION_ID|Confirm Donation Summary^Name: $donor_name ^Amount: GHS $DATA^$network Wallet Num: $walletno ^^1. Yes^2. No |$USERNAME |$TRAFFIC_ID";
echo echo htmlspecialchars($RESPONSE_DATA);
updateProgress($MSISDN,$SESSION_ID,"amount",$DATA);
}
else {
updateTracking($MSISDN,$SESSION_ID,$MODE,$USERNAME,$TIME,$DATA,'3');
$RESPONSE_DATA = "$NETWORKID|MORE|$MSISDN|$SESSION_ID|Invalid Amount inputted, Kindly ensure you enter a valid numeric amount.|$USERNAME |$TRAFFIC_ID";
echo $RESPONSE_DATA;
updateProgress($MSISDN,$SESSION_ID,"amount",$DATA);
}
}
elseif($option == 'Volunteer') {
if (is_numeric($DATA)) {
updateTracking($MSISDN,$SESSION_ID,$MODE,$USERNAME,$TIME,$DATA,'4');
$RESPONSE_DATA = "$NETWORKID|MORE|$MSISDN|$SESSION_ID|Enter your Constituency:|$USERNAME |$TRAFFIC_ID";
echo $RESPONSE_DATA;
updateProgress($MSISDN,$SESSION_ID,"age",$DATA);
}
else{
updateTracking($MSISDN,$SESSION_ID,$MODE,$USERNAME,$TIME,$DATA,'3');
$RESPONSE_DATA = "$NETWORKID|MORE|$MSISDN|$SESSION_ID|Invalid Age inputted, Kindly ensure you enter a valid Age.|$USERNAME |$TRAFFIC_ID";
echo $RESPONSE_DATA;
updateProgress($MSISDN,$SESSION_ID,"age",$DATA);
}
}
break;
case "4":
if ($option == 'Donate') {
if($DATA=='1'){
$fetchdis = getProgress($MSISDN);
$walletno=$fetchdis['ID'];
$donor_name=$fetchdis['donor_name'];
$network=$fetchdis['network'];
updateTracking($MSISDN,$SESSION_ID,$MODE,$USERNAME,$TIME,$DATA,'5');
insertTransaction($amount,$donor_name,$walletno,$network);
$RESPONSE_DATA = "$NETWORKID|END|$MSISDN|$SESSION_ID|Your payment request has been initiated. Kindly approve the payment prompt from $network.|$USERNAME |$TRAFFIC_ID";
echo $RESPONSE_DATA;
}
else{
updateTracking($MSISDN,$SESSION_ID,$MODE,$USERNAME,$TIME,$DATA,'5');
$RESPONSE_DATA = "$NETWORKID|END|$MSISDN|$SESSION_ID|Payment Cancelled.Thanks for using our system|$USERNAME |$TRAFFIC_ID";
echo $RESPONSE_DATA;
}
}
elseif($option== 'Volunteer') {
$fetchdis = getProgress($MSISDN);
$volunteer_name=$fetchdis['volunteer_name'];
$age=$fetchdis['age'];
updateTracking($MSISDN,$SESSION_ID,$MODE,$USERNAME,$TIME,$DATA,'5');
$RESPONSE_DATA = "$NETWORKID|MORE|$MSISDN|$SESSION_ID|Confirm Summary^Name: $volunteer_name ^Age: $age^Constituency: $DATA ^^1. Yes^2. No |$USERNAME |$TRAFFIC_ID";
echo $RESPONSE_DATA;
updateProgress($MSISDN,$SESSION_ID,"constituency",$DATA);
}
break;
case "5":
if ($option=='Volunteer') {
if($DATA=="1"){
$fetchdis = getProgress($MSISDN);
$full_name=$fetchdis['volunteer_name'];
$mobile_number=$fetchdis['ID'];
$age=$fetchdis['age'];
$constituency=$fetchdis['constituency'];
$message= "Thank you $full_name from $constituency Constiteuncy for voluntering with Bakeside.";
updateTracking($MSISDN,$SESSION_ID,$MODE,$USERNAME,$TIME,$DATA,'6');
insertvolunteer($full_name,$mobile_number,$age,$constituency);
sendSMS($mobile_number,$message);
$RESPONSE_DATA = "$NETWORKID|END|$MSISDN|$SESSION_ID|Thank you for Volunteering with Bakeside.|$USERNAME |$TRAFFIC_ID";
echo $RESPONSE_DATA;
}else{
updateTracking($MSISDN,$SESSION_ID,$MODE,$USERNAME,$TIME,$DATA,'6');
$RESPONSE_DATA = "$NETWORKID|END|$MSISDN|$SESSION_ID|Request Cancelled. Thanks for using our system.|$USERNAME |$TRAFFIC_ID";
echo $RESPONSE_DATA;
}
}
break;
}
}
?>