49 lines
1.6 KiB
PHP
49 lines
1.6 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;
|
|
|
|
/**
|
|
* Shared by every payment type with no real gateway to confirm against —
|
|
* cash-in-hand, cash-on-delivery — where the shopper pays at pickup/on
|
|
* delivery, not at checkout. 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;
|
|
}
|
|
} |