feat(sale): implement confirm and cancel functionality for sales in AdminApp; update routes and tests
This commit is contained in:
@@ -18,12 +18,17 @@ class ReleaseCheckoutService
|
||||
|
||||
public function cancel(Purchase $purchase): Purchase
|
||||
{
|
||||
return $this->release($purchase, Purchase::STATUS_CANCELLED);
|
||||
return $this->release($purchase, Purchase::STATUS_CANCELLED, restoreCart: true);
|
||||
}
|
||||
|
||||
public function cancelWithoutRestoringCart(Purchase $purchase): Purchase
|
||||
{
|
||||
return $this->release($purchase, Purchase::STATUS_CANCELLED, restoreCart: false);
|
||||
}
|
||||
|
||||
public function expire(Purchase $purchase): Purchase
|
||||
{
|
||||
return $this->release($purchase, Purchase::STATUS_EXPIRED);
|
||||
return $this->release($purchase, Purchase::STATUS_EXPIRED, restoreCart: true);
|
||||
}
|
||||
|
||||
public function expireOverdue(): int
|
||||
@@ -46,9 +51,9 @@ class ReleaseCheckoutService
|
||||
return $expiredCount;
|
||||
}
|
||||
|
||||
private function release(Purchase $purchase, string $targetStatus): Purchase
|
||||
private function release(Purchase $purchase, string $targetStatus, bool $restoreCart): Purchase
|
||||
{
|
||||
return DB::transaction(function () use ($purchase, $targetStatus): Purchase {
|
||||
return DB::transaction(function () use ($purchase, $targetStatus, $restoreCart): Purchase {
|
||||
$purchase = $this->lockPurchase($purchase);
|
||||
|
||||
if ($purchase->status === Purchase::STATUS_PAID) {
|
||||
@@ -76,7 +81,7 @@ class ReleaseCheckoutService
|
||||
->where('reservation_status', PurchaseItem::RESERVATION_ACTIVE)
|
||||
->lockForUpdate()
|
||||
->get();
|
||||
$reservationReturnedToCart = $this->sourceCart->restore($purchase);
|
||||
$reservationReturnedToCart = $restoreCart && $this->sourceCart->restore($purchase);
|
||||
|
||||
foreach ($items as $item) {
|
||||
if (! $reservationReturnedToCart) {
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Domains\Purchase\Services\Checkout\EditCheckoutService;
|
||||
use App\Domains\Purchase\Services\Checkout\ReleaseCheckoutService;
|
||||
use App\Domains\Purchase\Services\Checkout\StartCheckoutService;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Stable checkout API used by controllers, commands and integrations.
|
||||
@@ -64,11 +65,26 @@ class CheckoutService
|
||||
$this->completer->confirm($purchase);
|
||||
}
|
||||
|
||||
public function confirmPaidPurchase(Purchase $purchase): Purchase
|
||||
{
|
||||
return DB::transaction(function () use ($purchase): Purchase {
|
||||
$this->completer->confirm($purchase);
|
||||
$purchase->markAsPaid();
|
||||
|
||||
return $purchase->refresh()->load(['items.imageAttachment']);
|
||||
});
|
||||
}
|
||||
|
||||
public function cancelPurchase(Purchase $purchase): Purchase
|
||||
{
|
||||
return $this->releaser->cancel($purchase);
|
||||
}
|
||||
|
||||
public function cancelPurchaseWithoutRestoringCart(Purchase $purchase): Purchase
|
||||
{
|
||||
return $this->releaser->cancelWithoutRestoringCart($purchase);
|
||||
}
|
||||
|
||||
public function expirePurchase(Purchase $purchase): Purchase
|
||||
{
|
||||
return $this->releaser->expire($purchase);
|
||||
|
||||
Reference in New Issue
Block a user