feat: Complete Shiplogic integration with mobile-optimized ops workflow
**Shiplogic API Integration:**
- Fixed API base URL configuration (removed /api suffix)
- Implemented comprehensive request/response logging for rates and shipments endpoints
- Fixed PDF fetching: API returns S3 URLs, now downloads actual PDFs from S3
- Added tests and mock API responses for local development (routes/shiplogic-mock.php)
**Courier Service Enhancements:**
- Added redownloadShipmentPdfs() public method for re-downloading corrupted PDFs
- Enhanced error logging with full request/response bodies for debugging
- Proper binary PDF storage using Laravel Storage facade
- URL and S3 download handling for Shiplogic API responses
**Workflow & Operations:**
- Changed to manual "Ready for Collection" button instead of automatic move
- Operators now: scan QR → apply labels → click "Ready for Collection" → moves to Awaiting Collection
- Removed duplicate PDF attachments to Trello (was adding twice from two listeners)
- Fixed NotifySlackOnShipmentCreated to only handle Slack notifications
**Mobile-Optimized Ops Page:**
- Removed QR code display from order detail page
- Implemented responsive single-column layout for mobile phones
- Large touch-friendly buttons (full width, increased padding)
- Bold typography for better readability on small screens
- Larger input fields and tracking number displays
- Clear step-by-step instructions for warehouse operators
- Re-download PDF button for damaged/corrupted labels
**New Features:**
- POST /ops/orders/{uuid}/ready-for-collection endpoint
- Re-download PDFs functionality accessible from awaiting_collection and in_transit states
- Full audit logging for all operations via ops interface
- Proper error handling and user feedback
**Testing:**
- Added ShipmentCreationTest with mock HTTP client
- Created comprehensive testing guide (SHIPLOGIC_TESTING.md)
- Mock API routes for local development without hitting live API
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Order;
|
||||
use App\Testing\ShiplogicMockClient;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ShipmentCreationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Test that shipment can be created with mocked Shiplogic API
|
||||
*/
|
||||
public function test_shipment_creation_with_mock_api(): void
|
||||
{
|
||||
// Setup mock HTTP responses
|
||||
ShiplogicMockClient::setup();
|
||||
|
||||
// Create a test order with required fields
|
||||
$order = Order::factory()->create([
|
||||
'order_number' => 'TEST-001',
|
||||
'customer_name' => 'John Doe',
|
||||
'customer_email' => 'john@example.com',
|
||||
'customer_phone' => '+1234567890',
|
||||
'delivery_street' => '123 Main Street',
|
||||
'delivery_unit' => 'Apt 5B',
|
||||
'delivery_city' => 'New York',
|
||||
'delivery_zone' => 'NY',
|
||||
'delivery_code' => '10001',
|
||||
'delivery_country' => 'US',
|
||||
'packing_length' => 30,
|
||||
'packing_width' => 20,
|
||||
'packing_height' => 10,
|
||||
'packing_weight' => 2.5,
|
||||
'status' => 'ready_to_ship',
|
||||
]);
|
||||
|
||||
// Dispatch the ReadyToShipIntent event to trigger shipment creation
|
||||
// This would normally be triggered by user action in Filament
|
||||
event(new \App\Events\ReadyToShipIntent($order));
|
||||
|
||||
// Verify the order now has shipment metadata
|
||||
$order->refresh();
|
||||
$this->assertNotNull($order->courier_shipment_id);
|
||||
$this->assertNotNull($order->courier_service_level_code);
|
||||
$this->assertNotNull($order->courier_rate);
|
||||
|
||||
// Verify PDFs were stored
|
||||
$this->assertTrue(\Illuminate\Support\Facades\Storage::exists(
|
||||
"public/shipments/{$order->uuid}/Shipment Label.pdf"
|
||||
));
|
||||
$this->assertTrue(\Illuminate\Support\Facades\Storage::exists(
|
||||
"public/shipments/{$order->uuid}/Shipment Sticker.pdf"
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that ECO service level is selected when available
|
||||
*/
|
||||
public function test_eco_service_level_selection(): void
|
||||
{
|
||||
ShiplogicMockClient::setup();
|
||||
|
||||
$order = Order::factory()->create([
|
||||
'order_number' => 'TEST-002',
|
||||
'customer_name' => 'Jane Smith',
|
||||
'customer_email' => 'jane@example.com',
|
||||
'delivery_street' => '456 Oak Ave',
|
||||
'delivery_city' => 'London',
|
||||
'delivery_country' => 'GB',
|
||||
'packing_weight' => 1.5,
|
||||
'status' => 'ready_to_ship',
|
||||
]);
|
||||
|
||||
event(new \App\Events\ReadyToShipIntent($order));
|
||||
|
||||
$order->refresh();
|
||||
// ECO variant should be selected (FEDEX_INTERNATIONAL_ECONOMY)
|
||||
$this->assertStringContainsString('ECONOMY', $order->courier_service_level_code);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user