58 lines
1.9 KiB
PHP
58 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Modules\Core\Payment\Drivers;
|
|
|
|
use Lunar\Exceptions\Carts\CartException;
|
|
use Lunar\Exceptions\DisallowMultipleCartOrdersException;
|
|
use Lunar\Exceptions\FingerprintMismatchException;
|
|
use Lunar\Models\Cart;
|
|
use Lunar\Models\Order;
|
|
use Modules\Core\Checkout\Contracts\PaymentDriver;
|
|
use Modules\Core\Checkout\Services\CheckoutService;
|
|
|
|
/**
|
|
* 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. confirm() has nothing to wait on, so it places
|
|
* the order immediately, same as Lunar's own OfflinePayment would, but
|
|
* through CheckoutService::placeOrder() so it goes through the same
|
|
* fingerprint check every other driver does. $data is unused: nothing about
|
|
* this confirmation depends on gateway-specific payload.
|
|
*
|
|
* Sets the order status to config("lunar.payments.types.{$type}.authorized")
|
|
* afterward, using the type actually confirmed — not a hardcoded key —
|
|
* since this one driver is shared across multiple types.
|
|
* placeOrder() itself leaves the order at Lunar's configured draft_status,
|
|
* same as every driver is responsible for moving it on from.
|
|
*/
|
|
class OfflinePaymentDriver implements PaymentDriver
|
|
{
|
|
public function __construct(
|
|
private readonly CheckoutService $checkout,
|
|
) {}
|
|
|
|
/**
|
|
* Always true — no external dependency to be missing.
|
|
*/
|
|
public function isConfigured(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @throws FingerprintMismatchException
|
|
* @throws CartException
|
|
* @throws DisallowMultipleCartOrdersException
|
|
*/
|
|
public function confirm(Cart $cart, string $type, string $fingerprint, array $data): Order
|
|
{
|
|
$order = $this->checkout->placeOrder($fingerprint);
|
|
|
|
$order->update([
|
|
'status' => config("lunar.payments.types.{$type}.authorized", $order->status),
|
|
]);
|
|
|
|
return $order->refresh();
|
|
}
|
|
}
|