mohd-arbaaz/amazon-shipping-laravel 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mohd-arbaaz/amazon-shipping-laravel

最新稳定版本:v1.0.1

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

统计信息

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

GitHub 信息

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

其他信息

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