/** * Store a newly created resource in storage. * * @return Response */ public function store() { $nexmo = new NexmoAccount(Cache::get('NEXMO_KEY', getenv('NEXMO_KEY')), Cache::get('NEXMO_SECRET', getenv('NEXMO_SECRET'))); $isBought = $nexmo->buyNumber(Input::get('country_code'), Input::get('number')); if ($isBought) { Pusherer::trigger('boom', 'update_balance', $nexmo->getBalance()); $number = new Number(); $number->number = Input::get('number'); $number->country_code = Input::get('country_code'); $number->type = Input::get('type'); $number->features = explode(',', Input::get('features')); $number->save(); return $number; } return $this->response->errorInternal(); }
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()); } }
| It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the Closure to execute when that URI is requested. | */ Route::filter('nexmo', function () { $nexmo_key = getenv('NEXMO_KEY') ?: (Schema::hasTable('cache') ? Cache::get('NEXMO_KEY') : false); $nexmo_secret = getenv('NEXMO_SECRET') ?: (Schema::hasTable('cache') ? Cache::get('NEXMO_SECRET') : false); if (!$nexmo_key || !$nexmo_secret) { return Redirect::to('start'); } // validate nexmo credentials $nexmo = new NexmoAccount($nexmo_key, $nexmo_secret); try { $isNexmoValid = Cache::get('nexmo'); if (!$isNexmoValid) { Cache::put('nexmo', $nexmo->getBalance(), 10); } } catch (Exception $e) { return Redirect::to('start'); } }); /* * Main page */ Route::filter('dashboardFilter', function () { if (!Schema::hasTable('users')) { return Redirect::to('start'); } if (!User::all()->count()) { return Redirect::to('register'); }