Feat: Creating PaymentMethods, Setting Fees, Availabilities
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Cash-on-delivery has no gateway to confirm against — the shopper pays the
|
||||
* courier on delivery, not at checkout — so confirm() has nothing to wait
|
||||
* on and 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.cash-on-delivery.authorized')
|
||||
* afterward — placeOrder() itself leaves the order at Lunar's configured
|
||||
* draft_status, same as every driver is responsible for moving it on from.
|
||||
*/
|
||||
class CashOnDeliveryPaymentDriver implements PaymentDriver
|
||||
{
|
||||
public function __construct(
|
||||
private readonly CheckoutService $checkout,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws FingerprintMismatchException
|
||||
* @throws CartException
|
||||
* @throws DisallowMultipleCartOrdersException
|
||||
*/
|
||||
public function confirm(Cart $cart, string $fingerprint, array $data): Order
|
||||
{
|
||||
$order = $this->checkout->placeOrder($fingerprint);
|
||||
|
||||
$order->update([
|
||||
'status' => config('lunar.payments.types.cash-on-delivery.authorized', $order->status),
|
||||
]);
|
||||
|
||||
return $order->refresh();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user