fix: version should come from constants + fix stripe webhook error reporting

This commit is contained in:
Andras Bacsai
2024-11-25 11:28:08 +01:00
parent 6ad2e18060
commit 37d4d5f98c
10 changed files with 215 additions and 211 deletions

View File

@@ -31,7 +31,7 @@ class UpdateCoolify
} }
CleanupDocker::dispatch($this->server); CleanupDocker::dispatch($this->server);
$this->latestVersion = get_latest_version_of_coolify(); $this->latestVersion = get_latest_version_of_coolify();
$this->currentVersion = config('version'); $this->currentVersion = config('constants.coolify.version');
if (! $manual_update) { if (! $manual_update) {
if (! $settings->is_auto_update_enabled) { if (! $settings->is_auto_update_enabled) {
return; return;

View File

@@ -200,7 +200,7 @@ class Init extends Command
private function restore_coolify_db_backup() private function restore_coolify_db_backup()
{ {
if (version_compare('4.0.0-beta.179', config('version'), '<=')) { if (version_compare('4.0.0-beta.179', config('constants.coolify.version'), '<=')) {
try { try {
$database = StandalonePostgresql::withTrashed()->find(0); $database = StandalonePostgresql::withTrashed()->find(0);
if ($database && $database->trashed()) { if ($database && $database->trashed()) {
@@ -228,7 +228,7 @@ class Init extends Command
private function send_alive_signal() private function send_alive_signal()
{ {
$id = config('app.id'); $id = config('app.id');
$version = config('version'); $version = config('constants.coolify.version');
$settings = instanceSettings(); $settings = instanceSettings();
$do_not_track = data_get($settings, 'do_not_track'); $do_not_track = data_get($settings, 'do_not_track');
if ($do_not_track == true) { if ($do_not_track == true) {
@@ -264,7 +264,7 @@ class Init extends Command
private function replace_slash_in_environment_name() private function replace_slash_in_environment_name()
{ {
if (version_compare('4.0.0-beta.298', config('version'), '<=')) { if (version_compare('4.0.0-beta.298', config('constants.coolify.version'), '<=')) {
$environments = Environment::all(); $environments = Environment::all();
foreach ($environments as $environment) { foreach ($environments as $environment) {
if (str_contains($environment->name, '/')) { if (str_contains($environment->name, '/')) {

View File

@@ -37,7 +37,7 @@ class OtherController extends Controller
)] )]
public function version(Request $request) public function version(Request $request)
{ {
return response(config('version')); return response(config('constants.coolify.version'));
} }
#[OA\Get( #[OA\Get(

View File

@@ -27,7 +27,7 @@ class CheckForUpdatesJob implements ShouldBeEncrypted, ShouldQueue
$versions = $response->json(); $versions = $response->json();
$latest_version = data_get($versions, 'coolify.v4.version'); $latest_version = data_get($versions, 'coolify.v4.version');
$current_version = config('version'); $current_version = config('constants.coolify.version');
if (version_compare($latest_version, $current_version, '>')) { if (version_compare($latest_version, $current_version, '>')) {
// New version available // New version available

View File

@@ -25,6 +25,7 @@ class StripeProcessJob implements ShouldQueue
public function handle(): void public function handle(): void
{ {
try {
$excludedPlans = config('subscription.stripe_excluded_plans'); $excludedPlans = config('subscription.stripe_excluded_plans');
$type = data_get($this->event, 'type'); $type = data_get($this->event, 'type');
@@ -51,7 +52,7 @@ class StripeProcessJob implements ShouldQueue
send_internal_notification("Early fraud warning created Refunded, subscription canceled. Charge: {$charge}, id: {$id}, pi: {$pi}"); send_internal_notification("Early fraud warning created Refunded, subscription canceled. Charge: {$charge}, id: {$id}, pi: {$pi}");
} else { } else {
send_internal_notification("Early fraud warning: subscription not found. Charge: {$charge}, id: {$id}, pi: {$pi}"); send_internal_notification("Early fraud warning: subscription not found. Charge: {$charge}, id: {$id}, pi: {$pi}");
throw new \Exception("Early fraud warning: subscription not found. Charge: {$charge}, id: {$id}, pi: {$pi}"); throw new \RuntimeException("Early fraud warning: subscription not found. Charge: {$charge}, id: {$id}, pi: {$pi}");
} }
break; break;
case 'checkout.session.completed': case 'checkout.session.completed':
@@ -68,7 +69,7 @@ class StripeProcessJob implements ShouldQueue
$found = $team->members->where('id', $userId)->first(); $found = $team->members->where('id', $userId)->first();
if (! $found->isAdmin()) { if (! $found->isAdmin()) {
send_internal_notification("User {$userId} is not an admin or owner of team {$team->id}, customerid: {$customerId}, subscriptionid: {$subscriptionId}."); send_internal_notification("User {$userId} is not an admin or owner of team {$team->id}, customerid: {$customerId}, subscriptionid: {$subscriptionId}.");
throw new \Exception("User {$userId} is not an admin or owner of team {$team->id}, customerid: {$customerId}, subscriptionid: {$subscriptionId}."); throw new \RuntimeException("User {$userId} is not an admin or owner of team {$team->id}, customerid: {$customerId}, subscriptionid: {$subscriptionId}.");
} }
$subscription = Subscription::where('team_id', $teamId)->first(); $subscription = Subscription::where('team_id', $teamId)->first();
if ($subscription) { if ($subscription) {
@@ -101,7 +102,7 @@ class StripeProcessJob implements ShouldQueue
'stripe_invoice_paid' => true, 'stripe_invoice_paid' => true,
]); ]);
} else { } else {
throw new \Exception("No subscription found for customer: {$customerId}"); throw new \RuntimeException("No subscription found for customer: {$customerId}");
} }
break; break;
case 'invoice.payment_failed': case 'invoice.payment_failed':
@@ -109,12 +110,12 @@ class StripeProcessJob implements ShouldQueue
$subscription = Subscription::where('stripe_customer_id', $customerId)->first(); $subscription = Subscription::where('stripe_customer_id', $customerId)->first();
if (! $subscription) { if (! $subscription) {
send_internal_notification('invoice.payment_failed failed but no subscription found in Coolify for customer: '.$customerId); send_internal_notification('invoice.payment_failed failed but no subscription found in Coolify for customer: '.$customerId);
throw new \Exception("No subscription found for customer: {$customerId}"); throw new \RuntimeException("No subscription found for customer: {$customerId}");
} }
$team = data_get($subscription, 'team'); $team = data_get($subscription, 'team');
if (! $team) { if (! $team) {
send_internal_notification('invoice.payment_failed failed but no team found in Coolify for customer: '.$customerId); send_internal_notification('invoice.payment_failed failed but no team found in Coolify for customer: '.$customerId);
throw new \Exception("No team found in Coolify for customer: {$customerId}"); throw new \RuntimeException("No team found in Coolify for customer: {$customerId}");
} }
if (! $subscription->stripe_invoice_paid) { if (! $subscription->stripe_invoice_paid) {
SubscriptionInvoiceFailedJob::dispatch($team); SubscriptionInvoiceFailedJob::dispatch($team);
@@ -128,7 +129,7 @@ class StripeProcessJob implements ShouldQueue
$subscription = Subscription::where('stripe_customer_id', $customerId)->first(); $subscription = Subscription::where('stripe_customer_id', $customerId)->first();
if (! $subscription) { if (! $subscription) {
send_internal_notification('payment_intent.payment_failed, no subscription found in Coolify for customer: '.$customerId); send_internal_notification('payment_intent.payment_failed, no subscription found in Coolify for customer: '.$customerId);
throw new \Exception("No subscription found in Coolify for customer: {$customerId}"); throw new \RuntimeException("No subscription found in Coolify for customer: {$customerId}");
} }
if ($subscription->stripe_invoice_paid) { if ($subscription->stripe_invoice_paid) {
send_internal_notification('payment_intent.payment_failed but invoice is active for customer: '.$customerId); send_internal_notification('payment_intent.payment_failed but invoice is active for customer: '.$customerId);
@@ -145,20 +146,20 @@ class StripeProcessJob implements ShouldQueue
if (! $teamId || ! $userId) { if (! $teamId || ! $userId) {
$subscription = Subscription::where('stripe_customer_id', $customerId)->first(); $subscription = Subscription::where('stripe_customer_id', $customerId)->first();
if ($subscription) { if ($subscription) {
throw new \Exception("Subscription already exists for customer: {$customerId}"); throw new \RuntimeException("Subscription already exists for customer: {$customerId}");
} }
throw new \Exception('No team id or user id found'); throw new \RuntimeException('No team id or user id found');
} }
$team = Team::find($teamId); $team = Team::find($teamId);
$found = $team->members->where('id', $userId)->first(); $found = $team->members->where('id', $userId)->first();
if (! $found->isAdmin()) { if (! $found->isAdmin()) {
send_internal_notification("User {$userId} is not an admin or owner of team {$team->id}, customerid: {$customerId}."); send_internal_notification("User {$userId} is not an admin or owner of team {$team->id}, customerid: {$customerId}.");
throw new \Exception("User {$userId} is not an admin or owner of team {$team->id}, customerid: {$customerId}."); throw new \RuntimeException("User {$userId} is not an admin or owner of team {$team->id}, customerid: {$customerId}.");
} }
$subscription = Subscription::where('team_id', $teamId)->first(); $subscription = Subscription::where('team_id', $teamId)->first();
if ($subscription) { if ($subscription) {
send_internal_notification("Subscription already exists for team: {$teamId}"); send_internal_notification("Subscription already exists for team: {$teamId}");
throw new \Exception("Subscription already exists for team: {$teamId}"); throw new \RuntimeException("Subscription already exists for team: {$teamId}");
} else { } else {
Subscription::create([ Subscription::create([
'team_id' => $teamId, 'team_id' => $teamId,
@@ -182,7 +183,7 @@ class StripeProcessJob implements ShouldQueue
if (! $subscription) { if (! $subscription) {
if ($status === 'incomplete_expired') { if ($status === 'incomplete_expired') {
send_internal_notification('Subscription incomplete expired'); send_internal_notification('Subscription incomplete expired');
throw new \Exception('Subscription incomplete expired'); throw new \RuntimeException('Subscription incomplete expired');
} }
if ($teamId) { if ($teamId) {
$subscription = Subscription::create([ $subscription = Subscription::create([
@@ -193,7 +194,7 @@ class StripeProcessJob implements ShouldQueue
]); ]);
} else { } else {
send_internal_notification('No subscription and team id found'); send_internal_notification('No subscription and team id found');
throw new \Exception('No subscription and team id found'); throw new \RuntimeException('No subscription and team id found');
} }
} }
$cancelAtPeriodEnd = data_get($data, 'cancel_at_period_end'); $cancelAtPeriodEnd = data_get($data, 'cancel_at_period_end');
@@ -236,7 +237,10 @@ class StripeProcessJob implements ShouldQueue
$team?->subscriptionEnded(); $team?->subscriptionEnded();
break; break;
default: default:
// Unhandled event type throw new \RuntimeException("Unhandled event type: {$type}");
}
} catch (\Exception $e) {
send_internal_notification('StripeProcessJob error: '.$e->getMessage());
} }
} }
} }

View File

@@ -71,7 +71,7 @@ class EnvironmentVariable extends Model
} }
} }
$environment_variable->update([ $environment_variable->update([
'version' => config('version'), 'version' => config('constants.coolify.version'),
]); ]);
}); });
static::saving(function (EnvironmentVariable $environmentVariable) { static::saving(function (EnvironmentVariable $environmentVariable) {

View File

@@ -46,7 +46,7 @@ class DiscordMessage
public function toPayload(): array public function toPayload(): array
{ {
$footerText = 'Coolify v'.config('version'); $footerText = 'Coolify v'.config('constants.coolify.version');
if (isCloud()) { if (isCloud()) {
$footerText = 'Coolify Cloud'; $footerText = 'Coolify Cloud';
} }

View File

@@ -1,4 +1,4 @@
<?php <?php
$version = include 'config/version.php'; $version = include 'config/constants.php';
echo $version; echo $version['coolify']['version'] ?: 'unknown';

View File

@@ -192,7 +192,7 @@ function defaultLabels($id, $name, $pull_request_id = 0, string $type = 'applica
{ {
$labels = collect([]); $labels = collect([]);
$labels->push('coolify.managed=true'); $labels->push('coolify.managed=true');
$labels->push('coolify.version='.config('version')); $labels->push('coolify.version='.config('constants.coolify.version'));
$labels->push('coolify.'.$type.'Id='.$id); $labels->push('coolify.'.$type.'Id='.$id);
$labels->push("coolify.type=$type"); $labels->push("coolify.type=$type");
$labels->push('coolify.name='.$name); $labels->push('coolify.name='.$name);

View File

@@ -1,4 +1,4 @@
<a {{ $attributes->merge(['class' => 'text-xs cursor-pointer opacity-90 hover:opacity-100 dark:hover:text-white hover:text-black']) }} <a {{ $attributes->merge(['class' => 'text-xs cursor-pointer opacity-90 hover:opacity-100 dark:hover:text-white hover:text-black']) }}
href="https://github.com/coollabsio/coolify/releases/tag/v{{ config('version') }}" target="_blank"> href="https://github.com/coollabsio/coolify/releases/tag/v{{ config('constants.coolify.version') }}" target="_blank">
v{{ config('version') }} v{{ config('constants.coolify.version') }}
</a> </a>