torfs-ict/crembl

Crembl API wrapper, allows you send regular (or registered) mail through the Crembl web service.

1.0.0 2017-01-05 17:50 UTC

This package is auto-updated.

Last update: 2024-04-21 19:33:27 UTC


README

API wrapper for the Crembl web service.

Please note that we are in no way affiliated with neither Crembl nor bpost. Issues regarding this API wrapper can be filed at our GitHub page, while issues regarding to the actual API should be filed with Crembl.

Usage

Before using this API make sure to check out the official documentation. The API only has three methods:

  1. Creating a task (i.e. document to be sent): createTask.
  2. Uploading a file for an existing task: uploadFile or uploadFileFromString.
  3. Retrieve information about an existing task: getTaskInfo.

Error handling

Whenever an error occurs, the client will throw an exception of type Crembl\Exception, where you can find the actual error information by calling the getInfo() method.

Examples

use bpost\Crembl\Client;
use bpost\Crembl\Config\TaskConfig;

$client = new Client('<secret>');

Creating a task

$task = new TaskConfig();
$task
    ->setDocumentTypeRegular()
    ->setAddresseeLine1('Microsoft Belgium')
    ->setAddresseeLine2('Corporate Village - Bayreuth Building')
    ->setAddressCountry('BE')
    ->setAddressZipCode('1935')
    ->setAddressCity('Zaventem')
    ->setAddressStreetName('Leonardo Da Vincilaan')
    ->setAddressStreetNumber('3');
$id = $client->createTask($task);

Returns the id generated by the Crembl API e.g. A12345678910111213141516171819209.

Uploading a file

$success = $client->uploadFile($id, __DIR__ . '/myletter.pdf');

Returns TRUE in case of success, or throws an error otherwise.

Retrieve task information

$task = $client->getTaskInfo($id);
var_dump($task);

Returns an object of type Crembl\Task\Info.