定制 pralhadstha/nepalcan-laravel 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pralhadstha/nepalcan-laravel

Composer 安装命令:

composer require pralhadstha/nepalcan-laravel

包简介

Laravel integration for Nepal Can Move (NCM) courier API — shipments, tracking, rates, webhooks, COD, and delivery management for Nepal

README 文档

README

Latest Version on Packagist Tests License PHP Version

Laravel integration for the Nepal Can Move (NCM) courier and shipping API. Manage shipments, track deliveries, calculate rates, handle COD payments, and process webhooks — all with idiomatic Laravel patterns.

Built on top of Nepal Can PHP SDK.

Features

  • Service Provider with auto-discovery — zero configuration to get started
  • Facade (NepalCan) for clean, expressive syntax
  • Dependency Injection — type-hint OmniCargo\NepalCan\Client in any class
  • Publishable Config — environment-based API token and base URL management
  • Webhook Integration — automatic route registration with Laravel event dispatching
  • Webhook Middleware — user-agent validation out of the box
  • Laravel Events — listen for delivery status changes with native event listeners

Requirements

Dependency Version
PHP ^8.1
Laravel 10.x, 11.x, or 12.x

Installation

composer require pralhadstha/nepalcan-laravel

The service provider and facade are auto-discovered. No manual registration needed.

Publish Configuration

php artisan vendor:publish --tag=nepalcan-config

This creates config/nepalcan.php in your application.

Configuration

Add these variables to your .env file:

NEPALCAN_API_TOKEN=your-api-token-here
NEPALCAN_ENVIRONMENT=sandbox

Environment Variables

Variable Description Default
NEPALCAN_API_TOKEN Your NCM API token from the dashboard ""
NEPALCAN_ENVIRONMENT sandbox or production sandbox
NEPALCAN_BASE_URL Override the API base URL entirely null
NEPALCAN_WEBHOOK_VALIDATE_UA Validate webhook User-Agent header true
NEPALCAN_WEBHOOK_PATH Webhook endpoint path /nepalcan/webhook

Set NEPALCAN_ENVIRONMENT=production when you're ready to go live. This switches the base URL from demo.nepalcanmove.com to nepalcanmove.com.

Usage

Using the Facade

use OmniCargo\NepalCan\Laravel\Facades\NepalCan;

Create a Shipment

$order = NepalCan::shipments()->create([
    'receiver_name' => 'Ram Shrestha',
    'receiver_phone' => '9801234567',
    'receiver_address' => 'Kathmandu',
    'product_name' => 'Electronics',
    'cod_charge' => '1500',
    'quantity' => 1,
]);

echo $order->orderId;

Track an Order

// 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]);

Calculate Shipping Rates

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
);

Available delivery types: TYPE_PICKUP_COLLECT (Door2Door), TYPE_SEND (Branch2Door), TYPE_D2B (Door2Branch), TYPE_B2B (Branch2Branch).

List Branches

$branches = NepalCan::branches()->list();

foreach ($branches as $branch) {
    echo "{$branch->name} - {$branch->district}";
}

Support Tickets

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);

Staff Management

$result = NepalCan::staff()->list(search: 'ram', page: 1, pageSize: 10);

foreach ($result['results'] as $staff) {
    echo "{$staff->name} - {$staff->email}";
}

Using Dependency Injection

You can type-hint the SDK client directly in your controllers, jobs, or any service:

use OmniCargo\NepalCan\Client;

class ShippingController extends Controller
{
    public function __construct(private readonly Client $client)
    {
    }

    public function show(int $orderId)
    {
        $order = $this->client->shipments->find($orderId);
        $history = $this->client->tracking->getStatusHistory($orderId);

        return view('shipping.show', compact('order', 'history'));
    }
}

Webhook Handling

Automatic Route Registration

By default, the package registers a POST route at /nepalcan/webhook. Incoming webhook payloads are parsed and dispatched as Laravel events.

Make sure to exclude this path from CSRF verification. In Laravel 10:

// app/Http/Middleware/VerifyCsrfToken.php
protected $except = [
    'nepalcan/webhook',
];

In Laravel 11+:

// bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
    $middleware->validateCsrfTokens(except: [
        'nepalcan/webhook',
    ]);
})

To disable the automatic route, set NEPALCAN_WEBHOOK_PATH to an empty value or set webhook.path to null in the config.

User-Agent Validation

The package validates that incoming webhook requests have a User-Agent header starting with NCM-Webhook/. This prevents unauthorized requests from reaching your event listeners. Disable this with:

NEPALCAN_WEBHOOK_VALIDATE_UA=false

Listening for Events

Register listeners in your EventServiceProvider or use Event::listen():

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,
    ]);
});

Available Events

Every webhook dispatches the generic NepalCanWebhookReceived event. Additionally, a specific event is dispatched based on the webhook type:

Webhook Event Laravel Event Class
pickup_completed OmniCargo\NepalCan\Laravel\Events\PickupCompleted
sent_for_delivery OmniCargo\NepalCan\Laravel\Events\SentForDelivery
order_dispatched OmniCargo\NepalCan\Laravel\Events\OrderDispatched
order_arrived OmniCargo\NepalCan\Laravel\Events\OrderArrived
delivery_completed OmniCargo\NepalCan\Laravel\Events\DeliveryCompleted

All event classes carry a public readonly Webhook $webhook property with the parsed payload data.

Testing

composer test

Or run individual suites:

vendor/bin/phpunit --testsuite=Unit
vendor/bin/phpunit --testsuite=Feature

Credits

License

The MIT License (MIT). See LICENSE for details.

pralhadstha/nepalcan-laravel 适用场景与选型建议

pralhadstha/nepalcan-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「ecommerce」 「service-provider」 「laravel」 「facade」 「shipping」 「delivery」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 pralhadstha/nepalcan-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 pralhadstha/nepalcan-laravel 我们能提供哪些服务?
定制开发 / 二次开发

基于 pralhadstha/nepalcan-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 38
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-01