1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Http/Controllers/ClientPortal/SubscriptionPlanSwitchController.php

59 lines
1.7 KiB
PHP
Raw Normal View History

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
* @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()
->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
*/
if (is_null($amount)) {
2021-04-13 11:34:59 +02:00
render('subscriptions.denied');
}
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,
'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
}
}