PHP code example of smart-dato / gls-shop-returns-customer-sdk
1. Go to this page and download the library: Download smart-dato/gls-shop-returns-customer-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 / gls-shop-returns-customer-sdk example snippets
return [
'environment' => env('GLS_ENVIRONMENT', 'sandbox'), // sandbox, qas, production
'app_id' => env('GLS_APP_ID', 'sandbox'),
'client_id' => env('GLS_CLIENT_ID', ''),
'client_secret' => env('GLS_CLIENT_SECRET', ''),
];
use SmartDato\GlsShopReturnsCustomer\GlsShopReturnsCustomer;
$gls = app(GlsShopReturnsCustomer::class);
use SmartDato\GlsShopReturnsCustomer\Data\CreateReturnOrderData;
$request = CreateReturnOrderData::from([
'originalOrderReference' => 'ORDER-12345',
'returnReason' => 'Product not as described',
'sender' => [
'personName' => 'Max Mustermann',
'address' => [
'street' => 'Musterstr. 1',
'city' => 'Berlin',
'zipCode' => '10115',
'countryCode' => 'DE',
],
],
]);
$response = $gls->createReturnOrder($request);
$response->returnOrderId; // "d137d614-ccc0-4d09-b956-9fc7483e7993"
$response->references->trackId; // "YUNKGBSU"
$response->references->parcelId; // "100002180461"
use SmartDato\GlsShopReturnsCustomer\Enums\LabelFormat;
$response = $gls->createReturnOrderWithLabel($request, LabelFormat::Pdf);
$response->returnOrderId;
$response->label->contentType; // "application/pdf"
$response->label->content; // Base64-encoded PDF
$rawPdf = $gls->createReturnOrderWithRawLabel($request, LabelFormat::Pdf);
// $rawPdf is the raw PDF binary content
file_put_contents('return-label.pdf', $rawPdf);
$response = $gls->createReturnOrderWithQrCode($request);
$response->parcelShopQrCode->contentType; // "application/pdf"
$response->parcelShopQrCode->content; // Base64-encoded QR code
use SmartDato\GlsShopReturnsCustomer\Enums\LabelType;
use SmartDato\GlsShopReturnsCustomer\Enums\LabelFormat;
// Get label as JSON (base64)
$response = $gls->getLabel(
returnOrderId: 'd137d614-ccc0-4d09-b956-9fc7483e7993',
labelType: LabelType::Label,
labelFormat: LabelFormat::Pdf,
);
// Get raw label binary
$rawLabel = $gls->getRawLabel(
returnOrderId: 'd137d614-ccc0-4d09-b956-9fc7483e7993',
labelType: LabelType::Label,
labelFormat: LabelFormat::Pdf,
);
$request = CreateReturnOrderData::from([
'originalOrderReference' => 'ORDER-12345',
'returnReason' => 'Wrong size',
'sender' => [
'personName' => 'Maria Garcia',
'companyName' => 'Garcia SL',
'email' => '[email protected] ', // Required for ES, FR, IT, SE
'address' => [
'street' => 'Calle Mayor 1',
'city' => 'Madrid',
'zipCode' => '28001',
'countryCode' => 'ES',
],
],
'parcel' => [
'weight' => 2.5, // kg, defaults to 1.5
],
'options' => [
'languageCode' => 'es',
'confirmationMail' => [
'sendTo' => ['[email protected] '],
'attachments' => [
'label' => ['
use SmartDato\GlsShopReturnsCustomer\Facades\GlsShopReturnsCustomer;
$response = GlsShopReturnsCustomer::createReturnOrder($request);
$label = GlsShopReturnsCustomer::createReturnOrderWithLabel($request, LabelFormat::Pdf);
$rawPdf = GlsShopReturnsCustomer::createReturnOrderWithRawLabel($request, LabelFormat::Pdf);
use SmartDato\GlsShopReturnsCustomer\Enums\Environment; // Sandbox, Qas, Production
use SmartDato\GlsShopReturnsCustomer\Enums\LabelFormat; // Pdf, Zpl, Png
use SmartDato\GlsShopReturnsCustomer\Enums\LabelType; // Label, ParcelShopQrCode
use SmartDato\GlsShopReturnsCustomer\Enums\LabelDpi; // Dpi152, Dpi203, Dpi300
use SmartDato\GlsShopReturnsCustomer\Enums\LabelLayout; // A4, A6
use SmartDato\GlsShopReturnsCustomer\Enums\LanguageCode; // German, English, French, Spanish, ...
use SmartDato\GlsShopReturnsCustomer\Exceptions\GlsApiException;
try {
$response = $gls->createReturnOrder($request);
} catch (GlsApiException $e) {
$e->getMessage(); // Error message from the API
$e->getCode(); // HTTP status code (400, 401, 403, 429, etc.)
$e->errors; // Array of ErrorData objects
$e->errors[0]->type; // "400-UNKNOWN-KEY"
$e->errors[0]->fieldName; // "layout"
$e->errors[0]->fieldValue; // "XYZ"
$e->errors[0]->message; // "must be one of [A4, A6]"
}