定制 manoar/laravel-steadfast 二次开发

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

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

manoar/laravel-steadfast

Composer 安装命令:

composer require manoar/laravel-steadfast

包简介

A Laravel package for interacting with the Steadfast Courier API.

README 文档

README

A Laravel package that provides seamless integration with Steadfast Courier API services.

Installation

Install the package via Composer:

composer require manoar/laravel-steadfast

Configuration

  1. Publish the configuration file:
php artisan vendor:publish --provider="Manoar\Steadfast\SteadfastServiceProvider"
  1. Configure your credentials in your .env file:
STEADFAST_API_KEY=your_api_key
STEADFAST_API_SECRET=your_api_secret
STEADFAST_API_URL=https://api.steadfast.com

Usage

Facade Usage

<?php
use Manoar\Steadfast\Facades\Steadfast;
use Manoar\Steadfast\Exceptions\SteadfastApiException;

try {
    // Create an order
    $response = Steadfast::createOrder([
        'invoice' => 'INV-123',
        'recipient_name' => 'John Doe',
        'recipient_phone' => '01700000000',
        'recipient_address' => '123 Main St, Dhaka',
        'cod_amount' => 1500,
        'note' => 'Please handle with care'
    ]);
    
    $consignmentId = $response['consignment']['consignment_id'];
    $trackingCode = $response['consignment']['tracking_code'];
    
    // Get order status
    $status = Steadfast::getStatusByConsignmentId($consignmentId);
    
    // Check balance
    $balance = Steadfast::getBalance();
} catch (SteadfastApiException $e) {
    // Handle errors
    $message = $e->getMessage();
    $responseData = $e->getApiErrorData();
    $statusCode = $e->getCode();
}

Dependency Injection

<?php
use Manoar\Steadfast\SteadfastClient;

class OrderController extends Controller
{
    protected SteadfastClient $steadfast;
    
    public function __construct(SteadfastClient $steadfast)
    {
        $this->steadfast = $steadfast;
    }
    
    public function placeOrder(Request $request)
    {
        try {
            $response = $this->steadfast->createOrder([
                'invoice' => $request->invoice_id,
                'recipient_name' => $request->name,
                'recipient_phone' => $request->phone,
                'recipient_address' => $request->address,
                'cod_amount' => $request->amount,
                'note' => $request->note
            ]);
            
            return response()->json(['success' => true, 'data' => $response]);
        } catch (SteadfastApiException $e) {
            return response()->json(['success' => false, 'message' => $e->getMessage()], 500);
        }
    }
}

Available Methods

Method Description
createOrder(array $data) Create a new order/consignment
placeBulkOrders(array $orders) Place multiple orders in bulk (max 500)
getStatusByConsignmentId(string|int $consignmentId) Get status by Consignment ID
getStatusByInvoice(string $invoiceId) Get status by Invoice ID
getStatusByTrackingCode(string $trackingCode) Get status by Tracking Code
getBalance() Get merchant account balance

Error Handling

The package throws SteadfastApiException on API failures, providing:

  • Error message via getMessage()
  • HTTP status code via getCode()
  • API error data via getApiErrorData()
  • Full HTTP response via getResponse()

Local Development

To develop this package locally:

  1. Create a directory structure:

    packages/manoar/laravel-steadfast/
  2. Add to your Laravel project's composer.json:

    "repositories": [
      {
        "type": "path",
        "url": "packages/manoar/laravel-steadfast"
      }
    ],
    "require": {
      "manoar/laravel-steadfast": "@dev"
    }
  3. Run composer update manoar/laravel-steadfast

License

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

Contributing

Contributions are welcome! Please follow the coding standards and include tests for new features or bug fixes.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固