public function connectProvider($provider) { if ($provider == 'stripe') { $user = Auth::user(); if (Input::has('code')) { // get the token with the code $response = OAuth2::getRefreshToken(Input::get('code')); if (isset($response['refresh_token'])) { $user->stripeRefreshToken = $response['refresh_token']; $user->stripeUserId = $response['stripe_user_id']; Stripe\Stripe::setApiKey($_ENV['STRIPE_SECRET_KEY']); $account = Stripe\Account::retrieve($user->stripeUserId); // success $returned_object = json_decode(strstr($account, '{'), true); // save user $user->ready = 'connecting'; // setting name if is null if (strlen($user->name) == 0) { $user->name = $returned_object['display_name']; } if (strlen($user->zoneinfo) == 0) { $user->zoneinfo = $returned_object['country']; } // saving user $user->save(); IntercomHelper::connected($user, 'stripe'); Queue::push('CalculateFirstTime', array('userID' => $user->id)); } else { if (isset($response['error'])) { Log::error($response['error_description']); return Redirect::route('connect.connect')->with('error', 'Something went wrong, try again later'); } else { Log::error("Something went wrong with stripe connect, don't know what"); return Redirect::route('connect.connect')->with('error', 'Something went wrong, try again later'); } } } else { if (Input::has('error')) { // there was an error in the request Log::error(Input::get('error_description')); return Redirect::route('connect.connect')->with('error', Input::get('error_description')); } else { // we don't know what happened Log: error('Unknown error with user: '******'connect.connect')->with('error', 'Something went wrong, try again'); } } } return Redirect::route('auth.dashboard')->with('success', ucfirst($provider) . ' connected.'); }