Deploy Ladill Events / deploy (push) Successful in 38s
Show per-event payment history with fees and net amounts, and let organizers manage payout accounts and withdrawals without leaving the app. Co-authored-by: Cursor <cursoragent@cursor.com>
86 lines
2.1 KiB
PHP
86 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class QrEventRegistration extends Model
|
|
{
|
|
public const STATUS_PENDING = 'pending';
|
|
public const STATUS_CONFIRMED = 'confirmed';
|
|
public const STATUS_FAILED = 'failed';
|
|
public const STATUS_CANCELLED = 'cancelled';
|
|
|
|
protected $fillable = [
|
|
'pay_order_id',
|
|
'qr_code_id',
|
|
'user_id',
|
|
'reference',
|
|
'badge_code',
|
|
'tier_name',
|
|
'amount_minor',
|
|
'currency',
|
|
'attendee_name',
|
|
'attendee_email',
|
|
'attendee_phone',
|
|
'badge_fields',
|
|
'status',
|
|
'payment_reference',
|
|
'paid_at',
|
|
'checked_in_at',
|
|
'metadata',
|
|
];
|
|
|
|
protected $casts = [
|
|
'badge_fields' => 'array',
|
|
'metadata' => 'array',
|
|
'amount_minor' => 'integer',
|
|
'paid_at' => 'datetime',
|
|
'checked_in_at' => 'datetime',
|
|
];
|
|
|
|
public function qrCode(): BelongsTo
|
|
{
|
|
return $this->belongsTo(QrCode::class);
|
|
}
|
|
|
|
public function organizer(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
}
|
|
|
|
public function amountCedis(): float
|
|
{
|
|
return round($this->amount_minor / 100, 2);
|
|
}
|
|
|
|
public function platformFeeMinor(): int
|
|
{
|
|
$metadata = (array) ($this->metadata ?? []);
|
|
|
|
if (isset($metadata['ladill_pay']['platform_fee_minor'])) {
|
|
return (int) $metadata['ladill_pay']['platform_fee_minor'];
|
|
}
|
|
|
|
if (isset($metadata['platform_fee_ghs'])) {
|
|
return (int) round((float) $metadata['platform_fee_ghs'] * 100);
|
|
}
|
|
|
|
$mode = $this->qrCode?->content()['mode'] ?? 'ticketing';
|
|
$rate = $mode === 'contributions' ? 0.035 : 0.055;
|
|
|
|
return (int) round($this->amount_minor * $rate);
|
|
}
|
|
|
|
public function netAmountMinor(): int
|
|
{
|
|
return max(0, $this->amount_minor - $this->platformFeeMinor());
|
|
}
|
|
|
|
public function isPaid(): bool
|
|
{
|
|
return $this->amount_minor > 0;
|
|
}
|
|
}
|