52 lines
1.8 KiB
PHP
52 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Modules\Core\Payment\Drivers;
|
|
|
|
use Illuminate\Support\Str;
|
|
use Lunar\DataTypes\Price;
|
|
use Modules\Core\Payment\Contracts\Configurable;
|
|
use Modules\Core\Payment\Contracts\SupportsPay;
|
|
use Modules\Core\Payment\DTOs\PaymentResult;
|
|
use Modules\Core\Payment\Enums\PaymentResultStatus;
|
|
use Modules\Core\Payment\Events\PaymentCaptured;
|
|
|
|
/**
|
|
* Cash-in-hand — a shopper paying in person at the moment of pickup, with
|
|
* nothing left to reconcile afterward, so capture is immediate. NOT used
|
|
* for cash-on-delivery, which has its own Modules\Core\Payment\Drivers\
|
|
* CashOnDeliveryPaymentDriver — COD payment happens at an unpredictable
|
|
* later time (same-day to months), so it must not capture immediately the
|
|
* way this driver does. There is no separate hold-then-settle model
|
|
* (SupportsAuthorization/SupportsCaptures/SupportsVoids) and no async
|
|
* resolution (HandlesPaymentCallback) — pay() decides success immediately
|
|
* and dispatches PaymentCaptured before returning.
|
|
*
|
|
* $reference is generated here (not supplied by a gateway, since there is
|
|
* none) purely so PaymentCaptured, and anything downstream keying on it,
|
|
* have something to identify this attempt by.
|
|
*/
|
|
class OfflinePaymentDriver implements Configurable, SupportsPay
|
|
{
|
|
/**
|
|
* Always true — no external dependency to be missing.
|
|
*/
|
|
public function isConfigured(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function pay(string $type, Price $amount, array $data = [], array $context = []): PaymentResult
|
|
{
|
|
$reference = 'offline-'.Str::uuid();
|
|
|
|
$result = new PaymentResult(
|
|
status: PaymentResultStatus::Succeeded,
|
|
reference: $reference,
|
|
amount: $amount,
|
|
);
|
|
|
|
PaymentCaptured::dispatch($type, $result, $context);
|
|
|
|
return $result;
|
|
}
|
|
} |