2026-08-31 14:12:21 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Modules\Core\Payment\Drivers;
|
|
|
|
|
|
|
|
|
|
use Lunar\Models\Cart;
|
2026-09-02 16:14:52 +03:00
|
|
|
use Modules\Core\Checkout\Events\OrderPlaced;
|
|
|
|
|
use Modules\Core\Checkout\Events\PaymentConfirmed;
|
|
|
|
|
use Modules\Core\Payment\Contracts\PaymentDriver;
|
2026-08-31 14:12:21 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
2026-09-02 16:14:52 +03:00
|
|
|
* delivery, not at checkout. confirm() has nothing to wait on, so it
|
|
|
|
|
* dispatches PaymentConfirmed immediately, same moment Lunar's own
|
|
|
|
|
* OfflinePayment would place the order — but the actual placement now
|
|
|
|
|
* happens in CheckoutService::onPaymentConfirmed(), not here. $data is
|
|
|
|
|
* unused: nothing about this confirmation depends on gateway-specific
|
|
|
|
|
* payload.
|
2026-08-31 14:12:21 +03:00
|
|
|
*
|
2026-09-02 16:14:52 +03:00
|
|
|
* The status-mapping step this driver used to do inline right after
|
|
|
|
|
* placeOrder() returned now happens in onOrderPlaced() below instead —
|
|
|
|
|
* see PaymentDriver's docblock for why a driver can no longer rely on
|
|
|
|
|
* placeOrder()'s return value.
|
2026-08-31 14:12:21 +03:00
|
|
|
*/
|
|
|
|
|
class OfflinePaymentDriver implements PaymentDriver
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Always true — no external dependency to be missing.
|
|
|
|
|
*/
|
|
|
|
|
public function isConfigured(): bool
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-02 16:14:52 +03:00
|
|
|
public function confirm(Cart $cart, string $type, string $fingerprint, array $data): void
|
|
|
|
|
{
|
|
|
|
|
PaymentConfirmed::dispatch($cart, $type, $fingerprint, $data);
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-31 14:12:21 +03:00
|
|
|
/**
|
2026-09-02 16:14:52 +03:00
|
|
|
* Registered in PaymentServiceProvider. Every offline-style type
|
|
|
|
|
* shares this one driver, so $order->meta['payment_method'] is checked
|
|
|
|
|
* against config('lunar.payments.types') to confirm the placed order
|
|
|
|
|
* actually belongs to one of them, rather than assuming every
|
|
|
|
|
* OrderPlaced is this driver's to act on — a Stripe order placed via
|
|
|
|
|
* StripePaymentDriver fires the same event.
|
2026-08-31 14:12:21 +03:00
|
|
|
*/
|
2026-09-02 16:14:52 +03:00
|
|
|
public function onOrderPlaced(OrderPlaced $event): void
|
2026-08-31 14:12:21 +03:00
|
|
|
{
|
2026-09-02 16:14:52 +03:00
|
|
|
$order = $event->order;
|
|
|
|
|
$type = $order->meta['payment_method'] ?? null;
|
|
|
|
|
|
|
|
|
|
if (! $type || config("lunar.payments.types.{$type}.payment_driver") !== self::class) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-08-31 14:12:21 +03:00
|
|
|
|
|
|
|
|
$order->update([
|
|
|
|
|
'status' => config("lunar.payments.types.{$type}.authorized", $order->status),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|