1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 07:33:04 +01:00
invoiceninja/app/Http/Controllers/ClientPortal/SubscriptionPlanSwitchController.php

60 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
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. 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;
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
{
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');
}
2023-02-16 02:36:09 +01:00
$amount = max(0, $amount);
2022-12-23 01:33:14 +01:00
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
]);
}
public function not_availabe()
{
abort(404, 'ewwo');
}
2021-04-07 18:08:26 +02:00
}