Add Payment module: contracts, payments/refunds tables, KBZ gateway, factory, orchestrator (T5.1-T5.7)

- T5.1 PaymentGatewayInterface, DTOs, PaymentMethod/PaymentStatus/RefundStatus enums
- T5.2 payments/refunds tables, models, factories
- T5.3-T5.5 KbzMiniAppGateway: initiate()/verify()/refund(), ported KBZ signing scheme,
  wired refund_amount through for partial refunds, mTLS options for refund
- T5.6 PaymentGatewayFactory resolving gateways by PaymentMethod
- T5.7 PaymentService orchestrator delegating to the resolved gateway
This commit is contained in:
Nyan Lin Paing
2026-08-08 22:42:16 +07:00
parent e0bcc5f81a
commit 4737838021
28 changed files with 1407 additions and 1 deletions
@@ -0,0 +1,63 @@
<?php
namespace Modules\Payment\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Modules\Booking\Models\Booking;
use Modules\Payment\Database\Factories\PaymentFactory;
use Modules\Payment\Enums\PaymentMethod;
use Modules\Payment\Enums\PaymentStatus;
/**
* One attempt to pay for a Booking through a gateway a Booking can have
* more than one Payment row if an earlier attempt failed and the customer
* retried (domain.md §1).
*/
class Payment extends Model
{
/** @use HasFactory<PaymentFactory> */
use HasFactory;
/**
* @var list<string>
*/
protected $fillable = [
'booking_id',
'gateway',
'status',
'amount',
'currency',
'gateway_transaction_id',
'gateway_payload',
'initiated_at',
'completed_at',
];
/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'gateway' => PaymentMethod::class,
'status' => PaymentStatus::class,
'amount' => 'decimal:2',
'gateway_payload' => 'array',
'initiated_at' => 'datetime',
'completed_at' => 'datetime',
];
}
public function booking(): BelongsTo
{
return $this->belongsTo(Booking::class);
}
public function refunds(): HasMany
{
return $this->hasMany(Refund::class);
}
}
+60
View File
@@ -0,0 +1,60 @@
<?php
namespace Modules\Payment\Models;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Modules\Payment\Database\Factories\RefundFactory;
use Modules\Payment\Enums\RefundStatus;
/**
* A reversal against a specific successful Payment (not against the Booking
* directly) a Payment can have more than one Refund row for partial
* refunds (domain.md §1, §6).
*/
class Refund extends Model
{
/** @use HasFactory<RefundFactory> */
use HasFactory;
/**
* @var list<string>
*/
protected $fillable = [
'payment_id',
'status',
'amount',
'reason',
'gateway_refund_id',
'gateway_payload',
'requested_by',
'requested_at',
'completed_at',
];
/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'status' => RefundStatus::class,
'amount' => 'decimal:2',
'gateway_payload' => 'array',
'requested_at' => 'datetime',
'completed_at' => 'datetime',
];
}
public function payment(): BelongsTo
{
return $this->belongsTo(Payment::class);
}
public function requestedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'requested_by');
}
}