Ejemplo n.º 1
0
 public function postSetupNexmo()
 {
     $nexmo_key = Input::get('nexmo_key');
     $nexmo_secret = Input::get('nexmo_secret');
     $nexmo = new NexmoAccount($nexmo_key, $nexmo_secret);
     try {
         // check nexmo credentials
         $credit_balance = $nexmo->getBalance();
         // check db connection
         DB::connection()->getDatabaseName();
         // migrate db
         Artisan::call('migrate');
         // truncate number table
         DB::table('number')->truncate();
         // set nexmo credentials to env
         Cache::forever('NEXMO_KEY', $nexmo_key);
         Cache::forever('NEXMO_SECRET', $nexmo_secret);
         // add numbers to db
         $numbers = $nexmo->getInboundNumbers();
         if ($numbers['count'] > 0) {
             foreach ($numbers['numbers'] as $num) {
                 $number = new Number();
                 $number->number = $num['msisdn'];
                 $number->country_code = $num['country'];
                 $number->type = $num['type'];
                 $number->features = $num['features'];
                 $number->voice_callback_type = $num['voiceCallbackType'];
                 $number->voice_callback_value = $num['voiceCallbackValue'];
                 $number->save();
             }
         }
         // set dn callback url
         // $nexmo->updateAccountSettings(array('drCallBackUrl' => url('callback/dn')));
         Queue::getIron()->addSubscriber('setupDnCallbackUrl', array('url' => url('queue/receive')));
         Queue::push('HomeController@setupDnCallbackUrl', array('nexmo_key' => $nexmo_key, 'nexmo_secret' => $nexmo_secret), 'setupDnCallbackUrl');
         // set balance to cache
         Cache::put('nexmo', $credit_balance, 10);
         if (Auth::check()) {
             return Redirect::to('/');
         }
         return Redirect::to('/register');
     } catch (Exception $e) {
         return Redirect::to('start')->with('message', $e->__toString());
     }
 }