79 lines
2.0 KiB
PHP
79 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Tenancy\HasTenant;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Support\Str;
|
|
use Spatie\Activitylog\LogOptions;
|
|
use Spatie\Activitylog\Traits\LogsActivity;
|
|
|
|
class Payment extends Model
|
|
{
|
|
use HasFactory, HasTenant, LogsActivity;
|
|
|
|
public const PURPOSE_RESIDENT = 'resident_code_purchase';
|
|
|
|
public const PURPOSE_STORE_WHOLESALE = 'store_inventory_purchase';
|
|
|
|
public const STATUS_PENDING = 'pending';
|
|
|
|
public const STATUS_PROCESSING = 'processing';
|
|
|
|
public const STATUS_PAID = 'paid';
|
|
|
|
public const STATUS_FAILED = 'failed';
|
|
|
|
public const STATUS_REFUNDED = 'refunded';
|
|
|
|
public const PROVIDER_PAYMONGO = 'paymongo';
|
|
|
|
public const PROVIDER_MANUAL = 'manual';
|
|
|
|
protected $fillable = [
|
|
'uuid', 'tenant_id', 'payer_user_id', 'purpose', 'amount_centavos', 'currency',
|
|
'provider', 'provider_payment_id', 'status', 'provider_data',
|
|
'metadata', 'paid_at',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'amount_centavos' => 'integer',
|
|
'provider_data' => 'array',
|
|
'metadata' => 'array',
|
|
'paid_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function getRouteKeyName(): string
|
|
{
|
|
return 'uuid';
|
|
}
|
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logOnly(['status', 'amount_centavos', 'provider', 'paid_at'])
|
|
->logOnlyDirty()
|
|
->dontSubmitEmptyLogs()
|
|
->useLogName('payment');
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $p): void {
|
|
if (empty($p->uuid)) {
|
|
$p->uuid = (string) Str::uuid();
|
|
}
|
|
});
|
|
}
|
|
|
|
public function payer(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'payer_user_id');
|
|
}
|
|
}
|