定制 laravel-nepal/nepal-can-move 二次开发

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

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

laravel-nepal/nepal-can-move

Composer 安装命令:

composer require laravel-nepal/nepal-can-move

包简介

SDK for integration with the Nepal Can Move API in PHP applications.

README 文档

README

Lint & Test PR

A strictly typed, and expressive PHP SDK for integrating with the Nepal Can Move (NCM) logistics API.

This package provides a fluent wrapper around the NCM API, normalizing API responses into clean Data Transfer Objects (DTOs), leveraging PHP 8.1+ Enums for type safety, and handling all authentication and error states automatically.

Requirements

  • PHP: 8.2+
  • Laravel: 10.x, 11.x, or 12.x

Installation

Install the package via Composer:

composer require laravel-nepal/nepal-can-move

(Optional) Publish the configuration file:

php artisan vendor:publish --tag="nepal-can-move"

Configuration

Add your NCM credentials to your .env file. Enable sandbox mode for testing.

NCM_TOKEN=your_api_token_here
NCM_SANDBOX_MODE=true

You can get your token by registering a vendor account then from the portal dashboard.

Usage

Warning

API Limits

Please be mindful of the NCM API limits to avoid IP throttling:

Order Creation: 1,000 per day.
Order Views (Detail/Status): 20,000 per day.

Fetching Branches

Retrieve all available NCM branches as strictly typed Branch objects.

use LaravelNepal\NCM\Facades\NCM;

$branches = NCM::getBranches();

$tinkune = $branches->firstWhere('name', 'TINKUNE');

echo $tinkune->phone;

Calculating Shipping Rates

Calculate delivery charges using the DeliveryType enum.

use LaravelNepal\NCM\Enums\DeliveryType;

$charge = NCM::getDeliveryCharge(
    source: $tinkune,
    destination: $pokhara,
    deliveryType: DeliveryType::BranchToDoor
);

Creating an Order

Use the CreateOrderRequest DTO to ensure all required fields are present.

use LaravelNepal\NCM\Data\CreateOrderRequest;
use LaravelNepal\NCM\Enums\DeliveryType;

$request = new CreateOrderRequest(
    name: 'Achyut Neupane',
    phone: '9800000000',
    codCharge: '1500',
    address: 'Lakeside, Pokhara',
    sourceBranch: 'KATHMANDU',
    destinationBranch: 'POKHARA',
    package: 'Books',
    deliveryType: DeliveryType::DoorToDoor
);

$order = NCM::createOrder($request);

echo $order->id;

Important

The NCM API uses different naming conventions across its endpoints (e.g., Pickup/Collect vs Door2Door).
This SDK normalizes these into the DeliveryType enum. You should always use the Enum cases; the SDK handles the underlying API string transformations automatically.

Order Management

The Order object exposes rich behavior.

Fetching an Order

$order = NCM::getOrder(12345);

Status History

$history = $order->statusHistory();

foreach ($history as $status) {
    echo $status->status . ' - ' . $status->addedTime->diffForHumans();
}
Latest Order Status
echo $order->status();

Comments

$order->addComment('Customer requested evening delivery.');

$comments = $order->comments();

Return & Exchange

$order->return('Customer refused delivery');

$order->exchange();

Redirecting an Order

use LaravelNepal\NCM\Data\RedirectOrderRequest;

$redirect = new RedirectOrderRequest(
    orderId: $order->id,
    name: 'Not Achyut Neupane',
    phone: '9811111111',
    address: 'New Address, Kathmandu',
    orderIdentifier: 'ORD-REF-002',
    destinationBranchId: 5,
    codCharge: 1600.00
);

NCM::redirectOrder($redirect);

Support Tickets

General Support

use LaravelNepal\NCM\Enums\TicketType;

NCM::createSupportTicket(
    TicketType::OrderProcessing,
    "My order is stuck in Pickup status for 3 days."
);

COD Transfer Request

$ticketId = NCM::createCODTransferTicket(
    bankName: 'Nabil Bank',
    accountHolderName: 'My Company Pvt Ltd',
    accountNumber: '001001001001'
);

Webhooks

The Nepal Can Move SDK allows you to manage your webhook configuration and transform incoming POST data into strictly typed objects.

Configuring Webhooks

You can programmatically set, test, or remove your webhook URL:

// Set the URL where NCM will push updates
$ncm->setWebhookUrl('https://your-app.com/api/ncm/webhook');

// Send a test payload to your URL to verify connectivity
$ncm->testWebhookUrl('https://your-app.com/api/ncm/webhook');

// Disable webhooks
$ncm->removeWebhookUrl();

Handling Webhook Payloads

When NCM sends a status update to your server, use parseWebhook to convert the raw request data into a StatusEvent DTO. This automatically maps technical events to your OrderStatus enums using the toOrderStatus method.

use LaravelNepal\NCM\Exceptions\NCMException;
use LaravelNepal\NCM\Enums\OrderStatus;

try {
    $event = $ncm->parseWebhook($payload);

    echo $event->orderIds; // e.g., [123, 124]
    echo $event->event->getLabel(); // e.g., "Delivered"
    
    // Get the normalized OrderStatus enum
    $status = $event->getOrderStatus(); 
    
    if ($status === OrderStatus::Delivered) {
        // Perform business logic
    }
} catch (NCMException $NCMException) {
    // Handle unknown event types or malformed data
}

Tip

Since NCM webhooks do not currently include a cryptographic signature, it is recommended to add a unique query parameter to your webhook URL (e.g., ?secret=your-random-key) and verify it in your controller to ensure the request is legitimate.

Exception Handling

use LaravelNepal\NCM\Exceptions\NCMException;

try {
    NCM::createOrder($request);
} catch (NCMException $e) {
    return back()->withErrors($e->getMessage());
}

Contributing

Contributions are welcome! Please create a pull request or open an issue if you find any bugs or have feature requests.

License

This package is open-sourced software licensed under the MIT license.

Support

If you find this package useful, please consider starring the repository on GitHub to show your support.

laravel-nepal/nepal-can-move 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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