DEV Community

Cover image for Simplify International Shipping in PHP/Laravel with the EasyShip API
Igor
Igor

Posted on

Simplify International Shipping in PHP/Laravel with the EasyShip API

In modern eCommerce, fast and reliable shipping isn't just a nice-to-have; it's a critical factor for success. Customers expect transparency, speed, and fair prices, especially for international orders. For developers, integrating with multiple shipping carriers, calculating rates, tracking shipments, and handling customs documentation can be a major headache. Fortunately, platforms exist to handle the complexities of logistics, and one such platform is EasyShip.

What is EasyShip?

EasyShip is an all-in-one shipping platform that connects to over 550 courier services worldwide. It provides a unified API to access a wide range of logistics services, allowing online stores, marketplaces, and enterprise clients to automate and optimize their shipping processes. The platform offers discounted rates of up to 91%, automatic tax and duty calculations, and tools for tracking and returns. Giants like eBay and Shopify already use EasyShip to expand their global operations.

Key features of the EasyShip API include:

  • Rate Comparison: Get real-time shipping quotes from hundreds of carriers.
  • Label Generation: Create and print shipping labels in bulk.
  • Tracking: Monitor shipment status with webhook notifications.
  • Customs Clearance: Automatically calculate duties and taxes (DDP or DDU).
  • Returns Management: Generate pre-paid return labels.

Introducing easyship-php: A PHP/Laravel Client for the EasyShip API

For developers working with PHP and Laravel, a new convenient tool for integrating with EasyShip has emerged: the tigusigalpa/easyship-php library. This SDK provides full support for all 348+ EasyShip API endpoints and significantly simplifies the integration process.

The library is built with modern PHP standards (PSR-4/PSR-12) and supports PHP 8.1+ and Laravel 9-12. It includes essential features such as:

  • Complete API Coverage: All available EasyShip API methods are implemented.
  • Laravel Integration: Includes a service provider, facade, and configuration file.
  • OAuth 2.0 Support: Simplifies the creation of partner integrations.
  • Webhook Handling: Built-in signature verification for secure notification processing.
  • Typed Exceptions: Convenient API error handling.
  • Automatic Retries: Increases reliability during temporary network failures.
  • Sandbox and Production Support: Easy switching between environments.

Quick Start

Getting started with the library is very simple. First, install it via Composer:

composer require tigusigalpa/easyship-php
Enter fullscreen mode Exit fullscreen mode

For a standalone PHP project:

use Tigusigalpa\EasyShip\EasyShipClient;

$client = new EasyShipClient([
    'api_token' => 'sand_xxxxxxxxxxxxxxxx', // or prod_xxxxxxxxxxxxxxxx
    'timeout' => 30,
    'retry' => 3,
]);

$shipments = $client->shipments()->list();
Enter fullscreen mode Exit fullscreen mode

For a Laravel project:

  1. Publish the configuration file:

    php artisan vendor:publish --tag=easyship-config
    
  2. Add your API key to your .env file:

    EASYSHIP_API_TOKEN=sand_xxxxxxxxxxxxxxxx
    
  3. Use the facade or dependency injection:

    use Tigusigalpa\EasyShip\Laravel\Facades\EasyShip;
    
    // Via facade
    $shipments = EasyShip::shipments()->list();
    
    // Via Dependency Injection
    use Tigusigalpa\EasyShip\EasyShipClient;
    
    class ShippingController extends Controller
    {
        public function __construct(private EasyShipClient $easyship) {}
    
        public function index()
        {
            $shipments = $this->easyship->shipments()->list();
        }
    }
    

Conclusion

EasyShip provides a powerful solution for automating international shipping, and the easyship-php library makes its integration into PHP and Laravel projects incredibly simple and fast. With its complete API coverage, modern architecture, and convenient framework integration, this SDK will become an indispensable tool for developers looking to take their e-commerce business to a global level.

If you are looking for a reliable and functional solution for working with the EasyShip API, be sure to check out this library.

Top comments (0)