-
Notifications
You must be signed in to change notification settings - Fork 0
Installation
This guide will walk you through the process of installing the Shippo PHP SDK in your project.
Before you begin, ensure you have the following prerequisites installed:
- PHP 8.1 or higher
- Composer
- A Shippo account (Sign up at https://goshippo.com/)
To install the package, run the following command in your project's root directory:
composer require tigusigalpa/shippo-phpTo use the Shippo API, you need an API token. You can find your token in your Shippo dashboard:
- Log in to your Shippo Dashboard.
- Navigate to Settings → API.
- Copy your Test Token for development and your Live Token for production.
For projects without a framework, you'll need to include the Composer autoloader and manually instantiate the Shippo client.
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Psr7\HttpFactory;
use Tigusigalpa\Shippo\Config;
use Tigusigalpa\Shippo\Shippo;
// Create configuration
$config = Config::make('your_test_token_here', [
'is_test' => true,
]);
// Initialize HTTP dependencies
$httpFactory = new HttpFactory();
// Create Shippo client
$shippo = new Shippo(
httpClient: new GuzzleClient(),
requestFactory: $httpFactory,
streamFactory: $httpFactory,
config: $config
);
// Use the client
$address = $shippo->addresses()->create([
'name' => 'John Doe',
'street1' => '215 Clayton St.',
'city' => 'San Francisco',
'state' => 'CA',
'zip' => '94117',
'country' => 'US',
]);
echo "Address created: {$address->objectId}\n";If you are using Laravel, the package will automatically register its service provider. You can publish the configuration file to customize the settings.
-
Publish the configuration file:
php artisan vendor:publish --tag=shippo-config
-
Add your API token to your
.envfile:SHIPPO_API_TOKEN=your_shippo_api_token_here SHIPPO_IS_TEST=true
With this setup, you can now use the Shippo facade in your Laravel application.