feat: clean credits users
This commit is contained in:
@@ -3,24 +3,20 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\BillingProductPurpose;
|
||||
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
|
||||
class BillingProduct extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\CreditProductFactory> */
|
||||
use HasFactory, HasUlids;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
'type',
|
||||
'purpose',
|
||||
'credits',
|
||||
'amount',
|
||||
'currency',
|
||||
'stripe_product_id',
|
||||
@@ -29,11 +25,6 @@ class CreditProduct extends Model
|
||||
'sort_order',
|
||||
];
|
||||
|
||||
public function ledgerEntries(): HasMany
|
||||
{
|
||||
return $this->hasMany(CreditLedgerEntry::class);
|
||||
}
|
||||
|
||||
public function paymentTransactions(): HasMany
|
||||
{
|
||||
return $this->hasMany(PaymentTransaction::class);
|
||||
@@ -52,9 +43,7 @@ class CreditProduct extends Model
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'type' => CreditProductType::class,
|
||||
'purpose' => BillingProductPurpose::class,
|
||||
'credits' => 'integer',
|
||||
'amount' => 'integer',
|
||||
'is_active' => 'boolean',
|
||||
'sort_order' => 'integer',
|
||||
@@ -1,49 +0,0 @@
|
||||
<?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',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -16,8 +16,7 @@ class PaymentTransaction extends Model
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'credit_product_id',
|
||||
'credit_ledger_entry_id',
|
||||
'billing_product_id',
|
||||
'type',
|
||||
'status',
|
||||
'stripe_event_id',
|
||||
@@ -30,8 +29,6 @@ class PaymentTransaction extends Model
|
||||
'stripe_price_id',
|
||||
'amount',
|
||||
'currency',
|
||||
'credits_expected',
|
||||
'credits_granted',
|
||||
'invoice_url',
|
||||
'invoice_pdf_url',
|
||||
'invoice_email_sent_at',
|
||||
@@ -45,14 +42,9 @@ class PaymentTransaction extends Model
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function creditProduct(): BelongsTo
|
||||
public function billingProduct(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CreditProduct::class);
|
||||
}
|
||||
|
||||
public function creditLedgerEntry(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CreditLedgerEntry::class);
|
||||
return $this->belongsTo(BillingProduct::class);
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
@@ -61,8 +53,6 @@ class PaymentTransaction extends Model
|
||||
'type' => PaymentTransactionType::class,
|
||||
'status' => PaymentTransactionStatus::class,
|
||||
'amount' => 'integer',
|
||||
'credits_expected' => 'integer',
|
||||
'credits_granted' => 'integer',
|
||||
'invoice_email_sent_at' => 'datetime',
|
||||
'payload' => 'array',
|
||||
'processed_at' => 'datetime',
|
||||
|
||||
@@ -61,7 +61,6 @@ class User extends Authenticatable implements FilamentUser, HasAvatar, HasLocale
|
||||
'suspended_at',
|
||||
'suspended_by',
|
||||
'suspended_reason',
|
||||
'ai_credits_balance',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -98,7 +97,6 @@ class User extends Authenticatable implements FilamentUser, HasAvatar, HasLocale
|
||||
'date_of_birth' => 'immutable_date',
|
||||
'suspended_at' => 'datetime',
|
||||
'trial_ends_at' => 'datetime',
|
||||
'ai_credits_balance' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -122,11 +120,6 @@ class User extends Authenticatable implements FilamentUser, HasAvatar, HasLocale
|
||||
return $this->hasMany(AiUsage::class);
|
||||
}
|
||||
|
||||
public function creditLedgerEntries(): HasMany
|
||||
{
|
||||
return $this->hasMany(CreditLedgerEntry::class);
|
||||
}
|
||||
|
||||
public function paymentTransactions(): HasMany
|
||||
{
|
||||
return $this->hasMany(PaymentTransaction::class);
|
||||
|
||||
Reference in New Issue
Block a user