PHP code example of alexanderpoellmann / laravel-post-plc
1. Go to this page and download the library: Download alexanderpoellmann/laravel-post-plc 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/ */
alexanderpoellmann / laravel-post-plc example snippets
use AlexanderPoellmann\LaravelPostPlc\Enums\PostProductCodes;
use AlexanderPoellmann\LaravelPostPlc\Shipping\PostPlcShippingAdapter;
use AlexanderPoellmann\Shipping\Data\Address;
use AlexanderPoellmann\Shipping\Data\Parcel;
use AlexanderPoellmann\Shipping\Data\Shipment;
$adapter = app(PostPlcShippingAdapter::class)
->forProduct(PostProductCodes::PaketOesterreich);
$result = $adapter->createShipment(new Shipment(
sender: new Address('Sender GmbH', 'Rochusmarkt', '1030', 'Wien', 'AT', houseNumber: '5'),
recipient: new Address('Recipient GmbH', 'Hauptplatz', '4020', 'Linz', 'AT', houseNumber: '1'),
parcels: [new Parcel(weightInGrams: 1200, lengthInMillimeters: 300, widthInMillimeters: 200, heightInMillimeters: 100)],
reference: 'ORDER-42',
));
foreach ($result->trackingNumbers as $trackingNumber) {
$trackingNumber->value; // String, preserving leading zeros.
}
foreach ($result->labels as $label) {
$label->contents; // Decoded PDF bytes or raw ZPL text.
$label->mimeType;
$label->trackingNumber; // Null for a document covering multiple parcels.
}
use AlexanderPoellmann\LaravelPostPlc\Enums\LabelSizes;
use AlexanderPoellmann\LaravelPostPlc\Enums\PaperLayouts;
use AlexanderPoellmann\LaravelPostPlc\Enums\PrinterLanguages;
$thermal = $adapter->withPrinter(
language: PrinterLanguages::ZPL2,
labelSize: LabelSizes::SHORT,
paperLayout: PaperLayouts::SHORT,
);
foreach (app()->tagged('shipping.adapters') as $carrier) {
$carrier->carrier();
}
use AlexanderPoellmann\LaravelPostPlc\Classes\Address;
use AlexanderPoellmann\LaravelPostPlc\Classes\Collo;
use AlexanderPoellmann\LaravelPostPlc\Classes\Shipment;
use AlexanderPoellmann\LaravelPostPlc\DataTransferObjects\FeatureRow;
use AlexanderPoellmann\LaravelPostPlc\Enums\PostProductCodes;
use AlexanderPoellmann\LaravelPostPlc\Enums\ServiceMethods;
use AlexanderPoellmann\LaravelPostPlc\Facades\LaravelPostPlc;
$from = (new Address)
->name('Absender GmbH')
->street('Rochusmarkt 5')
->postCode('1030')
->city('Wien')
->countryCode('AT')
->phone('+431234567')
->email('[email protected]')
->get();
$to = (new Address)
->name('Musterfirma GmbH', 'c/o Maria Muster')
->street('Landesgerichtsstraße 1')
->postCode('1010')
->city('Wien')
->countryCode('AT')
->email('[email protected]')
->get();
$shipment = (new Shipment)
->withPrinter()
->withNumber('ORDER-12345')
->using(PostProductCodes::PaketPremiumOesterreichB2B)
->from($from)
->to($to)
->withFeatures([
FeatureRow::cashOnDelivery(
amount: 199.99,
currency: 'EUR',
iban: 'AT000000000000000000',
bic: 'BICCODE',
accountHolder: 'Muster GmbH',
paymentReference: 'ORDER-12345',
),
])
->parcels([
(new Collo)->weight(0.4)->get(),
])
->get();
LaravelPostPlc::request(ServiceMethods::ImportShipment, $shipment, asRow: true);
$result = LaravelPostPlc::toObject();
use AlexanderPoellmann\LaravelPostPlc\Validation\ShipmentValidator;
$validation = app(ShipmentValidator::class)->validate($shipment);
$validation->throwIfInvalid();
use AlexanderPoellmann\LaravelPostPlc\Resolvers\AllowedServicesResolver;
$capabilities = app(AllowedServicesResolver::class)->forCountries('DE');
foreach ($capabilities->products() as $product) {
$product->code->value;
$product->name;
$product->contractProduct; // PLC's "Vertragsprodukt Ja/Nein" flag
$product->order;
$product->featureCodes();
}
$capabilities->allowsProduct('45');
$capabilities->allowsFeature('45', '054');
use AlexanderPoellmann\LaravelPostPlc\LaravelPostPlc;
$client = app(LaravelPostPlc::class)->forProfile('store-b');
$factory = new ReturnShipmentFactory($client);
$labels = new ReturnLabelService($client, app(ShipmentValidator::class));
$capabilities = new AllowedServicesResolver($client, app(\Illuminate\Contracts\Cache\Repository::class));