Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip
  • Loading branch information
djaiss committed Jan 27, 2018
commit d7ac203d744213683b03dd0f2ad7cd7b79c503c8
35 changes: 35 additions & 0 deletions app/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,39 @@ public function getRemindersForMonth(int $month)

return $reminders;
}

/**
* Get the plan information for the given time period.
*
* @param String Accepted values: 'monthly', 'annual'
* @return Array
*/
public function getPlanInformationFromConfig(String $timePeriod)
{
if ($timePeriod != 'monthly' && $timePeriod != 'annual') {
return;
}

if ($timePeriod == 'monthly') {
$planInformation = [
'type' => 'monthly',
'name' => config('monica.paid_plan_friendly_name'),
'id' => config('monica.paid_plan_id'),
'price' => config('monica.paid_plan_price'),
'friendlyPrice' => config('monica.paid_plan_price')/100,
];
}

if ($timePeriod == 'annual') {
$planInformation = [
'type' => 'annual',
'name' => config('monica.paid_plan_annual_friendly_name'),
'id' => config('monica.paid_plan_annual_id'),
'price' => config('monica.paid_plan_annual_price'),
'friendlyPrice' => config('monica.paid_plan_annual_price')/100,
];
}

return $planInformation;
}
}
17 changes: 17 additions & 0 deletions app/Helpers/DateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,21 @@ public static function getMonthAndYear(int $month)

return $month.' '.$year;
}

/**
* Gets the next theoritical billing date.
* This is used on the Upgrade page to tell the user when the next billing
* date would be if he subscribed.
*
* @param String
* @return Carbon
*/
public static function getNextTheoriticalBillingDate(String $interval)
{
if ($interval == 'monthly') {
return Carbon::now()->addMonth();
}

return Carbon::now()->addYear();
}
}
19 changes: 15 additions & 4 deletions app/Http/Controllers/Settings/SubscriptionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers\Settings;

use App\Helpers\DateHelper;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

Expand Down Expand Up @@ -30,19 +31,25 @@ public function index()
*
* @return \Illuminate\Http\Response
*/
public function upgrade()
public function upgrade(Request $request)
{
if (! config('monica.requires_subscription')) {
return redirect('settings/');
}

$account = auth()->user()->account;
$plan = $request->query('plan');

$data = [
'planInformation' => auth()->user()->account->getPlanInformationFromConfig($plan),
'nextTheoriticalDate' => DateHelper::getShortDate(DateHelper::getNextTheoriticalBillingDate($plan)),
];

if ($account->subscribed(config('monica.paid_plan_friendly_name'))) {
return redirect('/settings/subscriptions');
}

return view('settings.subscriptions.upgrade');
return view('settings.subscriptions.upgrade', $data);
}

/**
Expand Down Expand Up @@ -92,8 +99,12 @@ public function processPayment(Request $request)

$stripeToken = $request->input('stripeToken');

auth()->user()->account->newSubscription(config('monica.paid_plan_friendly_name'), config('monica.paid_plan_id'))
->create($stripeToken);
$plan = auth()->user()->account->getPlanInformationFromConfig($request->input('plan'));

auth()->user()->account->newSubscription($plan['name'], $plan['id'])
->create($stripeToken, [
'email' => auth()->user()->email,
]);

return redirect('settings/subscriptions');
}
Expand Down
3 changes: 3 additions & 0 deletions config/monica.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
'paid_plan_friendly_name' => env('PAID_PLAN_FRIENDLY_NAME', null),
'paid_plan_id' => env('PAID_PLAN_ID', null),
'paid_plan_price' => env('PAID_PLAN_PRICE', null),
'paid_plan_annual_friendly_name' => env('PAID_PLAN_ANNUAL_FRIENDLY_NAME', null),
'paid_plan_annual_id' => env('PAID_PLAN_ANNUAL_ID', null),
'paid_plan_annual_price' => env('PAID_PLAN_ANNUAL_PRICE', null),

/*
|--------------------------------------------------------------------------
Expand Down
18,923 changes: 18,914 additions & 9 deletions public/css/app.css

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions public/css/stripe.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63,258 changes: 63,256 additions & 2 deletions public/js/app.js

Large diffs are not rendered by default.

Loading