pralhadstha/nepal-can-php-sdk
PHP SDK for Nepal Can Move (NCM) shipping API. Create and manage shipments, track orders, calculate delivery rates, list branches, handle COD and returns/exchanges, manage tickets/staff, and process webhooks with typed resources. PHP 8.1+ with Guzzle.
Shipment, Rate, Webhook) align with DDD principles, making it easier to model domain entities (e.g., Order → Shipment).EventDispatcher enables reactive workflows (e.g., auto-updating order statuses in real-time). Pairs well with Laravel’s event system or queues for async processing.pralhadstha/nepalcan-laravel wrapper) with:
| Risk Area | Mitigation Strategy |
|---|---|
| API Deprecation | Monitor NCM’s API changelog; use feature flags to isolate SDK changes. |
| Rate Limits | Implement exponential backoff and caching (e.g., Redis) for rate-heavy ops. |
| Webhook Duplicates | Use idempotency keys (as shown in docs) + Laravel’s queue:failed table. |
| Data Mismatch | Validate SDK responses against internal schemas (e.g., Shipment → Order mapping). |
| Testing Gaps | Extend SDK’s test suite with contract tests (e.g., Pact) for API interactions. |
orderId map to internal order_id? (Use database indexes or caching layers for performance.)cache()->remember()).| Component | Laravel Integration Strategy |
|---|---|
| Client Initialization | Use Laravel’s Service Container to bind Client with config (e.g., config('services.nepalcan.api_token')). |
| Webhooks | Leverage Laravel’s HTTP middleware for validation (e.g., nepalcan.webhook.signature). |
| Events | Dispatch Laravel events (e.g., OrderShipped) from EventDispatcher handlers. |
| Commands | Extend SDK’s Artisan commands (e.g., nepalcan:webhook:validate) for debugging. |
| Queues | Offload webhook processing to Laravel Queues (e.g., ShipmentWebhookJob). |
| Testing | Use Laravel’s Pest/Tests to mock Client and verify event dispatching. |
Phase 1: Core Integration (2-3 weeks)
config/nepalcan.php with API tokens.OrderService./api/nepalcan/webhook) with validation.Phase 2: Workflow Automation (1-2 weeks)
OrderStatusUpdated).Cache::remember()).OrderController.Phase 3: Observability (1 week)
nepalcan.ping command).Laravel Horizon or StatsD.php -v and composer.json).https://your-app.com/api/nepalcan/webhook).pralhadstha/nepal-can-php-sdk for updates (check GitHub releases).composer.json to avoid breaking changes:
"pralhadstha/nepal-can-php-sdk": "^1.0.0"
NEPALCAN_API_TOKEN) or Vault.php artisan config:cache) in production.try {
$client->shipments->create(...);
} catch (ApiException $e) {
Log::error("NCM API Error", [
'order_id' => $orderId,
'error' => $e->getErrorBody(),
'status' => $e->getStatusCode(),
]);
}
$client->webhooks->parse($payload, debug: true);
Laravel Monitor).spatie/fruitful) for NCM API calls.$job->retryAfter(5); // Retry after 5 seconds
$client->tracking->getBulkStatuses([$orderId1, $orderId2]);
| Failure Scenario | Mitigation Strategy |
|---|---|
| NCM API Downtime | Implement retry logic + fallback courier (if applicable). |
| Webhook Delivery Failures | Use exponential backoff + dead-letter queue for failed webhooks. |
| Duplicate Webhooks | Enforce idempotency (as shown in docs) + database constraints. |
| Rate Limit Exceeded | Cache responses + queue delays for bulk operations. |
| Data Corruption | Validate SDK responses against **internal schemas |
How can I help you explore Laravel packages today?