feat: revenue cat
CI / 🧪 Tests Laravel (push) Successful in 2m24s
CI / 🐳 Build & Push Image (push) Successful in 1m13s

This commit is contained in:
2026-08-12 16:00:11 +02:00
parent 31633cfd2c
commit 29e85589b0
55 changed files with 703 additions and 2363 deletions
-52
View File
@@ -1,52 +0,0 @@
<?php
namespace App\Models;
use App\Enums\BillingProductPurpose;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class BillingProduct extends Model
{
use HasFactory, HasUlids;
protected $fillable = [
'name',
'description',
'purpose',
'amount',
'currency',
'stripe_product_id',
'stripe_price_id',
'is_active',
'sort_order',
];
public function paymentTransactions(): HasMany
{
return $this->hasMany(PaymentTransaction::class);
}
public function scopeActive(Builder $query): Builder
{
return $query->where('is_active', true);
}
public function formattedAmount(): string
{
return number_format($this->amount / 100, 2, ',', ' ').' '.strtoupper($this->currency);
}
protected function casts(): array
{
return [
'purpose' => BillingProductPurpose::class,
'amount' => 'integer',
'is_active' => 'boolean',
'sort_order' => 'integer',
];
}
}
-61
View File
@@ -1,61 +0,0 @@
<?php
namespace App\Models;
use App\Enums\PaymentTransactionStatus;
use App\Enums\PaymentTransactionType;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PaymentTransaction extends Model
{
/** @use HasFactory<\Database\Factories\PaymentTransactionFactory> */
use HasFactory, HasUlids;
protected $fillable = [
'user_id',
'billing_product_id',
'type',
'status',
'stripe_event_id',
'stripe_event_type',
'stripe_customer_id',
'stripe_checkout_session_id',
'stripe_invoice_id',
'stripe_payment_intent_id',
'stripe_subscription_id',
'stripe_price_id',
'amount',
'currency',
'invoice_url',
'invoice_pdf_url',
'invoice_email_sent_at',
'error_message',
'payload',
'processed_at',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function billingProduct(): BelongsTo
{
return $this->belongsTo(BillingProduct::class);
}
protected function casts(): array
{
return [
'type' => PaymentTransactionType::class,
'status' => PaymentTransactionStatus::class,
'amount' => 'integer',
'invoice_email_sent_at' => 'datetime',
'payload' => 'array',
'processed_at' => 'datetime',
];
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Model;
class RevenueCatWebhookEvent extends Model
{
use HasUlids;
protected $fillable = [
'event_id',
'type',
'app_user_id',
'product_id',
'entitlement_ids',
'environment',
'payload',
'processed_at',
];
protected function casts(): array
{
return [
'entitlement_ids' => 'array',
'payload' => 'array',
'processed_at' => 'datetime',
];
}
}
+17 -13
View File
@@ -25,13 +25,12 @@ use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Storage;
use Laravel\Cashier\Billable;
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable implements FilamentUser, HasAvatar, HasLocalePreference, MustVerifyEmail
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use Billable, HasApiTokens, HasFactory, HasUlids, Notifiable, SoftDeletes;
use HasApiTokens, HasFactory, HasUlids, Notifiable, SoftDeletes;
protected $attributes = [
'social_notifications_enabled' => true,
@@ -55,7 +54,10 @@ class User extends Authenticatable implements FilamentUser, HasAvatar, HasLocale
'bio',
'account_verified_at',
'certification_purchased_at',
'trial_ends_at',
'subscription_product_id',
'subscription_store',
'subscription_expires_at',
'subscription_is_trial',
'daily_calorie_goal',
'daily_protein_goal',
'daily_carbs_goal',
@@ -109,7 +111,8 @@ class User extends Authenticatable implements FilamentUser, HasAvatar, HasLocale
'social_notifications_enabled' => 'boolean',
'engagement_reminders_enabled' => 'boolean',
'suspended_at' => 'datetime',
'trial_ends_at' => 'datetime',
'subscription_expires_at' => 'datetime',
'subscription_is_trial' => 'boolean',
];
}
@@ -133,11 +136,6 @@ class User extends Authenticatable implements FilamentUser, HasAvatar, HasLocale
return $this->hasMany(AiUsage::class);
}
public function paymentTransactions(): HasMany
{
return $this->hasMany(PaymentTransaction::class);
}
public function identityVerificationRequest(): HasOne
{
return $this->hasOne(IdentityVerificationRequest::class);
@@ -229,16 +227,22 @@ class User extends Authenticatable implements FilamentUser, HasAvatar, HasLocale
public function canAnalyzeMeals(): bool
{
return $this->subscribed('default') || $this->onGenericTrial();
return $this->hasActiveSubscription();
}
public function analysisAccessLevel(): string
{
if ($this->subscribed('default')) {
return 'subscribed';
if (! $this->hasActiveSubscription()) {
return 'free';
}
return $this->onGenericTrial() ? 'trial' : 'free';
return $this->subscription_is_trial ? 'trial' : 'subscribed';
}
public function hasActiveSubscription(): bool
{
return $this->subscription_product_id !== null
&& $this->subscription_expires_at?->isFuture() === true;
}
public function hasPurchasedCertification(): bool