mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-19 11:45:01 +00:00
deleted pro files
This commit is contained in:
@@ -1,569 +0,0 @@
|
||||
<?php
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use DB;
|
||||
use App\Users\Models\User;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Console\Command;
|
||||
use Domain\Settings\Models\Setting;
|
||||
use VueFileManager\Subscription\Domain\Plans\Models\Plan;
|
||||
use VueFileManager\Subscription\Domain\CreditCards\Models\CreditCard;
|
||||
use VueFileManager\Subscription\Domain\Plans\DTO\CreateFixedPlanData;
|
||||
use VueFileManager\Subscription\Domain\Plans\DTO\CreateMeteredPlanData;
|
||||
use VueFileManager\Subscription\Domain\Subscriptions\Models\Subscription;
|
||||
use VueFileManager\Subscription\Domain\Plans\Actions\StoreFixedPlanAction;
|
||||
use VueFileManager\Subscription\Domain\Plans\Actions\StoreMeteredPlanAction;
|
||||
|
||||
class GenerateDemoSubscriptionContentCommand extends Command
|
||||
{
|
||||
public $signature = 'subscription:demo {type=fixed}';
|
||||
|
||||
public $description = 'Generate demo content for subscription module';
|
||||
|
||||
public function __construct(
|
||||
private StoreFixedPlanAction $storeFixedPlan,
|
||||
private StoreMeteredPlanAction $storeMeteredPlan,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
// Truncate all subscription relate tables
|
||||
collect([
|
||||
'balances', 'billing_alerts', 'credit_cards', 'customers', 'failed_payments', 'metered_tiers', 'plan_drivers', 'plan_fixed_features', 'plan_metered_features', 'plans', 'subscription_drivers', 'subscriptions', 'usages', 'transactions',
|
||||
])->each(fn ($name) => DB::table($name)->truncate());
|
||||
|
||||
// Create plans and subscriptions for metered billing
|
||||
if ($this->argument('type') === 'metered') {
|
||||
$this->info('Setting up new metered plans demo data...');
|
||||
$this->generateMeteredPlans();
|
||||
|
||||
$this->info('Setting up new pre-paid subscriptions data...');
|
||||
$this->generateMeteredSubscription();
|
||||
}
|
||||
|
||||
// Create plans and subscriptions for fixed billing
|
||||
if ($this->argument('type') === 'fixed') {
|
||||
// TODO: check for credentials
|
||||
|
||||
$this->info('Setting up new fixed plans demo data...');
|
||||
$this->generateFixedPlans();
|
||||
|
||||
$this->info('Setting up new fixed subscriptions data...');
|
||||
$this->generateFixedSubscription();
|
||||
}
|
||||
|
||||
// Set subscription type for the app
|
||||
Setting::updateOrCreate([
|
||||
'name' => 'subscription_type',
|
||||
], [
|
||||
'value' => $this->argument('type'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function generateMeteredSubscription(): void
|
||||
{
|
||||
$plan = Plan::where('name', 'Pay as You Go')
|
||||
->first();
|
||||
|
||||
User::all()
|
||||
->each(function ($user) use ($plan) {
|
||||
$isHowdy = $user->email === 'howdy@hi5ve.digital';
|
||||
|
||||
$this->info("Storing {$plan->name} for {$user->email}...");
|
||||
|
||||
// 1. Create subscription
|
||||
$subscription = Subscription::create([
|
||||
'user_id' => $user->id,
|
||||
'type' => 'pre-paid',
|
||||
'plan_id' => $plan->id,
|
||||
'name' => $plan->name,
|
||||
'status' => 'active',
|
||||
'renews_at' => now()->addDays(16),
|
||||
'created_at' => now()->subDays(14),
|
||||
'updated_at' => now()->subDays(14),
|
||||
]);
|
||||
|
||||
// 2. Log fake storage and bandwidth
|
||||
foreach (range(1, 31) as $item) {
|
||||
$this->info('Logging fake bandwidth usage...');
|
||||
|
||||
$bandwidthFeature = $plan
|
||||
->meteredFeatures()
|
||||
->where('key', 'bandwidth')
|
||||
->first();
|
||||
|
||||
$subscription->usages()->create([
|
||||
'metered_feature_id' => $bandwidthFeature->id,
|
||||
'quantity' => random_int(111, 999) / 1000,
|
||||
'created_at' => now()->subDays($item),
|
||||
]);
|
||||
|
||||
$this->info('Logging fake storage usage...');
|
||||
|
||||
$storageFeature = $plan
|
||||
->meteredFeatures()
|
||||
->where('key', 'storage')
|
||||
->first();
|
||||
|
||||
$subscription->usages()->create([
|
||||
'metered_feature_id' => $storageFeature->id,
|
||||
'quantity' => random_int(1111, 3999) / 1000,
|
||||
'created_at' => now()->subDays($item),
|
||||
]);
|
||||
}
|
||||
|
||||
// 3. Store flat fee
|
||||
$flatFeeFeature = $plan
|
||||
->meteredFeatures()
|
||||
->where('key', 'flatFee')
|
||||
->first();
|
||||
|
||||
$subscription->usages()->create([
|
||||
'metered_feature_id' => $flatFeeFeature->id,
|
||||
'quantity' => 1,
|
||||
'created_at' => now()->subDays(2),
|
||||
]);
|
||||
|
||||
// 4. Store member count
|
||||
$memberFeature = $plan
|
||||
->meteredFeatures()
|
||||
->where('key', 'member')
|
||||
->first();
|
||||
|
||||
$subscription->usages()->create([
|
||||
'metered_feature_id' => $memberFeature->id,
|
||||
'quantity' => 7,
|
||||
'created_at' => now()->subDays(2),
|
||||
]);
|
||||
|
||||
// 5. Store fake transactions
|
||||
$this->info("Storing transactions for {$user->email}...");
|
||||
|
||||
collect([
|
||||
[
|
||||
'type' => 'withdrawal',
|
||||
'created_at' => now()->subDays(2),
|
||||
'amount' => $isHowdy ? 12.59 : random_int(1, 20),
|
||||
'note' => now()->subDays(32)->format('d. M') . ' - ' . now()->subDays(2)->format('d. M'),
|
||||
'driver' => 'system',
|
||||
],
|
||||
[
|
||||
'type' => 'credit',
|
||||
'created_at' => now()->subDays(26 * 1),
|
||||
'note' => __('Bonus'),
|
||||
'amount' => $isHowdy ? 12.00 : random_int(1, 20),
|
||||
'driver' => 'system',
|
||||
],
|
||||
[
|
||||
'type' => 'withdrawal',
|
||||
'created_at' => now()->subDays(26 * 1),
|
||||
'note' => now()->subDays(30 + 26 * 1)->format('d. M') . ' - ' . now()->subDays(26 * 1)->format('d. M'),
|
||||
'amount' => $isHowdy ? 2.38 : random_int(1, 20),
|
||||
'driver' => 'system',
|
||||
],
|
||||
[
|
||||
'type' => 'withdrawal',
|
||||
'created_at' => now()->subDays(26 * 2),
|
||||
'note' => now()->subDays(30 + 26 * 2)->format('d. M') . ' - ' . now()->subDays(26 * 2)->format('d. M'),
|
||||
'amount' => $isHowdy ? 5.12 : random_int(1, 20),
|
||||
'driver' => 'system',
|
||||
],
|
||||
[
|
||||
'type' => 'withdrawal',
|
||||
'created_at' => now()->subDays(26 * 3),
|
||||
'note' => now()->subDays(30 + 26 * 3)->format('d. M') . ' - ' . now()->subDays(26 * 3)->format('d. M'),
|
||||
'amount' => $isHowdy ? 3.89 : random_int(1, 20),
|
||||
'driver' => 'system',
|
||||
],
|
||||
[
|
||||
'type' => 'withdrawal',
|
||||
'created_at' => now()->subDays(26 * 4),
|
||||
'note' => now()->subDays(30 + 26 * 4)->format('d. M') . ' - ' . now()->subDays(26 * 4)->format('d. M'),
|
||||
'amount' => $isHowdy ? 7.42 : random_int(1, 20),
|
||||
'driver' => 'system',
|
||||
],
|
||||
[
|
||||
'type' => 'charge',
|
||||
'created_at' => now()->subDays(26 * 5),
|
||||
'note' => 'Account Fund',
|
||||
'amount' => $isHowdy ? 50.00 : random_int(1, 20),
|
||||
'driver' => 'paypal',
|
||||
],
|
||||
])->each(
|
||||
function ($transaction) use ($user, $plan) {
|
||||
$bandwidthUsage = random_int(1000, 12000) / 1000;
|
||||
$storageUsage = random_int(300, 4900) / 1000;
|
||||
$memberUsage = random_int(3, 20);
|
||||
|
||||
$user->transactions()->create([
|
||||
'type' => $transaction['type'],
|
||||
'status' => 'completed',
|
||||
'note' => $transaction['note'],
|
||||
'currency' => $plan->currency,
|
||||
'driver' => $transaction['driver'],
|
||||
'amount' => $transaction['amount'],
|
||||
'created_at' => $transaction['created_at'],
|
||||
'reference' => Str::random(12),
|
||||
'metadata' => $transaction['type'] === 'withdrawal'
|
||||
? [
|
||||
[
|
||||
'feature' => 'bandwidth',
|
||||
'amount' => 0.29 * $bandwidthUsage,
|
||||
'usage' => $bandwidthUsage,
|
||||
],
|
||||
[
|
||||
'feature' => 'storage',
|
||||
'amount' => 0.19 * $storageUsage,
|
||||
'usage' => $storageUsage,
|
||||
],
|
||||
[
|
||||
'feature' => 'flatFee',
|
||||
'amount' => 2.49,
|
||||
'usage' => 1,
|
||||
],
|
||||
[
|
||||
'feature' => 'member',
|
||||
'amount' => 0.10 * $memberUsage,
|
||||
'usage' => $memberUsage,
|
||||
],
|
||||
]
|
||||
: null,
|
||||
]);
|
||||
}
|
||||
);
|
||||
|
||||
// Make fake credit card
|
||||
$creditCard = CreditCard::factory()
|
||||
->make();
|
||||
|
||||
// 6. Store credit card
|
||||
if (! $isHowdy) {
|
||||
$user->creditCards()->create([
|
||||
'brand' => $creditCard->brand,
|
||||
'last4' => $creditCard->last4,
|
||||
'service' => $creditCard->service,
|
||||
'reference' => $creditCard->reference,
|
||||
'expiration' => $creditCard->expiration,
|
||||
]);
|
||||
}
|
||||
|
||||
// 7. Add default user balance
|
||||
$user->balance()->create([
|
||||
'currency' => 'USD',
|
||||
'amount' => $isHowdy ? 30.60 : random_int(20, 60),
|
||||
]);
|
||||
|
||||
// 8. Create billing alert
|
||||
$user->billingAlert()->create([
|
||||
'amount' => $isHowdy ? 25 : random_int(30, 80),
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
public function generateFixedSubscription(): void
|
||||
{
|
||||
$howdy = User::where('email', 'howdy@hi5ve.digital')
|
||||
->first();
|
||||
|
||||
$alice = User::where('email', 'alice@hi5ve.digital')
|
||||
->first();
|
||||
|
||||
$johan = User::where('email', 'johan@hi5ve.digital')
|
||||
->first();
|
||||
|
||||
$professionalPackPlan = Plan::where('name', 'Professional Pack')
|
||||
->where('interval', 'month')
|
||||
->first();
|
||||
|
||||
$businessPackPlan = Plan::where('name', 'Business Pack')
|
||||
->where('interval', 'month')
|
||||
->first();
|
||||
|
||||
$this->info("Storing {$professionalPackPlan->name} for {$howdy->email}...");
|
||||
|
||||
$howdySubscription = $howdy->subscription()->create([
|
||||
'plan_id' => $professionalPackPlan->id,
|
||||
'name' => $professionalPackPlan->name,
|
||||
'status' => 'active',
|
||||
'created_at' => now()->subDays(14),
|
||||
'updated_at' => now()->subDays(14),
|
||||
]);
|
||||
|
||||
$this->info("Storing {$businessPackPlan->name} for {$alice->email}...");
|
||||
|
||||
$aliceSubscription = $alice->subscription()->create([
|
||||
'plan_id' => $businessPackPlan->id,
|
||||
'name' => $businessPackPlan->name,
|
||||
'status' => 'active',
|
||||
'created_at' => now()->subDays(9),
|
||||
'updated_at' => now()->subDays(9),
|
||||
]);
|
||||
|
||||
$this->info("Storing {$professionalPackPlan->name} for {$johan->email}...");
|
||||
|
||||
$johanSubscription = $johan->subscription()->create([
|
||||
'plan_id' => $professionalPackPlan->id,
|
||||
'name' => $professionalPackPlan->name,
|
||||
'status' => 'cancelled',
|
||||
'ends_at' => now()->addDays(18),
|
||||
'created_at' => now()->subDays(8),
|
||||
'updated_at' => now()->subDays(8),
|
||||
]);
|
||||
|
||||
$this->info("Storing transactions for {$howdy->email}...");
|
||||
|
||||
collect([
|
||||
['created_at' => now()->subDays(2)],
|
||||
['created_at' => now()->subDays(26)],
|
||||
['created_at' => now()->subDays(26 * 2)],
|
||||
['created_at' => now()->subDays(26 * 3)],
|
||||
['created_at' => now()->subDays(26 * 4)],
|
||||
['created_at' => now()->subDays(26 * 5)],
|
||||
])->each(
|
||||
fn ($transaction) => $howdy->transactions()->create([
|
||||
'status' => 'completed',
|
||||
'note' => $professionalPackPlan->name,
|
||||
'currency' => $professionalPackPlan->currency,
|
||||
'amount' => $professionalPackPlan->amount,
|
||||
'driver' => 'paypal',
|
||||
'created_at' => $transaction['created_at'],
|
||||
'reference' => Str::random(12),
|
||||
])
|
||||
);
|
||||
|
||||
$this->info("Storing transactions for {$johan->email}...");
|
||||
|
||||
collect([
|
||||
['created_at' => now()->subDay()],
|
||||
['created_at' => now()->subDays(29)],
|
||||
['created_at' => now()->subDays(29 * 2)],
|
||||
['created_at' => now()->subDays(29 * 3)],
|
||||
])->each(
|
||||
fn ($transaction) => $johan->transactions()->create([
|
||||
'status' => 'completed',
|
||||
'note' => $professionalPackPlan->name,
|
||||
'currency' => $professionalPackPlan->currency,
|
||||
'amount' => $professionalPackPlan->amount,
|
||||
'driver' => 'stripe',
|
||||
'created_at' => $transaction['created_at'],
|
||||
'reference' => Str::random(12),
|
||||
])
|
||||
);
|
||||
|
||||
$this->info("Storing transactions for {$alice->email}...");
|
||||
|
||||
collect([
|
||||
['created_at' => now()],
|
||||
['created_at' => now()->subDays(28)],
|
||||
['created_at' => now()->subDays(28 * 2)],
|
||||
['created_at' => now()->subDays(28 * 3)],
|
||||
['created_at' => now()->subDays(28 * 4)],
|
||||
])->each(
|
||||
fn ($transaction) => $alice->transactions()->create([
|
||||
'status' => 'completed',
|
||||
'note' => $businessPackPlan->name,
|
||||
'currency' => $businessPackPlan->currency,
|
||||
'amount' => $businessPackPlan->amount,
|
||||
'driver' => 'paystack',
|
||||
'created_at' => $transaction['created_at'],
|
||||
'reference' => Str::random(12),
|
||||
])
|
||||
);
|
||||
|
||||
$howdySubscription->driver()->create([
|
||||
'driver' => 'stripe',
|
||||
'driver_subscription_id' => Str::random(),
|
||||
]);
|
||||
|
||||
// Make fake credit card
|
||||
$creditCard = CreditCard::factory()
|
||||
->make();
|
||||
|
||||
// 6. Store credit card
|
||||
$howdy->creditCards()->create([
|
||||
'brand' => $creditCard->brand,
|
||||
'last4' => $creditCard->last4,
|
||||
'service' => $creditCard->service,
|
||||
'reference' => $creditCard->reference,
|
||||
'expiration' => $creditCard->expiration,
|
||||
]);
|
||||
|
||||
$aliceSubscription->driver()->create([
|
||||
'driver' => 'paystack',
|
||||
'driver_subscription_id' => Str::random(),
|
||||
]);
|
||||
|
||||
$johanSubscription->driver()->create([
|
||||
'driver' => 'stripe',
|
||||
'driver_subscription_id' => Str::random(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function generateFixedPlans()
|
||||
{
|
||||
// Define plans
|
||||
$plans = [
|
||||
[
|
||||
'type' => 'fixed',
|
||||
'name' => 'Professional Pack',
|
||||
'description' => 'Best for all professionals',
|
||||
'currency' => 'USD',
|
||||
'features' => [
|
||||
'max_storage_amount' => 200,
|
||||
'max_team_members' => 20,
|
||||
],
|
||||
'intervals' => [
|
||||
[
|
||||
'interval' => 'month',
|
||||
'amount' => 9.99,
|
||||
],
|
||||
[
|
||||
'interval' => 'year',
|
||||
'amount' => 99.49,
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'fixed',
|
||||
'name' => 'Business Pack',
|
||||
'description' => 'Best for business needs',
|
||||
'currency' => 'USD',
|
||||
'features' => [
|
||||
'max_storage_amount' => 500,
|
||||
'max_team_members' => 50,
|
||||
],
|
||||
'intervals' => [
|
||||
[
|
||||
'interval' => 'month',
|
||||
'amount' => 29.99,
|
||||
],
|
||||
[
|
||||
'interval' => 'year',
|
||||
'amount' => 189.99,
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'fixed',
|
||||
'name' => 'Elite Pack',
|
||||
'description' => 'Best for all your needs',
|
||||
'currency' => 'USD',
|
||||
'features' => [
|
||||
'max_storage_amount' => 2000,
|
||||
'max_team_members' => -1,
|
||||
],
|
||||
'intervals' => [
|
||||
[
|
||||
'interval' => 'month',
|
||||
'amount' => 59.99,
|
||||
],
|
||||
[
|
||||
'interval' => 'year',
|
||||
'amount' => 349.99,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// Create plans
|
||||
foreach ($plans as $plan) {
|
||||
foreach ($plan['intervals'] as $interval) {
|
||||
$data = CreateFixedPlanData::fromArray([
|
||||
'type' => $plan['type'],
|
||||
'name' => $plan['name'],
|
||||
'description' => $plan['description'],
|
||||
'features' => $plan['features'],
|
||||
'currency' => $plan['currency'],
|
||||
'amount' => $interval['amount'],
|
||||
'interval' => $interval['interval'],
|
||||
]);
|
||||
|
||||
$this->info("Creating plan with name: {$plan['name']} and interval: {$interval['interval']}");
|
||||
|
||||
// Store plans to the database and gateway
|
||||
($this->storeFixedPlan)($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function generateMeteredPlans()
|
||||
{
|
||||
// Define plans
|
||||
$plans = [
|
||||
[
|
||||
'type' => 'metered',
|
||||
'name' => 'Pay as You Go',
|
||||
'description' => 'Best for all professionals',
|
||||
'currency' => 'USD',
|
||||
'meters' => [
|
||||
[
|
||||
'key' => 'bandwidth',
|
||||
'aggregate_strategy' => 'sum_of_usage',
|
||||
'tiers' => [
|
||||
[
|
||||
'first_unit' => 1,
|
||||
'last_unit' => null,
|
||||
'per_unit' => 0.29,
|
||||
'flat_fee' => null,
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'key' => 'storage',
|
||||
'aggregate_strategy' => 'maximum_usage',
|
||||
'tiers' => [
|
||||
[
|
||||
'first_unit' => 1,
|
||||
'last_unit' => null,
|
||||
'per_unit' => 0.19,
|
||||
'flat_fee' => null,
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'key' => 'flatFee',
|
||||
'aggregate_strategy' => 'maximum_usage',
|
||||
'tiers' => [
|
||||
[
|
||||
'first_unit' => 1,
|
||||
'last_unit' => null,
|
||||
'per_unit' => 2.49,
|
||||
'flat_fee' => null,
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'key' => 'member',
|
||||
'aggregate_strategy' => 'maximum_usage',
|
||||
'tiers' => [
|
||||
[
|
||||
'first_unit' => 1,
|
||||
'last_unit' => null,
|
||||
'per_unit' => 0.10,
|
||||
'flat_fee' => null,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// Create plans
|
||||
foreach ($plans as $plan) {
|
||||
$data = CreateMeteredPlanData::fromArray([
|
||||
'type' => $plan['type'],
|
||||
'name' => $plan['name'],
|
||||
'meters' => $plan['meters'],
|
||||
'currency' => $plan['currency'],
|
||||
'description' => $plan['description'],
|
||||
]);
|
||||
|
||||
$this->info("Creating plan with name: {$plan['name']}");
|
||||
|
||||
// Store plans to the database and gateway
|
||||
($this->storeMeteredPlan)($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class SetupWebsocketEnvironment extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'websockets:install';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Set up websocket production environment';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
// Get allowed origins
|
||||
$origins = $this->ask('Type host of which you want to allow incoming requests. If you want to accept multiple hosts, separate them with comma(,)');
|
||||
|
||||
// Store origins to the .env file
|
||||
setEnvironmentValue([
|
||||
'PUSHER_APP_ALLOWED_ORIGIN' => $origins,
|
||||
'APP_ENV' => 'production',
|
||||
'APP_DEBUG' => 'false',
|
||||
]);
|
||||
|
||||
$this->info('Your host/s was stored successfully.');
|
||||
|
||||
// Generate new app key
|
||||
$this->call('key:generate', [
|
||||
'--force' => true,
|
||||
]);
|
||||
|
||||
// Clear cache
|
||||
$this->call('config:clear');
|
||||
|
||||
$this->info('Everything is done, congratulations! 🥳🥳🥳');
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
<?php
|
||||
namespace App\Socialite\Controllers;
|
||||
|
||||
use App\Users\Models\User;
|
||||
use App\Users\DTO\CreateUserData;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Laravel\Socialite\Facades\Socialite;
|
||||
use App\Users\Actions\CreateNewUserAction;
|
||||
use Illuminate\Contracts\Auth\StatefulGuard;
|
||||
use VueFileManager\Subscription\Domain\Plans\Models\Plan;
|
||||
use VueFileManager\Subscription\Domain\Plans\Exceptions\MeteredBillingPlanDoesntExist;
|
||||
|
||||
class SocialiteCallbackController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected StatefulGuard $guard,
|
||||
public CreateNewUserAction $createNewUser,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws MeteredBillingPlanDoesntExist
|
||||
*/
|
||||
public function __invoke($provider)
|
||||
{
|
||||
$isAllowedRegistration = intval(get_settings('registration'));
|
||||
|
||||
// Get socialite user
|
||||
if (app()->runningUnitTests()) {
|
||||
$socialite = Socialite::driver($provider)->user();
|
||||
} else {
|
||||
$socialite = Socialite::driver($provider)->stateless()->user();
|
||||
}
|
||||
|
||||
// Get user by email
|
||||
$user = User::where('email', $socialite->email);
|
||||
|
||||
// Login user when exists
|
||||
if ($user->exists()) {
|
||||
$this->guard->login(
|
||||
$user->first()
|
||||
);
|
||||
|
||||
return redirect()->to('/platform/files');
|
||||
}
|
||||
|
||||
// Check for metered billing plan
|
||||
if (get_settings('subscription_type') === 'metered') {
|
||||
// Get metered plan
|
||||
$plan = Plan::where('status', 'active')
|
||||
->where('type', 'metered');
|
||||
|
||||
// TODO: redirect to the error page
|
||||
if ($plan->doesntExist()) {
|
||||
return response([
|
||||
'type' => 'error',
|
||||
'message' => 'User registrations are temporarily disabled',
|
||||
], 409);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if account registration is enabled
|
||||
if (! $isAllowedRegistration) {
|
||||
return response([
|
||||
'type' => 'error',
|
||||
'message' => 'User registration is not allowed',
|
||||
], 401);
|
||||
}
|
||||
|
||||
// Create data user data object
|
||||
$data = CreateUserData::fromArray([
|
||||
'role' => 'user',
|
||||
'name' => $socialite->getName(),
|
||||
'email' => $socialite->getEmail(),
|
||||
'avatar' => store_socialite_avatar($socialite->getAvatar()),
|
||||
'oauth_provider' => $provider,
|
||||
]);
|
||||
|
||||
// Create User
|
||||
$newUser = ($this->createNewUser)($data);
|
||||
|
||||
// Login user
|
||||
$this->guard->login($newUser);
|
||||
|
||||
return redirect()->to('/platform/files');
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
namespace App\Socialite\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Laravel\Socialite\Facades\Socialite;
|
||||
|
||||
class SocialiteRedirectController extends Controller
|
||||
{
|
||||
public function __invoke($provider)
|
||||
{
|
||||
$url = Socialite::driver($provider)->stateless()->redirect()->getTargetUrl();
|
||||
|
||||
return response()->json([
|
||||
'url' => $url,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
namespace App\Users\Actions;
|
||||
|
||||
use App\Users\Models\User;
|
||||
use VueFileManager\Subscription\Domain\Plans\Models\Plan;
|
||||
use App\Users\Notifications\RegistrationBonusAddedNotification;
|
||||
|
||||
class AutoSubscribeForMeteredBillingAction
|
||||
{
|
||||
public function __invoke(User $user)
|
||||
{
|
||||
// Get metered billing plan
|
||||
$plan = Plan::where('status', 'active')
|
||||
->where('type', 'metered')
|
||||
->first();
|
||||
|
||||
// Get settings
|
||||
$settings = get_settings([
|
||||
'allowed_registration_bonus',
|
||||
'registration_bonus_amount',
|
||||
]);
|
||||
|
||||
// Create user balance
|
||||
if (intval($settings['allowed_registration_bonus'])) {
|
||||
// Create balance with bonus amount
|
||||
$user->balance()->create([
|
||||
'amount' => $settings['registration_bonus_amount'],
|
||||
'currency' => $plan->currency,
|
||||
]);
|
||||
|
||||
// Store transaction bonus
|
||||
$user->transactions()->create([
|
||||
'status' => 'completed',
|
||||
'type' => 'credit',
|
||||
'driver' => 'system',
|
||||
'note' => __t('registration_bonus'),
|
||||
'currency' => $plan->currency,
|
||||
'amount' => $settings['registration_bonus_amount'],
|
||||
]);
|
||||
|
||||
// Send user bonus notification
|
||||
$bonus = format_currency($settings['registration_bonus_amount'], $plan->currency);
|
||||
|
||||
$user->notify(new RegistrationBonusAddedNotification($bonus));
|
||||
} else {
|
||||
// Create balance with 0 amount
|
||||
$user->balance()->create([
|
||||
'amount' => 0,
|
||||
'currency' => $plan->currency,
|
||||
]);
|
||||
}
|
||||
|
||||
// Create user subscription
|
||||
$user->subscription()->create([
|
||||
'plan_id' => $plan->id,
|
||||
'name' => $plan->name,
|
||||
'status' => 'active',
|
||||
'renews_at' => now()->addDays(config('subscription.metered_billing.settlement_period')),
|
||||
'type' => 'pre-paid',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
namespace App\Users\Actions;
|
||||
|
||||
use ByteUnits\Metric;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class FormatUsageEstimatesAction
|
||||
{
|
||||
public function __invoke(string $currency, Collection|array $usage)
|
||||
{
|
||||
return collect($usage)
|
||||
->mapWithKeys(function ($estimate) use ($currency) {
|
||||
// Format usage
|
||||
$usage = match ($estimate['feature']) {
|
||||
'bandwidth', 'storage' => Metric::megabytes($estimate['usage'] * 1000)->format(),
|
||||
'flatFee' => intval($estimate['usage']) . ' ' . __t('pcs.'),
|
||||
'member' => intval($estimate['usage']) . ' ' . __t('mem.'),
|
||||
};
|
||||
|
||||
return [
|
||||
$estimate['feature'] => [
|
||||
'feature' => $estimate['feature'],
|
||||
'amount' => $estimate['amount'],
|
||||
'cost' => format_currency($estimate['amount'], $currency),
|
||||
'usage' => $usage,
|
||||
],
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
namespace App\Users\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class RegistrationBonusAddedNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
public string $bonus
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*/
|
||||
public function via(mixed $notifiable): array
|
||||
{
|
||||
return ['database'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*/
|
||||
public function toArray(mixed $notifiable): array
|
||||
{
|
||||
return [
|
||||
'category' => 'gift',
|
||||
'title' => __t('you_received_bonus', ['bonus' => $this->bonus]),
|
||||
'description' => __t('you_received_registration_bonus_note', ['bonus' => $this->bonus]),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
namespace App\Users\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UserSubscription extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$active_subscription = $this->subscription('main')
|
||||
->asStripeSubscription();
|
||||
|
||||
// TODO: vybrat z cache
|
||||
$subscription = resolve('App\Services\StripeService')
|
||||
->getPlan($this->subscription('main')->stripe_plan);
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'id' => $subscription['plan']['id'],
|
||||
'type' => 'subscription',
|
||||
'attributes' => [
|
||||
'incomplete' => $this->subscription('main')->incomplete(),
|
||||
'active' => $this->subscription('main')->active(),
|
||||
'canceled' => $this->subscription('main')->cancelled(),
|
||||
'name' => $subscription['product']['name'],
|
||||
'capacity' => (int) $subscription['product']['metadata']['capacity'],
|
||||
'capacity_formatted' => format_gigabytes($subscription['product']['metadata']['capacity']),
|
||||
'slug' => $subscription['plan']['id'],
|
||||
'canceled_at' => format_date($active_subscription['canceled_at'], 'd. M. Y'),
|
||||
'created_at' => format_date($active_subscription['current_period_start'], 'd. M. Y'),
|
||||
'ends_at' => format_date($active_subscription['current_period_end'], 'd. M. Y'),
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
namespace App\Users\Restrictions\Engines;
|
||||
|
||||
use App\Users\Models\User;
|
||||
use App\Users\Restrictions\RestrictionsEngine;
|
||||
use Domain\Teams\Actions\CheckMaxTeamMembersLimitAction;
|
||||
|
||||
class FixedBillingRestrictionsEngine implements RestrictionsEngine
|
||||
{
|
||||
public function canUpload(User $user, int $fileSize = 0): bool
|
||||
{
|
||||
// Get used capacity
|
||||
$usedPercentage = get_storage_percentage(
|
||||
used: $user->usedCapacity + $fileSize,
|
||||
maxAmount: $user->limitations->max_storage_amount,
|
||||
);
|
||||
|
||||
// Check if storage usage exceed predefined capacity
|
||||
return ! ($usedPercentage >= 100);
|
||||
}
|
||||
|
||||
public function canDownload(User $user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canCreateFolder(User $user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canCreateTeamFolder(User $user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canInviteTeamMembers(User $user, array $newInvites = []): bool
|
||||
{
|
||||
return resolve(CheckMaxTeamMembersLimitAction::class)($user, $newInvites);
|
||||
}
|
||||
|
||||
public function canVisitShared(User $user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
namespace App\Users\Restrictions\Engines;
|
||||
|
||||
use App\Users\Models\User;
|
||||
use App\Users\Restrictions\RestrictionsEngine;
|
||||
|
||||
class MeteredBillingRestrictionsEngine implements RestrictionsEngine
|
||||
{
|
||||
public function canUpload(User $user, int $fileSize = 0): bool
|
||||
{
|
||||
// Disable upload when user has more than 3 failed payments
|
||||
return ! ($user->failedPayments()->count() >= 3);
|
||||
}
|
||||
|
||||
public function canDownload(User $user): bool
|
||||
{
|
||||
// Disable download when user has more than 3 failed payments
|
||||
return ! ($user->failedPayments()->count() >= 3);
|
||||
}
|
||||
|
||||
public function canCreateFolder(User $user): bool
|
||||
{
|
||||
// Disable create folder when user has more than 3 failed payments
|
||||
return ! ($user->failedPayments()->count() >= 3);
|
||||
}
|
||||
|
||||
public function canCreateTeamFolder(User $user): bool
|
||||
{
|
||||
// Disable create folder when user has more than 3 failed payments
|
||||
return ! ($user->failedPayments()->count() >= 3);
|
||||
}
|
||||
|
||||
public function canInviteTeamMembers(User $user, array $newInvites = []): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canVisitShared(User $user): bool
|
||||
{
|
||||
// Disable share visit when user has more than 3 failed payments
|
||||
return ! ($user->failedPayments()->count() >= 3);
|
||||
}
|
||||
}
|
||||
@@ -10,21 +10,11 @@ class RestrictionsManager extends Manager
|
||||
{
|
||||
public function getDefaultDriver(): string
|
||||
{
|
||||
return get_restriction_driver();
|
||||
return 'default';
|
||||
}
|
||||
|
||||
public function createDefaultDriver(): DefaultRestrictionsEngine
|
||||
{
|
||||
return new DefaultRestrictionsEngine();
|
||||
}
|
||||
|
||||
public function createFixedDriver(): FixedBillingRestrictionsEngine
|
||||
{
|
||||
return new FixedBillingRestrictionsEngine();
|
||||
}
|
||||
|
||||
public function createMeteredDriver(): MeteredBillingRestrictionsEngine
|
||||
{
|
||||
return new MeteredBillingRestrictionsEngine();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user