1. Go to this page and download the library: Download arzcode/laravel-correos 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/ */
arzcode / laravel-correos example snippets
use Arzcode\LaravelCorreos\Correos;
$correos = app(Correos::class);
$correos->preregister()->createShipments($request);
use Arzcode\LaravelCorreos\Facades\Correos;
Correos::preregister()->createShipments($request);
use Arzcode\LaravelCorreos\Data\Labels\PrintLabelsRequestData;
$labels = $correos->labels()->printLabels(PrintLabelsRequestData::from([
'documentationType' => 1, // 0=All, 1=Label, 2=CN22/CN23
'print' => [
'shipments' => ['PQXYZ1234567890'],
'labelFormat' => 2, // 1=XML, 2=PDF, 3=ZPL
'labelPrintMode' => 1, // 1=A4, 2=Labeler
],
]));
$labels->pdf; // Base64-encoded PDF content
$labels->decodedPdf(); // The same PDF as raw bytes, or null if there is none
use Arzcode\LaravelCorreos\Exceptions\CorreosApiException;
try {
$response = $correos->preregister()->createShipments($request);
} catch (CorreosApiException $e) {
$e->getMessage(); // Error message from the API
$e->getCode(); // HTTP status code
$e->errorCode; // Correos error code
$e->moreInformation; // Additional error details
$e->getResponse(); // The raw Saloon response, for logging
}
$labels = $correos->labels()->printLabels($labelRequest);
// Never reached when Correos answered `{"pdf": null, "error": "El envío no existe"}`.
$pdf = $labels->decodedPdf();
$correos->labels()->lastResponse()?->body();
$packages = $correos->preregister()->getPackagesByReference('ORDER-10231');
if ($packages->packageCodes) {
// Already registered: store the codes instead of creating the shipment again.
}