feat: stripe
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\CreditLedgerEntryType;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class CreditLedgerEntry extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\CreditLedgerEntryFactory> */
|
||||
use HasFactory, HasUlids;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'credit_product_id',
|
||||
'type',
|
||||
'credits',
|
||||
'balance_after',
|
||||
'source',
|
||||
'stripe_checkout_session_id',
|
||||
'stripe_invoice_id',
|
||||
'stripe_payment_intent_id',
|
||||
'stripe_subscription_id',
|
||||
'metadata',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function creditProduct(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CreditProduct::class);
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'type' => CreditLedgerEntryType::class,
|
||||
'credits' => 'integer',
|
||||
'balance_after' => 'integer',
|
||||
'metadata' => 'array',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\CreditProductType;
|
||||
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 CreditProduct extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\CreditProductFactory> */
|
||||
use HasFactory, HasUlids;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
'type',
|
||||
'credits',
|
||||
'amount',
|
||||
'currency',
|
||||
'stripe_product_id',
|
||||
'stripe_price_id',
|
||||
'is_active',
|
||||
'sort_order',
|
||||
];
|
||||
|
||||
public function ledgerEntries(): HasMany
|
||||
{
|
||||
return $this->hasMany(CreditLedgerEntry::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 [
|
||||
'type' => CreditProductType::class,
|
||||
'credits' => 'integer',
|
||||
'amount' => 'integer',
|
||||
'is_active' => 'boolean',
|
||||
'sort_order' => 'integer',
|
||||
];
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -23,12 +23,13 @@ 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 HasApiTokens, HasFactory, HasUlids, Notifiable, SoftDeletes;
|
||||
use Billable, HasApiTokens, HasFactory, HasUlids, Notifiable, SoftDeletes;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
@@ -58,6 +59,7 @@ class User extends Authenticatable implements FilamentUser, HasAvatar, HasLocale
|
||||
'suspended_at',
|
||||
'suspended_by',
|
||||
'suspended_reason',
|
||||
'ai_credits_balance',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -92,6 +94,8 @@ class User extends Authenticatable implements FilamentUser, HasAvatar, HasLocale
|
||||
'role' => UserRole::class,
|
||||
'date_of_birth' => 'immutable_date',
|
||||
'suspended_at' => 'datetime',
|
||||
'trial_ends_at' => 'datetime',
|
||||
'ai_credits_balance' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -115,6 +119,11 @@ class User extends Authenticatable implements FilamentUser, HasAvatar, HasLocale
|
||||
return $this->hasMany(AiUsage::class);
|
||||
}
|
||||
|
||||
public function creditLedgerEntries(): HasMany
|
||||
{
|
||||
return $this->hasMany(CreditLedgerEntry::class);
|
||||
}
|
||||
|
||||
public function workouts(): HasMany
|
||||
{
|
||||
return $this->hasMany(WorkoutSessions::class);
|
||||
|
||||
Reference in New Issue
Block a user