2021-04-07 18:08:26 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2022-04-27 05:20:41 +02:00
|
|
|
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
2021-04-07 18:08:26 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2021-04-07 18:08:26 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\ClientPortal;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Http\Requests\ClientPortal\Subscriptions\ShowPlanSwitchRequest;
|
2021-04-10 06:07:08 +02:00
|
|
|
use App\Models\RecurringInvoice;
|
2021-04-07 18:08:26 +02:00
|
|
|
use App\Models\Subscription;
|
|
|
|
use Illuminate\Http\Request;
|
2021-04-14 04:40:16 +02:00
|
|
|
use Illuminate\Support\Str;
|
2021-04-07 18:08:26 +02:00
|
|
|
|
|
|
|
class SubscriptionPlanSwitchController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Show the page for switching between plans.
|
|
|
|
*
|
|
|
|
* @param ShowPlanSwitchRequest $request
|
2021-04-10 06:07:08 +02:00
|
|
|
* @param RecurringInvoice $recurring_invoice
|
2021-04-08 16:53:54 +02:00
|
|
|
* @param string $target
|
2021-04-07 18:08:26 +02:00
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
*/
|
2021-04-10 06:07:08 +02:00
|
|
|
public function index(ShowPlanSwitchRequest $request, RecurringInvoice $recurring_invoice, Subscription $target)
|
2021-04-07 18:08:26 +02:00
|
|
|
{
|
2023-01-12 03:52:06 +01:00
|
|
|
|
2021-04-13 11:34:59 +02:00
|
|
|
$amount = $recurring_invoice->subscription
|
|
|
|
->service()
|
2022-12-22 05:58:18 +01:00
|
|
|
->calculateUpgradePriceV2($recurring_invoice, $target);
|
|
|
|
|
2022-12-23 01:33:14 +01:00
|
|
|
nlog("payment amount = {$amount}");
|
2021-04-13 11:34:59 +02:00
|
|
|
/**
|
|
|
|
* Null value here is a proxy for
|
|
|
|
* denying the user a change plan option
|
|
|
|
*/
|
2022-06-21 11:57:17 +02:00
|
|
|
if (is_null($amount)) {
|
2021-04-13 11:34:59 +02:00
|
|
|
render('subscriptions.denied');
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
|
|
|
|
2022-12-23 01:33:14 +01:00
|
|
|
$amount = max(0,$amount);
|
|
|
|
|
2021-04-07 18:08:26 +02:00
|
|
|
return render('subscriptions.switch', [
|
2021-04-12 13:56:08 +02:00
|
|
|
'subscription' => $recurring_invoice->subscription,
|
|
|
|
'recurring_invoice' => $recurring_invoice,
|
2021-04-08 16:53:54 +02:00
|
|
|
'target' => $target,
|
2021-04-10 06:07:08 +02:00
|
|
|
'amount' => $amount,
|
2021-04-07 18:08:26 +02:00
|
|
|
]);
|
2023-01-12 03:52:06 +01:00
|
|
|
|
2021-04-07 18:08:26 +02:00
|
|
|
}
|
|
|
|
}
|