2026-09-01 14:04:12 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Modules\Core\Providers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Event;
|
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
use Lunar\Models\Order;
|
|
|
|
|
use Lunar\Models\Transaction;
|
2026-09-10 01:34:30 +03:00
|
|
|
use Modules\Core\Checkout\Events\OrderPlaced;
|
2026-09-01 14:04:12 +03:00
|
|
|
use Modules\Core\Notification\NotificationRegistry;
|
2026-09-10 22:50:40 +03:00
|
|
|
use Modules\Core\Order\Events\OrderDelivered;
|
2026-09-03 17:27:34 +03:00
|
|
|
use Modules\Core\Order\Listeners\ApplyResolvedPaymentStatus;
|
2026-09-10 22:50:40 +03:00
|
|
|
use Modules\Core\Order\Listeners\CompleteOrderOnDelivered;
|
2026-09-10 01:34:30 +03:00
|
|
|
use Modules\Core\Order\Listeners\DecrementStockOnOrderPlaced;
|
2026-09-01 14:04:12 +03:00
|
|
|
use Modules\Core\Order\Listeners\DeriveOrderDeliveredFromShipment;
|
2026-09-03 18:26:48 +03:00
|
|
|
use Modules\Core\Order\Listeners\RecordPaymentTransaction;
|
2026-09-01 14:04:12 +03:00
|
|
|
use Modules\Core\Order\Notifications\OrderCapturedNotification;
|
|
|
|
|
use Modules\Core\Order\Notifications\OrderDeliveredNotification;
|
2026-09-10 01:34:30 +03:00
|
|
|
use Modules\Core\Order\Notifications\OrderPlacedNotification;
|
2026-09-01 14:04:12 +03:00
|
|
|
use Modules\Core\Order\Notifications\OrderRefundedNotification;
|
|
|
|
|
use Modules\Core\Order\Notifications\OrderStatusUpdatedNotification;
|
|
|
|
|
use Modules\Core\Order\Observers\OrderObserver;
|
|
|
|
|
use Modules\Core\Order\Observers\TransactionObserver;
|
|
|
|
|
use Modules\Core\Order\Support\OrderStatus;
|
2026-09-03 17:27:34 +03:00
|
|
|
use Modules\Core\Payment\Events\PaymentAuthorized;
|
|
|
|
|
use Modules\Core\Payment\Events\PaymentCaptured;
|
2026-09-03 18:26:48 +03:00
|
|
|
use Modules\Core\Payment\Events\PaymentRefunded;
|
|
|
|
|
use Modules\Core\Payment\Events\PaymentVoided;
|
2026-09-01 14:04:12 +03:00
|
|
|
use Modules\Core\Shipping\Events\ShipmentStatusUpdatedByCarrier;
|
|
|
|
|
|
|
|
|
|
class OrderServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
|
|
|
|
public function boot(): void
|
|
|
|
|
{
|
|
|
|
|
Order::observe(OrderObserver::class);
|
|
|
|
|
Transaction::observe(TransactionObserver::class);
|
|
|
|
|
|
|
|
|
|
Order::macro('paymentStatus', fn () => OrderStatus::payment($this));
|
|
|
|
|
Order::macro('fulfillmentStatus', fn () => OrderStatus::fulfillment($this));
|
|
|
|
|
|
|
|
|
|
Event::listen(ShipmentStatusUpdatedByCarrier::class, DeriveOrderDeliveredFromShipment::class);
|
2026-09-10 22:50:40 +03:00
|
|
|
Event::listen(OrderDelivered::class, CompleteOrderOnDelivered::class);
|
2026-09-03 17:27:34 +03:00
|
|
|
Event::listen(PaymentCaptured::class, ApplyResolvedPaymentStatus::class);
|
|
|
|
|
Event::listen(PaymentAuthorized::class, ApplyResolvedPaymentStatus::class);
|
2026-09-09 00:48:09 +03:00
|
|
|
Event::listen(PaymentRefunded::class, ApplyResolvedPaymentStatus::class);
|
2026-09-03 18:26:48 +03:00
|
|
|
Event::listen(PaymentCaptured::class, RecordPaymentTransaction::class);
|
|
|
|
|
Event::listen(PaymentAuthorized::class, RecordPaymentTransaction::class);
|
|
|
|
|
Event::listen(PaymentVoided::class, RecordPaymentTransaction::class);
|
|
|
|
|
Event::listen(PaymentRefunded::class, RecordPaymentTransaction::class);
|
2026-09-10 01:34:30 +03:00
|
|
|
Event::listen(OrderPlaced::class, DecrementStockOnOrderPlaced::class);
|
2026-09-01 14:04:12 +03:00
|
|
|
|
|
|
|
|
NotificationRegistry::get()->register([
|
|
|
|
|
OrderDeliveredNotification::class,
|
|
|
|
|
OrderStatusUpdatedNotification::class,
|
|
|
|
|
OrderRefundedNotification::class,
|
|
|
|
|
OrderCapturedNotification::class,
|
2026-09-10 01:34:30 +03:00
|
|
|
OrderPlacedNotification::class,
|
2026-09-01 14:04:12 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// Lets the consuming app override copy/markup without forking core
|
|
|
|
|
// — published into resources/views/vendor/core/order/notifications,
|
|
|
|
|
// which loadViewsFrom() (CoreServiceProvider) already resolves
|
|
|
|
|
// ahead of the package's own views for the `core::` namespace.
|
|
|
|
|
$this->publishes([
|
|
|
|
|
__DIR__ . '/../../resources/views/order/notifications' => resource_path('views/vendor/core/order/notifications'),
|
|
|
|
|
], 'core-views');
|
|
|
|
|
}
|
|
|
|
|
}
|