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

92 lines
3.1 KiB
PHP
Raw Normal View History

<?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-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Controllers\ClientPortal;
use App\Http\Controllers\Controller;
use App\Models\Subscription;
use Illuminate\Http\Request;
2021-03-18 15:41:26 +01:00
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Cache;
2021-03-18 15:41:26 +01:00
use Illuminate\Support\Facades\DB;
2021-03-15 17:33:27 +01:00
use Illuminate\Support\Str;
class SubscriptionPurchaseController extends Controller
{
public function index(Subscription $subscription, Request $request)
{
/* Make sure the contact is logged into the correct company for this subscription */
if (auth()->guard('contact')->user() && auth()->guard('contact')->user()->company_id != $subscription->company_id) {
auth()->guard('contact')->logout();
$request->session()->invalidate();
}
2021-03-18 15:41:26 +01:00
if ($request->has('locale')) {
$this->setLocale($request->query('locale'));
}
2021-03-15 17:33:27 +01:00
return view('billing-portal.purchase', [
'subscription' => $subscription,
2021-03-15 17:33:27 +01:00
'hash' => Str::uuid()->toString(),
2021-03-18 15:41:26 +01:00
'request_data' => $request->all(),
2021-03-15 17:33:27 +01:00
]);
}
2021-03-18 15:41:26 +01:00
2022-11-23 07:27:43 +01:00
public function upgrade(Subscription $subscription, Request $request)
{
/* Make sure the contact is logged into the correct company for this subscription */
if (auth()->guard('contact')->user() && auth()->guard('contact')->user()->company_id != $subscription->company_id) {
auth()->guard('contact')->logout();
$request->session()->invalidate();
}
if ($request->has('locale')) {
$this->setLocale($request->query('locale'));
}
if(!auth()->guard('contact')->check() && $subscription->registration_required && $subscription->company->client_can_register) {
session()->put('url.intended', route('client.subscription.upgrade',['subscription' => $subscription->hashed_id]));
return redirect()->route('client.register', ['company_key' => $subscription->company->company_key]);
}
elseif(!auth()->guard('contact')->check() && $subscription->registration_required && ! $subscription->company->client_can_register) {
return render('generic.subscription_blocked', ['account' => $subscription->company->account, 'company' => $subscription->company]);
}
2022-11-23 07:27:43 +01:00
return view('billing-portal.purchasev2', [
'subscription' => $subscription,
'hash' => Str::uuid()->toString(),
'request_data' => $request->all(),
]);
}
2021-03-18 15:41:26 +01:00
/**
* Set locale for incoming request.
*
* @param string $locale
*/
private function setLocale(string $locale): void
{
$record = Cache::get('languages')->filter(function ($item) use ($locale) {
return $item->locale == $locale;
})->first();
2021-03-18 15:41:26 +01:00
if ($record) {
App::setLocale($record->locale);
}
}
2022-11-23 07:27:43 +01:00
}