This PHP library aims to present the PHP implementation of the Boxtal v1 API.
We will see step by step the essential blocks for building a custom shipping module on your e-shop:
For more information on input parameters, classes, please refer to our documentation (in french).
$ composer require boxtal/php-library
In order to use the API, you need to create a (free) user account on www.boxtal.com.
To create a test account on our sandbox, use this link: shipping.boxtal.build.
Make sure to fill in your credentials in the configuration file : config/config.php
/* To use 'test' or 'prod' environment */
define("EMC_MODE", "test");
if (EMC_MODE == "prod") {
/* To set 'prod' environment constants */
define("EMC_USER", "yourLoginProd");
define("EMC_PASS", "yourPasswordProd");
} else {
/* To set 'test' environment constants */
define("EMC_USER", "yourLoginTest");
define("EMC_PASS", "yourPasswordTest");
}
The package contains 5 main directories:
Here are the elements needed to get a quotation:
require __DIR__ . '/vendor/autoload.php';
// shipper address
$from = array(
'country' => 'FR', // must be an ISO code, set get_country example on how to get codes
'zipcode' => '38400',
'city' => "Saint Martin d'Hères",
'address' => '13 Rue Martin Luther King',
'type' => 'company', // accepted values are "company" or "individual"
);
// recipient address
$to = array(
'country' => 'FR', // must be an ISO code, set get_country example on how to get codes
'zipcode' => '33000',
'city' => 'Bordeaux',
'address' => '28, rue des Ayres',
'type' => 'individual', // accepted values are "company" or "individual"
);
/* Parcel information */
$parcels = array(
'type' => 'colis', // your shipment type: "encombrant" (bulky parcel), "colis" (parcel), "palette" (pallet), "pli" (envelope)
'dimensions' => array(
1 => array(
'poids' => 1,
'longueur' => 15,
'largeur' => 16,
'hauteur' => 8
)
)
);
$additionalParams = array(
'collection_date' => date("Y-m-d"),
'delay' => 'aucun',
'content_code' => 10120, // List of the available codes at samples/get_categories.php > List of contents
'colis.valeur' => "42.655" // prefixed with your shipment type: "encombrant" (bulky parcel), "colis" (parcel), "palette" (pallet), "pli" (envelope)
);
$lib = new \Emc\Quotation();
$lib->getQuotation($from, $to, $parcels, $additionalParams);
// The offers list is available on the array : $lib->offers
if (!$lib->curl_error && !$lib->resp_error) {
print_r($lib->offers);
} else {
handle_errors($lib);
}
See also: Paris to Bordeaux
See also: Paris to Sydney (international)
The process of making an order is the same as making a quotation. The only difference is the extra parameters you need to send.
For the sender and the recipient, you need to give phone numbers, name and first name.
For the shipment, depending on the carrier chosen, you might need to give hours for pickup availability, dropoff and/or pickup parcel points.
All international shipments need an object.valeur parameter (where object is the shipment type: "encombrant" (bulky parcel), "colis" (parcel), "palette" (pallet), "pli" (envelope)).
require __DIR__ . '/vendor/autoload.php';
// shipper address
$from = array(
'country' => 'FR', // must be an ISO code, set get_country example on how to get codes
'zipcode' => '75002',
'city' => 'Paris',
'address' => '15, rue Marsollier',
'type' => 'company', // accepted values are "company" or "individual"
'title' => 'M', // accepted values are "M" (sir) or "Mme" (madam)
'firstname' => 'Jon',
'lastname' => 'Snow',
'societe' => 'Boxtal', // company name
'email' => 'jsnow@boxtal.com',
'phone' => '0606060606',
'infos' => 'Some informations about this address'
);
// Recipient's address
$to = array(
'country' => 'FR', // must be an ISO code, set get_country example on how to get codes
'zipcode' => '13002',
'city' => 'Marseille',
'address' => '1, rue Chape',
'type' => 'individual', // accepted values are "company" or "individual"
'title' => 'Mme', // accepted values are "M" (sir) or "Mme" (madam)
'firstname' => 'Jane',
'lastname' => 'Doe',
'email' => 'jdoe@boxtal.com',
'phone' => '0606060606',
'infos' => 'Some informations about this address'
);
/* Parcels informations */
$parcels = array(
'type' => 'colis', // your shipment type: "encombrant" (bulky parcel), "colis" (parcel), "palette" (pallet), "pli" (envelope)
'dimensions' => array(
1 => array(
'poids' => 5, // parcel weight
'longueur' => 15, // parcel length
'largeur' => 16, // parcel width
'hauteur' => 8 // parcel height
)
)
);
$additionalParams = array(
'collection_date' => date('Y-m-d'),
'delay' => "aucun", // no delay, meaning shipping as soon as possible
'assurance.selection' => false, // whether you want an extra insurance or not
'url_push' => 'www.my-website.com/push.php&order=',
'content_code' => 40110,
'colis.description' => "Tissus, vêtements neufs", // prefixed with your shipment type: "encombrant" (bulky parcel), "colis" (parcel), "palette" (pallet), "pli" (envelope)
'colis.valeur' => "42.655", // prefixed with your shipment type: "encombrant" (bulky parcel), "colis" (parcel), "palette" (pallet), "pli" (envelope)
'depot.pointrelais' => 'CHRP-POST',
'operator' => 'CHRP',
'service' => 'Chrono18'
);
// Prepare and execute the request
$lib = new \emc\Quotation();
$orderPassed = $lib->makeOrder($from, $to, $parcels, $additionalParams);
if (!$lib->curl_error && !$lib->resp_error) {
print_r($lib->order);
} else {
handle_errors($lib);
}
Using the API, you can get a list of the available content types which you will be able to use in your module. The "content type" is the nature of the content that you are shipping.
require __DIR__ . '/vendor/autoload.php';
$lib = new \Emc\ContentCategory();
$lib->getCategories(); // load all content categories
$lib->getContents(); // load all content types
// The content categories list is available on the array : $lib->categories
// The content types list is available on the array : $lib->contents
if (!$lib->curl_error && !$lib->resp_error) {
print_r($lib->categories);
print_r($lib->contents);
} else {
handle_errors($lib);
}
The API will need the content type ids as a parameter for quotations and orders.
See also: list of contents example
Orders shipping with the Boxtal API use country ISO codes. For now, the system only allows shipments from France to abroad, not from abroad to France. Here is how to get the list of countries:
$lib = new \Emc\Country();
$lib->getCountries();
// The countries list is available on the array: $lib->countries
if (!$lib->curl_error && !$lib->resp_error) {
print_r($lib->countries);
} else {
handle_errors($lib);
}
The API will need the country ISO code as a parameter for several actions.
See also: list of countries example
Once you've created a library instance, you can use the following functions.
/* To change login for this request only */
$lib->setLogin("otherLogin");
/* To change password for this request only */
$lib->setPassword("otherPassword");
/* To change environment for this request only */
$lib->setEnv("prod");
/* To set API return language */
$lib->setLocale("fr-FR");
For more information on input parameters, classes, please refer to our documentation (in french).
If you have any trouble implementing the library, contact us.