2017 © Pedro Peláez
 

library sendcloud

Provides a client to interact with the SendCloud API.

image

jouwweb/sendcloud

Provides a client to interact with the SendCloud API.

  • Monday, June 18, 2018
  • by roelvanduijnhoven
  • Repository
  • 0 Watchers
  • 0 Stars
  • 67 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 509 % Grown

The README.md

Sendcloud

This is a PHP library that provides a simple way to communicate with the Sendcloud API. It was created because there were no simple alternatives that follow good object-oriented code practices., (*1)

NOTE: This library does not implement all Sendcloud API functionality. If you require functionality that is missing please request it through a GitHub issue or pull request., (*2)

Example

use JouwWeb\Sendcloud\Client;
use JouwWeb\Sendcloud\Model\Address;
use JouwWeb\Sendcloud\Model\Parcel;
use JouwWeb\Sendcloud\Model\ParcelItem;
use JouwWeb\Sendcloud\Model\WebhookEvent;
use JouwWeb\Sendcloud\Exception\SendcloudRequestException;

$client = new Client('your_public_key', 'your_secret_key');

// Print prices for all enabled shipping methods that ship to the Netherlands
foreach ($client->getShippingMethods() as $shippingMethod) {
    $price = $shippingMethod->getPriceForCountry('NL');
    if ($price) {
        echo $shippingMethod->getName() . ': €' . ($price / 100) . PHP_EOL;
    }
}

// Create a parcel and label
try {
    // Most of these arguments are optional and will fall back to defaults configured in Sendcloud
    $parcel = $client->createParcel(
        shippingAddress: new Address(
            name: 'John Doe',
            companyName: 'Big Box Co.',
            addressLine1: 'Office Street 2834A',
            city: 'Metropolis',
            postalCode: '9999ZZ',
            countryCode: 'NL',
            emailAddress: 'john@bigbox.co',
            phoneNumber: '+31612345678'
        ),
        servicePointId: null,
        orderNumber: '20190001',
        weight: 2500, // 2.5kg
        // Below options are only required when shipping outside the EU
        customsInvoiceNumber: 'CI-8329823',
        customsShipmentType: Parcel::CUSTOMS_SHIPMENT_TYPE_COMMERCIAL_GOODS,
        items: [
            new ParcelItem('green tea', 1, 123, 15.20, '090210', 'EC'),
            new ParcelItem('cardboard', 3, 50, 0.20, '090210', 'NL'),
        ],
        postNumber: 'PO BOX 42',
    );

    $parcel = $client->createLabel(
        parcel: $parcel,
        shippingMethod: 8,
        senderAddress: null, // Default sender address.
    );

    $pdf = $client->getLabelPdf($parcel, Parcel::LABEL_FORMAT_A4_BOTTOM_RIGHT);

    var_dump($parcel, $pdf);
} catch (SendcloudRequestException $exception) {
    echo $exception->getMessage();
}

// Verify and parse a webhook request
$webhookEvent = $client->parseWebhookRequest($request);
if ($webhookEvent->getType() === WebhookEvent::TYPE_PARCEL_STATUS_CHANGED) {
    $parcel = $webhookEvent->getParcel();
}

Retieve a list of service points

use JouwWeb\Sendcloud\ServicePointsClient;
use JouwWeb\Sendcloud\Exception\SendcloudRequestException;

$client = new ServicePointsClient('your_public_key', 'your_secret_key');

try {
    // Search for service points in the Netherlands.
    $servicePoints = $client->searchServicePoints('NL');

    var_dump($servicePoints[0]->isActive()); // bool(true)
    var_dump($servicePoints[0]->getName()); // string(7) "Primera"
    var_dump($servicePoints[0]->getCarrier()); // string(6) "postnl"
    var_dump($servicePoints[0]->getDistance()); // NULL ↓

    // If we want Sendcloud to calculate the distance between us and each service point, we need to supply latitude and
    // longitude.
    $servicePointsWithDistance = $client->searchServicePoints(
        country: 'NL',
        latitude: 51.4350511,
        longitude: 5.4746339
    );

    var_dump($servicePointsWithDistance[0]->getName()); // string(14) "Pakketautomaat"
    var_dump($servicePointsWithDistance[0]->getDistance()); // int(553)

    // Obtain a specific service point by ID.
    $servicePoint = $client->getServicePoint(1);
} catch (SendcloudRequestException $exception) {
    echo $exception->getMessage();
}

Installation

composer require jouwweb/sendcloud, (*3)

The Versions

18/06 2018

dev-master

9999999-dev

Provides a client to interact with the SendCloud API.

  Sources   Download

MIT

The Requires

 

by Avatar Villermen

18/06 2018

v2.0.0

2.0.0.0

Provides a client to interact with the SendCloud API.

  Sources   Download

MIT

The Requires

 

by Avatar Villermen

13/06 2018

v1.0.1

1.0.1.0

Provides a client to interact with the SendCloud API.

  Sources   Download

MIT

The Requires

 

by Avatar Villermen

25/05 2018

v1.0.0

1.0.0.0

Provides a client to interact with the SendCloud API.

  Sources   Download

MIT

The Requires

 

by Avatar Villermen

07/05 2018

v0.1.0

0.1.0.0

Provides a client to interact with the SendCloud API.

  Sources   Download

MIT

The Requires

 

by Avatar Villermen