Initial payment setup
This commit is contained in:
parent
8b054bcbf0
commit
21bcd43972
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum PaymentMethod: string
|
||||
{
|
||||
case CASH = 'cash';
|
||||
case CHECK = 'check';
|
||||
case CARD = 'card';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::CASH => 'Cash',
|
||||
self::CHECK => 'Check',
|
||||
self::CARD => 'Card',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum PaymentStatus: string
|
||||
{
|
||||
case PENDING = 'pending';
|
||||
case COMPLETED = 'completed';
|
||||
case FAILED = 'failed';
|
||||
case REFUNDED = 'refunded';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::PENDING => 'Pending',
|
||||
self::COMPLETED => 'Completed',
|
||||
self::FAILED => 'Failed',
|
||||
self::REFUNDED => 'Refunded',
|
||||
};
|
||||
}
|
||||
|
||||
public function color(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::PENDING => 'amber',
|
||||
self::COMPLETED => 'green',
|
||||
self::FAILED => 'red',
|
||||
self::REFUNDED => 'zinc',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,8 @@ use Illuminate\Database\Eloquent\Model;
|
|||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
|
||||
class Client extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
|
@ -41,6 +43,11 @@ class Client extends Model
|
|||
return $this->hasMany(Invoice::class);
|
||||
}
|
||||
|
||||
public function payments(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(Payment::class, Invoice::class);
|
||||
}
|
||||
|
||||
public function secondaryContacts(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Contact::class)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Casts\MoneyCast;
|
||||
use App\Enums\PaymentMethod;
|
||||
use App\Enums\PaymentStatus;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Payment extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'invoice_id',
|
||||
'contact_id',
|
||||
'payment_date',
|
||||
'status',
|
||||
'payment_method',
|
||||
'reference',
|
||||
'stripe_payment_intent_id',
|
||||
'fee_amount',
|
||||
'amount',
|
||||
'notes',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'payment_date' => 'date',
|
||||
'amount' => MoneyCast::class,
|
||||
'fee_amount' => MoneyCast::class,
|
||||
'status' => PaymentStatus::class,
|
||||
'payment_method' => PaymentMethod::class,
|
||||
];
|
||||
|
||||
public function invoice(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Invoice::class);
|
||||
}
|
||||
|
||||
public function contact(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Contact::class);
|
||||
}
|
||||
|
||||
public function client(): BelongsTo
|
||||
{
|
||||
return $this->invoice->client();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Contact;
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('payments', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignIdFor(Invoice::class)->constrained();
|
||||
$table->foreignIdFor(Contact::class)->nullable()->constrained();
|
||||
$table->date('payment_date');
|
||||
$table->string('status')->default('pending'); // Accordint to claude,needed by Stripe. pending, completed, failed, refunded
|
||||
$table->string('payment_method');
|
||||
$table->string('reference')->nullable();
|
||||
$table->string('stripe_payment_intent_id')->nullable();
|
||||
$table->integer('fee_amount')->nullable();
|
||||
$table->integer('amount');
|
||||
$table->text('notes')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('payments');
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue