Introduces a complete shipment review system allowing staff to request changes to customer orders and customers to resubmit corrected orders. - Add `ReviewState` enum and `ShipmentReview` model to track review history. - Implement `ShipmentReviewService` to handle approval and change request logic. - Add `resubmit` endpoint for customers to update orders when `changes_requested` state is active. - Add `request-changes` endpoint for staff to flag orders for correction. - Update `ShipmentResource` in Filament to display review states and manage approvals. - Implement WordPress bridge support for fetching and resubmitting orders via AJAX. - Add database migrations for `shipment_reviews` table and `review_state` column on shipments. - Add `StaffApiMiddleware` to secure staff-specific API routes.
166 lines
9.5 KiB
PHP
166 lines
9.5 KiB
PHP
<?php
|
||
|
||
use App\Http\Controllers\Api\CustomerFinancialController;
|
||
use App\Http\Controllers\Api\CommitmentFormController;
|
||
use App\Http\Controllers\Api\MobileVerificationController;
|
||
use App\Http\Controllers\Api\Customer\CustomerOrderController;
|
||
use App\Http\Controllers\Api\DiscountCodeController;
|
||
use App\Http\Controllers\Api\MockGatewayController;
|
||
use App\Http\Controllers\Api\PaymentController;
|
||
use App\Http\Controllers\Api\PricingController;
|
||
use App\Http\Controllers\Api\StaffOrderController;
|
||
use App\Http\Controllers\Api\TrackController;
|
||
use App\Http\Controllers\Api\WalletController;
|
||
use App\Http\Middleware\ApiKeyMiddleware;
|
||
use Illuminate\Support\Facades\Route;
|
||
use App\Http\Controllers\Api\AuthController;
|
||
use App\Http\Controllers\Api\BridgeAuthController;
|
||
|
||
|
||
// ══════════════════════════════════════════════════════════════
|
||
// Bridge Auth API (فقط برای پلاگین وردپرس - با API Key محافظت میشود)
|
||
// ══════════════════════════════════════════════════════════════
|
||
Route::post('/v1/bridge/login', [BridgeAuthController::class, 'login']); // Login
|
||
|
||
// ══════════════════════════════════════════════════════════════
|
||
// API عمومی با API Key
|
||
// ══════════════════════════════════════════════════════════════
|
||
Route::middleware([ApiKeyMiddleware::class])->prefix('v1')->group(function () {
|
||
Route::get('/track/{awb_no}', [TrackController::class, 'show']);
|
||
});
|
||
|
||
// ══════════════════════════════════════════════════════════════
|
||
// API عمومی (بدون نیاز به احراز هویت)
|
||
// ══════════════════════════════════════════════════════════════
|
||
Route::prefix('v1')->group(function () {
|
||
Route::get('/countries', [CustomerOrderController::class, 'countries']);
|
||
});
|
||
|
||
// ══════════════════════════════════════════════════════════════
|
||
// Auth API (عمومی - برای دریافت توکن)
|
||
// ══════════════════════════════════════════════════════════════
|
||
Route::post('/v1/auth/login', [AuthController::class, 'login']);
|
||
|
||
Route::middleware(['auth:sanctum'])->post('/v1/auth/logout', [AuthController::class, 'logout']);
|
||
|
||
// ══════════════════════════════════════════════════════════════
|
||
// API برای کاربران لاگینشده (با Sanctum / Bearer Token)
|
||
// ══════════════════════════════════════════════════════════════
|
||
Route::middleware(['auth:sanctum'])->prefix('v1')->group(function () {
|
||
|
||
// ─── Wallet API (کاربر عادی) ───
|
||
Route::get('/wallet/balance', [WalletController::class, 'balance']);
|
||
Route::get('/wallet/transactions', [WalletController::class, 'transactions']);
|
||
|
||
// ─── Payment API ───
|
||
Route::post('/payment/redirect', [PaymentController::class, 'redirectToGateway']);
|
||
Route::get('/payment/check/{transaction}', [PaymentController::class, 'checkStatus']);
|
||
|
||
// ─── Admin Wallet API ───
|
||
Route::post('/wallet/admin-adjust', [WalletController::class, 'adminAdjust']);
|
||
Route::post('/wallet/{wallet}/freeze', [WalletController::class, 'freeze']);
|
||
Route::post('/wallet/{wallet}/unfreeze', [WalletController::class, 'unfreeze']);
|
||
Route::get('/wallet/{wallet}/activity-log', [WalletController::class, 'activityLog']);
|
||
|
||
// ─── Customer Orders API (جدید) ───
|
||
Route::prefix('customer')->group(function () {
|
||
// پروفایل و آمار
|
||
Route::get('/profile', [CustomerOrderController::class, 'profile']);
|
||
|
||
// لیست کشورها (عمومی - بدون نیاز به احراز هویت)
|
||
// این endpoint در گروه auth:sanctum نیست
|
||
|
||
// سفارشات
|
||
Route::get('/orders', [CustomerOrderController::class, 'index']);
|
||
Route::post('/orders', [CustomerOrderController::class, 'store']);
|
||
Route::get('/orders/{shipment}', [CustomerOrderController::class, 'show']);
|
||
Route::post('/orders/{shipment}/cancel', [CustomerOrderController::class, 'cancel']);
|
||
Route::post('/orders/{shipment}/resubmit', [CustomerOrderController::class, 'resubmit']);
|
||
|
||
// دانلود PDFهای سفارش
|
||
Route::get('/orders/{shipment}/pdf/awb', [ShipmentPdfController::class, 'awb']);
|
||
Route::get('/orders/{shipment}/pdf/invoice', [ShipmentPdfController::class, 'invoice']);
|
||
Route::get('/orders/{shipment}/pdf/label', [ShipmentPdfController::class, 'label']);
|
||
Route::get('/orders/{shipment}/pdf/import-invoice', [ShipmentPdfController::class, 'importInvoice']);
|
||
|
||
// تعهدنامهها
|
||
Route::get('/orders/{shipment}/commitment-forms', [CommitmentFormController::class, 'shipmentForms']);
|
||
Route::post('/orders/{shipment}/commitment-forms/{form}/upload', [CommitmentFormController::class, 'uploadSigned']);
|
||
|
||
// نوتیفیکیشنها
|
||
Route::get('/notifications', [CustomerOrderController::class, 'notifications']);
|
||
Route::post('/notifications/{notification}/read', [CustomerOrderController::class, 'markNotificationRead']);
|
||
|
||
// پرداخت سفارش
|
||
Route::post('/orders/{shipment}/pay-wallet', [CustomerOrderController::class, 'payFromWallet']);
|
||
Route::post('/orders/{shipment}/pay-gateway', [CustomerOrderController::class, 'payViaGateway']);
|
||
});
|
||
|
||
// ─── Staff Orders API (تأیید سفارشات) ───
|
||
Route::middleware([\App\Http\Middleware\StaffApiMiddleware::class])
|
||
->prefix('staff')
|
||
->group(function () {
|
||
|
||
Route::get(
|
||
'/orders/pending-approval',
|
||
[StaffOrderController::class, 'pendingApproval']
|
||
);
|
||
|
||
Route::post(
|
||
'/orders/{shipment}/request-changes',
|
||
[StaffOrderController::class, 'requestChanges']
|
||
);
|
||
|
||
Route::post(
|
||
'/orders/{shipment}/approve',
|
||
[StaffOrderController::class, 'approve']
|
||
);
|
||
|
||
Route::post(
|
||
'/orders/{shipment}/reject',
|
||
[StaffOrderController::class, 'reject']
|
||
);
|
||
|
||
// ─── Customer Financial API ───
|
||
Route::get(
|
||
'/customers/search',
|
||
[CustomerFinancialController::class, 'search']
|
||
);
|
||
|
||
Route::get(
|
||
'/customers/{customer}/financial-status',
|
||
[CustomerFinancialController::class, 'financialStatus']
|
||
);
|
||
});
|
||
});
|
||
|
||
// ══════════════════════════════════════════════════════════════
|
||
// Mock Gateway Routes (عمومی - برای شبیهسازی درگاه)
|
||
// ══════════════════════════════════════════════════════════════
|
||
Route::prefix('v1/payment')->group(function () {
|
||
Route::get('/mock-gateway', [MockGatewayController::class, 'showGateway']);
|
||
Route::get('/mock-gateway/success', [MockGatewayController::class, 'simulateSuccess']);
|
||
Route::get('/mock-gateway/failure', [MockGatewayController::class, 'simulateFailure']);
|
||
});
|
||
|
||
// Callback از درگاه (بدون auth)
|
||
Route::any('/v1/payment/callback', [PaymentController::class, 'callback'])
|
||
->name('payment.callback');
|
||
|
||
// ══════════════════════════════════════════════════════════════
|
||
// APIهای عمومی (بدون auth)
|
||
// ══════════════════════════════════════════════════════════════
|
||
Route::post('/v1/calculate', [PricingController::class, 'calculate']);
|
||
Route::get('/v1/discount-codes', [DiscountCodeController::class, 'index']);
|
||
Route::post('/v1/discount-codes/validate', [DiscountCodeController::class, 'validate']);
|
||
|
||
// API فایلهای تعهدنامه (عمومی)
|
||
Route::get('/v1/commitment-forms', [CommitmentFormController::class, 'index']);
|
||
Route::get('/v1/commitment-forms/{direction}', [CommitmentFormController::class, 'byDirection']);
|
||
|
||
// API تأیید موبایل (عمومی)
|
||
Route::post('/v1/verify/send-code', [MobileVerificationController::class, 'sendCode']);
|
||
Route::post('/v1/verify/check-code', [MobileVerificationController::class, 'checkCode']);
|
||
|
||
// API ارسال پیامک (نیاز به auth دارد)
|
||
Route::middleware(['auth:sanctum'])->post('/v1/verify/send-sms', [MobileVerificationController::class, 'sendSms']); |