定制 devrkb21/pathao-laravel 二次开发

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

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

devrkb21/pathao-laravel

最新稳定版本:v1.0

Composer 安装命令:

composer require devrkb21/pathao-laravel

包简介

A complete Laravel package for Pathao Courier API integration with built-in validation, webhook handling, location caching, and Artisan commands.

README 文档

README

Latest Version on Packagist Total Downloads License

A complete Laravel package for Pathao Courier Merchant API integration. Setup once and forget about it — built-in validation, webhook handling, location caching, API logging, and powerful Artisan commands.

✨ Features

  • ✅ Client Credentials authentication with automatic token refresh
  • ✅ Sandbox & Production environment support
  • ✅ Cities, Zones, Areas — with bulk endpoints & local database caching
  • ✅ Store management (List & Create)
  • ✅ Order management (Create, View, Bulk Create, Price Calculation)
  • ✅ Merchant profile info retrieval
  • ✅ User success rate by phone number
  • ✅ Webhook signature validation with Laravel event dispatching
  • ✅ API request & webhook logging to database
  • ✅ Built-in request validation for all POST endpoints
  • ✅ Artisan commands for setup, sync, status, and diagnostics

⚙️ Installation

composer require devrkb21/pathao-laravel

Publish the config file:

php artisan vendor:publish --tag="pathao-config"

Laravel auto-discovers the service provider. If needed, manually register:

// config/app.php — providers array
devrkb21\PathaoLaravel\PathaoLaravelServiceProvider::class,

// config/app.php — aliases array
'PathaoLaravel' => devrkb21\PathaoLaravel\Facades\PathaoLaravel::class,

Environment Variables

Add the following to your .env file:

PATHAO_CLIENT_ID=
PATHAO_CLIENT_SECRET=
PATHAO_SECRET_TOKEN=
PATHAO_SANDBOX=false
PATHAO_DB_TABLE_NAME=pathao-courier

Where to find credentials? Go to Pathao Developers API → Merchant API Credentials.

Setup

Run the migration:

php artisan migrate

Set up authentication (one-time process):

php artisan pathao:setup

You will be provided a secret_token. Set it in your .env as PATHAO_SECRET_TOKEN.

🏗 Usage

use devrkb21\PathaoLaravel\Facades\PathaoLaravel;

Location APIs

// Get all cities
PathaoLaravel::GET_CITIES();

// Get zones for a city
PathaoLaravel::GET_ZONES(int $city_id);

// Get areas for a zone
PathaoLaravel::GET_AREAS(int $zone_id);

// Bulk fetch all zones / areas
PathaoLaravel::GET_ZONES_BULK();
PathaoLaravel::GET_AREAS_BULK();

Store APIs

// List stores (with optional pagination)
PathaoLaravel::GET_STORES(int $page = 1);

// Create a new store
// Required: name, contact_name, contact_number, address, city_id, zone_id, area_id
PathaoLaravel::CREATE_STORE($request);

Order APIs

// Create an order
// Required: store_id, recipient_name, recipient_phone, recipient_address,
//           delivery_type (48=Normal, 12=On-Demand), item_type (1=Document, 2=Parcel),
//           item_quantity, item_weight, amount_to_collect
PathaoLaravel::CREATE_ORDER($request);

// Create multiple orders in bulk
PathaoLaravel::CREATE_ORDERS_BULK(array $orders);

// View order details
PathaoLaravel::VIEW_ORDER(string $consignment_id);

// Calculate delivery price
PathaoLaravel::GET_PRICE_CALCULATION($request);

Merchant & User APIs

// Get merchant profile info
PathaoLaravel::GET_MERCHANT_INFO();

// Get user success rate by phone
PathaoLaravel::GET_USER_SUCCESS_RATE($request);

// Check token expiry
PathaoLaravel::GET_ACCESS_TOKEN_EXPIRY_DAYS_LEFT();

🔧 Artisan Commands

Command Description
pathao:setup Set up authentication credentials and generate secret token
pathao:merchant-info Verify API connection and display merchant profile info
pathao:sync-locations Fetch and cache all cities, zones, and areas into local database
pathao:status Display connection config, token status, and cached location counts
pathao:clear-cache Clear cached location tables

🔔 Webhook Integration

The package automatically registers a webhook endpoint at:

POST /api/pathao/webhook

Signature Validation: Incoming requests are validated against X-Pathao-Signature header using your PATHAO_SECRET_TOKEN.

Event Dispatching: On valid webhook, the package dispatches a PathaoWebhookReceived event. Listen for it in your application:

use devrkb21\PathaoLaravel\Events\PathaoWebhookReceived;

Event::listen(PathaoWebhookReceived::class, function ($event) {
    $payload = $event->payload;

    // Map webhook data to your order status updates
    // $payload['event'], $payload['consignment_id'], $payload['order_status'], etc.
});

Logging: All webhook calls (valid and invalid) are logged to the pathao_webhook_logs table. All API requests are logged to pathao_api_logs.

📦 Database Tables

After running migrations, the following tables are created:

Table Purpose
pathao-courier (configurable) Stores access tokens and secret keys
pathao_cities Cached cities directory
pathao_zones Cached zones directory
pathao_areas Cached areas directory
pathao_api_logs API request/response history
pathao_webhook_logs Webhook callback history

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固