定制 mohd-arbaaz/amazon-shipping-laravel 二次开发

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

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

mohd-arbaaz/amazon-shipping-laravel

Composer 安装命令:

composer require mohd-arbaaz/amazon-shipping-laravel

包简介

A Laravel package for integrating with Amazon Shipping API v2

README 文档

README

A Laravel package for integrating with the Amazon Shipping API v2.

Installation

1. Install the package

composer require your-vendor/amazon-shipping-laravel

2. Publish the configuration

php artisan vendor:publish --tag=amazon-shipping-config

3. Run migrations

php artisan migrate

4. Configure environment variables

Add the following to your .env file:

AMAZON_SHIPPING_CLIENT_ID=your_client_id
AMAZON_SHIPPING_CLIENT_SECRET=your_client_secret
AMAZON_SHIPPING_REFRESH_TOKEN=your_refresh_token

# Optional - defaults shown
AMAZON_SHIPPING_SANDBOX=false
AMAZON_SHIPPING_API_URL=https://sellingpartnerapi-eu.amazon.com
AMAZON_SHIPPING_SANDBOX_URL=https://sandbox.sellingpartnerapi-eu.amazon.com
AMAZON_SHIPPING_BUSINESS_ID=AmazonShipping_IN
AMAZON_SHIPPING_TOKEN_TTL=60
AMAZON_SHIPPING_CACHE_KEY=amazon_shipping_access_token

Configuration

The configuration file config/amazon-shipping.php contains:

KeyDescriptionDefault
client_idAmazon SP-API Client ID-
client_secretAmazon SP-API Client Secret-
refresh_tokenAmazon SP-API Refresh Token-
api.sandboxEnable sandbox mode for testingfalse
api.base_urlProduction API base URLhttps://sellingpartnerapi-eu.amazon.com
api.sandbox_urlSandbox API base URLhttps://sandbox.sellingpartnerapi-eu.amazon.com
api.business_idAmazon Shipping Business IDAmazonShipping_IN
cache.token_ttlAccess token cache duration (minutes)60
cache.token_keyCache key for access tokenamazon_shipping_access_token

Supported Business IDs

RegionBusiness ID
IndiaAmazonShipping_IN
United StatesAmazonShipping_US
United KingdomAmazonShipping_UK
ItalyAmazonShipping_IT
SpainAmazonShipping_ES
FranceAmazonShipping_FR
JapanAmazonShipping_JP

Documentation

APIDescription
RatesFetch shipping rates for a given shipment
ShipmentsPurchase shipping labels and manage shipments
One-Click ShipmentCreate shipments with automatic rate selection
TrackingTrack shipment status and events
Cancel ShipmentCancel a purchased shipment
Shipment DocumentsRe-download labels and get shipping documents
NDR FeedbackSubmit non-delivery report feedback

API Logging

All API calls are automatically logged to the amazon_shipping_api_logs table:

ColumnDescription
endpointAPI endpoint called
methodHTTP method (GET, POST, etc.)
serviceService class that made the call
status_codeHTTP response status code
statussuccess or failed
request_payloadJSON request body
response_payloadJSON response body
error_messageError details (if failed)
duration_msRequest duration in milliseconds
created_atTimestamp

Querying Logs

use AmazonShipping\Models\AmazonShippingApiLog;

// Get recent failed requests
$failedRequests = AmazonShippingApiLog::query()
    ->where('status', 'failed')
    ->latest()
    ->take(10)
    ->get();

// Get average response time for rates API
$avgDuration = AmazonShippingApiLog::query()
    ->where('endpoint', '/shipping/v2/shipments/rates')
    ->where('status', 'success')
    ->avg('duration_ms');

Testing

The package includes comprehensive tests that can be run in two ways:

Running Tests via Artisan Command

After installing the package, you can run the package tests using the built-in artisan command:

# Run all package tests
php artisan amazon-shipping:test

# Run only Feature tests
php artisan amazon-shipping:test --testsuite=Feature

# Run only Integration tests (requires sandbox credentials)
php artisan amazon-shipping:test --testsuite=Integration

# Run specific tests by filter
php artisan amazon-shipping:test --filter=RatesServiceTest

# Run with code coverage
php artisan amazon-shipping:test --coverage

Running Tests via PHPUnit Directly

You can also run the package tests directly using PHPUnit:

# Run all package tests
./vendor/bin/phpunit ./vendor/mohd-arbaaz/amazon-shipping-laravel/tests

# Run Feature tests only
./vendor/bin/phpunit ./vendor/mohd-arbaaz/amazon-shipping-laravel/tests/Feature

# Run Integration tests only
./vendor/bin/phpunit ./vendor/mohd-arbaaz/amazon-shipping-laravel/tests/Integration

# Run with the package's phpunit.xml configuration
./vendor/bin/phpunit --configuration ./vendor/mohd-arbaaz/amazon-shipping-laravel/phpunit.xml

Test Types

Test SuiteDescriptionRequires Credentials
FeatureUnit tests with mocked API responsesNo
IntegrationLive tests against Amazon Shipping Sandbox APIYes

Integration Test Configuration

Integration tests call the actual Amazon Shipping Sandbox API. Configure sandbox credentials in your .env file:

AMAZON_SHIPPING_CLIENT_ID=your_sandbox_client_id
AMAZON_SHIPPING_CLIENT_SECRET=your_sandbox_client_secret
AMAZON_SHIPPING_REFRESH_TOKEN=your_sandbox_refresh_token
AMAZON_SHIPPING_SANDBOX=true
AMAZON_SHIPPING_BUSINESS_ID=AmazonShipping_IN  # or AmazonShipping_UK, etc.

Built-in region presets:

  • IN (India) - INR currency, GST tax details
  • UK (United Kingdom) - GBP currency
  • US (United States) - USD currency

Without credentials, integration tests are automatically skipped.

What Tests Verify

Test FileAPI TestedVerifies
RatesApiTest.phpgetRatesRate retrieval, DTO hydration, DB storage
PurchaseShipmentApiTest.phppurchaseShipmentShipment purchase, labels, tracking IDs
OneClickShipmentApiTest.phponeClickShipmentAuto rate selection, label generation
TrackingApiTest.phpgetTrackingTracking info, event history
CancelShipmentApiTest.phpcancelShipmentShipment cancellation
ShipmentDocumentsApiTest.phpgetShipmentDocumentsDocument retrieval, label re-download
NdrFeedbackApiTest.phpsubmitNdrFeedbackNDR actions (reschedule, reattempt, RTO)

Package Development

If you're contributing to this package, clone the repository and run tests locally:

# Clone the repository
git clone https://github.com/mohd-arbaaz/amazon-shipping-laravel.git
cd amazon-shipping-laravel

# Install dependencies
composer install

# Run tests
vendor/bin/phpunit

# Run specific test suite
vendor/bin/phpunit --testsuite Feature
vendor/bin/phpunit --testsuite Integration

License

MIT License

mohd-arbaaz/amazon-shipping-laravel 适用场景与选型建议

mohd-arbaaz/amazon-shipping-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 mohd-arbaaz/amazon-shipping-laravel 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-19