PHP code example of pralhadstha / nepalcan-laravel
1. Go to this page and download the library: Download pralhadstha/nepalcan-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// By order ID
$statuses = NepalCan::tracking()->getStatusHistory(12345);
// By tracking ID
$detail = NepalCan::tracking()->track('NCM-123456');
echo $detail->lastDeliveryStatus;
// Bulk status check
$bulk = NepalCan::tracking()->getBulkStatuses([12345, 67890]);
use OmniCargo\NepalCan\Services\RateService;
$rate = NepalCan::rates()->calculate('Kathmandu', 'Pokhara');
echo $rate->charge;
// Specify delivery type
$rate = NepalCan::rates()->calculate(
'Kathmandu',
'Pokhara',
RateService::TYPE_D2B, // Door to Branch
);
use OmniCargo\NepalCan\Services\TicketService;
// Create a ticket
$ticket = NepalCan::tickets()->create(
TicketService::TYPE_GENERAL,
'Need help with order #12345',
);
// Request COD transfer
$ticket = NepalCan::tickets()->createCodTransfer(
bankName: 'Nepal Bank',
accountName: 'Ram Shrestha',
accountNumber: '1234567890',
);
// Close a ticket
NepalCan::tickets()->close($ticket->ticketId);
use OmniCargo\NepalCan\Laravel\Events\DeliveryCompleted;
use OmniCargo\NepalCan\Laravel\Events\NepalCanWebhookReceived;
// Listen for a specific event
Event::listen(DeliveryCompleted::class, function (DeliveryCompleted $event) {
$orderId = $event->webhook->orderId;
// Update your order status, notify customer, etc.
});
// Listen for ALL webhook events
Event::listen(NepalCanWebhookReceived::class, function (NepalCanWebhookReceived $event) {
Log::info("NCM webhook: {$event->webhook->event}", [
'order_id' => $event->webhook->orderId,
'status' => $event->webhook->status,
]);
});