PHP code example of smart-dato / mondial-relay-shipping-sdk
1. Go to this page and download the library: Download smart-dato/mondial-relay-shipping-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
smart-dato / mondial-relay-shipping-sdk example snippets
use SmartDato\MondialRelayShipping\Data\Address;
use SmartDato\MondialRelayShipping\Data\Parcel;
use SmartDato\MondialRelayShipping\Data\Shipment;
use SmartDato\MondialRelayShipping\Enums\CollectionMode;
use SmartDato\MondialRelayShipping\Enums\DeliveryMode;
use SmartDato\MondialRelayShipping\Facades\MondialRelayShipping;
$shipment = new Shipment(
deliveryMode: DeliveryMode::PointRelais,
deliveryLocation: 'FR-66974',
collectionMode: CollectionMode::MerchantCollection,
sender: new Address(
streetname: 'Avenue Antoine Pinay',
houseNo: '4',
countryCode: 'FR',
postCode: '59510',
city: 'Hem',
addressAdd1: 'My Shop',
),
recipient: new Address(
streetname: 'Test Street',
houseNo: '10',
countryCode: 'FR',
postCode: '75001',
city: 'Paris',
firstname: 'John',
lastname: 'Doe',
phoneNo: '+33320202020',
),
parcels: [new Parcel(weightGrams: 1000, content: 'Books')],
orderNo: 'ORDER-1234',
);
$created = MondialRelayShipping::createShipment($shipment);
$created->shipmentNumber; // "96408887"
$created->labels[0]->output; // PDF URL (or base64 printer code)
$created->labels[0]->decoded(); // raw ZPL/IPL when using printer output
$created->warnings(); // non-blocking API warnings
use SmartDato\MondialRelayShipping\Data\OutputOptions;
use SmartDato\MondialRelayShipping\Enums\OutputFormat;
use SmartDato\MondialRelayShipping\Enums\OutputType;
$created = MondialRelayShipping::createShipment(
$shipment,
new OutputOptions(OutputType::ZplCode, OutputFormat::ZplGeneric10x15),
);
$zpl = $created->labels[0]->decoded();
$result = MondialRelayShipping::createShipments([$first, $second]);
$result->successful(); // CreatedShipment[]
$result->failed(); // CreatedShipment[] with their error statuses
$result->errors(); // Status[] (code, level, message)
use SmartDato\MondialRelayShipping\MondialRelayShipping;
$otherAccount = new MondialRelayShipping(
login: '[email protected]',
password: 'other-password',
customerId: 'OTHER123',
culture: 'de-DE',
sandbox: false,
);
$otherAccount->createShipment($shipment);
$result = MondialRelayShipping::createShipments([$shipment]);
$result->exchange->request; // XML sent (contains credentials!)
$result->exchange->sanitizedRequest(); // XML with the password masked — safe to log
$result->exchange->response; // raw XML received
$result->exchange->status; // HTTP status code
try {
MondialRelayShipping::createShipment($shipment);
} catch (RequestFailedException|CriticalErrorException|ShipmentFailedException|InvalidResponseException $exception) {
logger()->error('Mondial Relay call failed', [
'request' => $exception->exchange?->sanitizedRequest(),
'response' => $exception->exchange?->response,
]);
}