Support canceling pro trial

This commit is contained in:
Hillel Coren 2017-01-04 13:20:56 +02:00
parent 521f2b5d0e
commit 9fc53c8b13
4 changed files with 5 additions and 52 deletions

View File

@ -233,6 +233,7 @@ class AccountController extends BaseController
$company->plan_expires = date_create()->modify($term == PLAN_TERM_MONTHLY ? '+1 month' : '+1 year')->format('Y-m-d');
}
$company->trial_plan = null;
$company->plan = $plan;
$company->save();
@ -1461,22 +1462,6 @@ class AccountController extends BaseController
return Redirect::to('/settings/'.ACCOUNT_USER_DETAILS)->with('message', trans('texts.confirmation_resent'));
}
/**
* @param $plan
* @return \Illuminate\Http\RedirectResponse
*/
public function startTrial($plan)
{
/** @var \App\Models\User $user */
$user = Auth::user();
if ($user->isEligibleForTrial($plan)) {
$user->account->startTrial($plan);
}
return Redirect::back()->with('message', trans('texts.trial_success'));
}
/**
* @param $section
* @param bool $subSection

View File

@ -239,8 +239,6 @@ Route::group([
Route::resource('users', 'UserController');
Route::post('users/bulk', 'UserController@bulk');
Route::get('send_confirmation/{user_id}', 'UserController@sendConfirmation');
Route::get('start_trial/{plan}', 'AccountController@startTrial')
->where(['plan'=>'pro']);
Route::get('/switch_account/{user_id}', 'UserController@switchAccount');
Route::get('/unlink_account/{user_account_id}/{user_id}', 'UserController@unlinkAccount');
Route::get('/manage_companies', 'UserController@manageCompanies');

View File

@ -924,6 +924,10 @@ class Account extends Eloquent
return;
}
if ($this->company->trial_started && $this->company->trial_started != '0000-00-00') {
return;
}
$this->company->trial_plan = $plan;
$this->company->trial_started = date_create()->format('Y-m-d');
$this->company->save();
@ -1159,31 +1163,6 @@ class Account extends Eloquent
return $plan_details && $plan_details['trial'];
}
/**
* @param null $plan
* @return array|bool
*/
public function isEligibleForTrial($plan = null)
{
if (!$this->company->trial_plan) {
if ($plan) {
return $plan == PLAN_PRO || $plan == PLAN_ENTERPRISE;
} else {
return [PLAN_PRO, PLAN_ENTERPRISE];
}
}
if ($this->company->trial_plan == PLAN_PRO) {
if ($plan) {
return $plan != PLAN_PRO;
} else {
return [PLAN_ENTERPRISE];
}
}
return false;
}
/**
* @return int
*/

View File

@ -138,15 +138,6 @@ class User extends Authenticatable
return $this->account->isTrial();
}
/**
* @param null $plan
* @return mixed
*/
public function isEligibleForTrial($plan = null)
{
return $this->account->isEligibleForTrial($plan);
}
/**
* @return int
*/