Feat: Shipping functionalities redesign, elta courier integration, commenting out acs since no integration can happen, flow updates

This commit is contained in:
arvanitakis committed 2026-09-30 17:28:47 +03:00
1 parent f411dec1da
commit 49ec4333af
63 files changed
+3143 -347

No files matched your search

+5 -34
View File
@@ -11,9 +11,8 @@ use Lunar\Shipping\Facades\Shipping;
use Modules\Core\Shipping\Contracts\CarrierFulfillmentInterface;
use Modules\Core\Shipping\Contracts\SupportsTracking;
use Modules\Core\Shipping\Enums\TrackingStatus;
use Modules\Core\Shipping\Events\ShipmentStatusUpdatedByCarrier;
use Modules\Core\Shipping\Models\Shipment;
use Modules\Core\Shipping\Models\ShipmentInfo;
use Modules\Core\Shipping\Services\ShipmentTrackingRecorder;
use Throwable;
/**
@@ -52,6 +51,8 @@ class PollShipmentTrackingJob implements ShouldQueue
Shipment::query()
->whereIn('carrier', $trackableCarriers)
->whereNull('cancelled_at')
// Pending vouchers (issued on print) have no number to track yet.
->whereNotNull('tracking_reference')
->whereDoesntHave('shipmentInfo', function ($query) {
$query->whereIn('status', [
TrackingStatus::Delivered->value,
@@ -68,49 +69,19 @@ class PollShipmentTrackingJob implements ShouldQueue
private function pollCarrierShipments(string $carrier, $shipments): void
{
$service = $this->fulfillmentService($carrier);
if (! $service instanceof SupportsTracking) {
if (! $this->fulfillmentService($carrier) instanceof SupportsTracking) {
return;
}
foreach ($shipments as $shipment) {
try {
$this->recordNewCheckpoints($shipment, $service->trackShipment($shipment));
app(ShipmentTrackingRecorder::class)->refresh($shipment);
} catch (Throwable $e) {
report($e);
}
}
}
private function recordNewCheckpoints(Shipment $shipment, $checkpoints): void
{
$existing = $shipment->shipmentInfo()
->get(['status', 'occurred_at'])
->map(fn ($info) => $info->status->value.'|'.$info->occurred_at->toIso8601String())
->flip();
foreach ($checkpoints as $checkpoint) {
$fingerprint = $checkpoint->status->value.'|'.$checkpoint->occurredAt->toIso8601String();
if ($existing->has($fingerprint)) {
continue;
}
$info = ShipmentInfo::create([
'shipment_id' => $shipment->id,
'status' => $checkpoint->status,
'carrier_status' => $checkpoint->carrierStatus,
'message' => $checkpoint->message,
'location' => $checkpoint->location,
'occurred_at' => $checkpoint->occurredAt,
'meta' => $checkpoint->meta,
]);
ShipmentStatusUpdatedByCarrier::dispatch($info);
}
}
private function fulfillmentService(string $carrier): ?CarrierFulfillmentInterface
{
return app(CarrierFulfillmentInterface::class, ['carrier' => $carrier]);
@@ -0,0 +1,34 @@
<?php
namespace Modules\Core\Shipping\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Modules\Core\Shipping\Services\CarrierVoucherSync;
/**
* Daily pull of every carrier's reported vouchers for the last $days days
* into the Carrier Vouchers screen (CarrierVoucherSync). Also run from
* that screen's "Sync now".
*/
class SyncCarrierVouchersJob implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
public int $tries = 2;
public int $backoff = 300;
public function __construct(public readonly int $days = 14) {}
public function handle(CarrierVoucherSync $sync): void
{
$sync->syncAll(now()->subDays($this->days)->startOfDay(), now());
}
}