예제 #1
0
 public function index(Request $request)
 {
     //get inputs
     $sessionId = $request->get('sessionId');
     $serviceCode = $request->get('serviceCode');
     $phoneNumber = $request->get('phoneNumber');
     $text = $request->get('text');
     /**
      * log all ussd requests
      */
     UssdLogs::create(['phone' => $phoneNumber, 'text' => $text, 'session_id' => $sessionId, 'service_code' => $serviceCode]);
     $no = substr($phoneNumber, -9);
     //verify that the user exists
     $user = UssdUser::where('phone', "0" . $no)->orWhere('phone', "+254" . $no)->first();
     if (!$user) {
         $data = ['phone' => $phoneNumber, 'session' => 0, 'progress' => 0, 'pin' => 0, 'menu_id' => 0, 'menu_item_id' => 0];
         $user = Ussduser::create($data);
     }
     if ($this->user_is_starting($text)) {
         $user->menu_id = 1;
         $user->session = 1;
         $user->progress = 0;
         $user->save();
         $menu = BundlesMenu::find(1);
         $response = $this->nextStepSwitch($user, $menu);
         $this->sendResponse($response, 1);
     } else {
         $result = explode("*", $text);
         if (empty($result)) {
             $message = $text;
         } else {
             end($result);
             // move the internal pointer to the end of the array
             $message = current($result);
         }
         switch ($user->session) {
             case 0:
                 break;
             case 1:
                 $response = $this->continueUssdProgress($user, $message);
                 break;
             case 2:
                 $response = $this->subscribeToDailyInternetBundles($user, $menu = null, $message);
                 break;
             case 3:
                 break;
             default:
                 break;
         }
         $this->sendResponse($response, 1);
     }
 }
 /**
  * This is my starting point
  * @param Request $request
  */
 public function index(Request $request)
 {
     $sessionId = $request->get('sessionId');
     $serviceCode = $request->get('serviceCode');
     $phoneNumber = $request->get('phoneNumber');
     $text = $request->get('text');
     /**
      * check if user exists
      *
      * count 9 numbers from right
      */
     $no = substr($phoneNumber, -9);
     $user = UssdUser::where('phone', "0" . $no)->orWhere('phone', "254" . $no)->first();
     if (!$user) {
         $data = [];
         $data['phone'] = "0" . $no;
         $data['session'] = 0;
         $data['progress'] = 0;
         $data['menu_item_id'] = 0;
         UssdUser::create($data);
         if ($text == '') {
             $this->sendResponse("Please enter staff ID e.g ekp1111", 1);
         }
     } else {
         if ($text == '') {
             $this->sendResponse("Please enter staff ID e.g ekp1111", 1);
         }
         $id = $text;
         $staff = $this->getStaffId($id);
         if ($staff) {
             $message = "ID is valid and it belongs to " . $staff->first_name . " " . $staff->last_name;
         } else {
             $message = "No Staff with that id";
         }
         $this->sendResponse($message, 2);
     }
 }