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,39 @@
<?php
namespace Modules\Payment\Factories;
use Modules\Payment\Contracts\PaymentGatewayInterface;
use Modules\Payment\Enums\PaymentMethod;
use RuntimeException;
/**
* Resolves a PaymentGatewayInterface implementation by PaymentMethod.
*
* Replaces bnf_event's 3x duplicated `switch($payment_type)` at each call
* site (domain.md §6). Call sites depend only on this factory, never on a
* concrete gateway class swapping/adding a gateway is a `register()` call
* here, no controller/action changes.
*/
class PaymentGatewayFactory
{
/**
* @var array<string, class-string<PaymentGatewayInterface>>
*/
private array $bindings = [];
/**
* @param class-string<PaymentGatewayInterface> $gatewayClass
*/
public function register(PaymentMethod $method, string $gatewayClass): void
{
$this->bindings[$method->value] = $gatewayClass;
}
public function make(PaymentMethod $method): PaymentGatewayInterface
{
$gatewayClass = $this->bindings[$method->value]
?? throw new RuntimeException("No payment gateway registered for method [{$method->value}].");
return app($gatewayClass);
}
}