feat: trial
This commit is contained in:
@@ -92,7 +92,6 @@ class WaitlistInvite extends Command
|
||||
}
|
||||
private function send_email()
|
||||
{
|
||||
ray($this->next_patient->email, $this->password);
|
||||
$token = Crypt::encryptString("{$this->next_patient->email}@@@$this->password");
|
||||
$loginLink = route('auth.link', ['token' => $token]);
|
||||
$mail = new MailMessage();
|
||||
|
||||
@@ -30,7 +30,7 @@ class Help extends Component
|
||||
try {
|
||||
$this->rateLimit(1, 60);
|
||||
$this->validate();
|
||||
$subscriptionType = auth()->user()?->subscription?->type() ?? 'unknown';
|
||||
$subscriptionType = auth()->user()?->subscription?->type();
|
||||
$debug = "Route: {$this->path}";
|
||||
$mail = new MailMessage();
|
||||
$mail->view(
|
||||
|
||||
@@ -10,6 +10,7 @@ class PricingPlans extends Component
|
||||
{
|
||||
public function subscribeStripe($type)
|
||||
{
|
||||
$team = currentTeam();
|
||||
Stripe::setApiKey(config('subscription.stripe_api_key'));
|
||||
switch ($type) {
|
||||
case 'basic-monthly':
|
||||
@@ -50,10 +51,23 @@ class PricingPlans extends Component
|
||||
'automatic_tax' => [
|
||||
'enabled' => true,
|
||||
],
|
||||
|
||||
'mode' => 'subscription',
|
||||
'success_url' => route('dashboard', ['success' => true]),
|
||||
'cancel_url' => route('subscription.index', ['cancelled' => true]),
|
||||
];
|
||||
|
||||
if (!data_get($team,'subscription.stripe_trial_already_ended')) {
|
||||
$payload['subscription_data'] = [
|
||||
'trial_period_days' => 30,
|
||||
'trial_settings' => [
|
||||
'end_behavior' => [
|
||||
'missing_payment_method' => 'cancel',
|
||||
]
|
||||
],
|
||||
];
|
||||
$payload['payment_method_collection'] = 'if_required';
|
||||
}
|
||||
$customer = currentTeam()->subscription?->stripe_customer_id ?? null;
|
||||
if ($customer) {
|
||||
$payload['customer'] = $customer;
|
||||
|
||||
44
app/Jobs/SubscriptionTrialEndedJob.php
Executable file
44
app/Jobs/SubscriptionTrialEndedJob.php
Executable file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Team;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class SubscriptionTrialEndedJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
public Team $team
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
try {
|
||||
$session = getStripeCustomerPortalSession($this->team);
|
||||
$mail = new MailMessage();
|
||||
$mail->subject('Action required: You trial in Coolify Cloud ended.');
|
||||
$mail->view('emails.trial-ended', [
|
||||
'stripeCustomerPortal' => $session->url,
|
||||
]);
|
||||
$this->team->members()->each(function ($member) use ($mail) {
|
||||
if ($member->isAdmin()) {
|
||||
ray('Sending trial ended email to ' . $member->email);
|
||||
send_user_an_email($mail, $member->email);
|
||||
send_internal_notification('Trial reminder email sent to ' . $member->email);
|
||||
}
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
send_internal_notification('SubscriptionTrialEndsSoonJob failed with: ' . $e->getMessage());
|
||||
ray($e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
44
app/Jobs/SubscriptionTrialEndsSoonJob.php
Executable file
44
app/Jobs/SubscriptionTrialEndsSoonJob.php
Executable file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Team;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class SubscriptionTrialEndsSoonJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
public Team $team
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
try {
|
||||
$session = getStripeCustomerPortalSession($this->team);
|
||||
$mail = new MailMessage();
|
||||
$mail->subject('You trial in Coolify Cloud ends soon.');
|
||||
$mail->view('emails.trial-ends-soon', [
|
||||
'stripeCustomerPortal' => $session->url,
|
||||
]);
|
||||
$this->team->members()->each(function ($member) use ($mail) {
|
||||
if ($member->isAdmin()) {
|
||||
ray('Sending trial ending email to ' . $member->email);
|
||||
send_user_an_email($mail, $member->email);
|
||||
send_internal_notification('Trial reminder email sent to ' . $member->email);
|
||||
}
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
send_internal_notification('SubscriptionTrialEndsSoonJob failed with: ' . $e->getMessage());
|
||||
ray($e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ class Subscription extends Model
|
||||
}
|
||||
if (isStripe()) {
|
||||
if (!$this->stripe_plan_id) {
|
||||
return 'unknown';
|
||||
return 'zero';
|
||||
}
|
||||
$subscription = Subscription::where('id', $this->id)->first();
|
||||
if (!$subscription) {
|
||||
@@ -54,6 +54,6 @@ class Subscription extends Model
|
||||
return Str::of($stripePlanId)->after('stripe_price_id_')->before('_')->lower();
|
||||
}
|
||||
}
|
||||
return 'unknown';
|
||||
return 'zero';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,4 +120,20 @@ class Team extends Model implements SendsDiscord, SendsEmail
|
||||
{
|
||||
return $this->hasMany(S3Storage::class);
|
||||
}
|
||||
public function trialEnded() {
|
||||
foreach ($this->servers as $server) {
|
||||
$server->settings()->update([
|
||||
'is_usable' => false,
|
||||
'is_reachable' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
public function trialEndedButSubscribed() {
|
||||
foreach ($this->servers as $server) {
|
||||
$server->settings()->update([
|
||||
'is_usable' => true,
|
||||
'is_reachable' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user