Search by

smart-dato / correos-sdk

smart-dato

Correos SOAP pre-registration and tracking SDK for Laravel

Package info

github.com/smart-dato/correos-sdk

Homepage

pkg:composer/smart-dato/correos-sdk

Fund package maintenance!

SmartDato

Statistics

Installs: 5 620

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.2.0 2026-09-24 07:08 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A small Laravel package for pre-registering Correos (Spanish postal service) shipments over SOAP and fetching their tracking events.

For labels, customs documents and a fuller API surface, see smart-dato/correos-shipping-sdk.

Requirements

  • PHP 8.2+
  • Laravel 10 – 13
  • The soap PHP extension

Installation

composer require smart-dato/correos-sdk

Publish the config file:

php artisan vendor:publish --tag="correos-sdk-config"
CORREOS_SDK_BASE_URL=https://your-correos-host
CORREOS_SDK_USERNAME=your-username
CORREOS_SDK_PASSWORD=your-password

SOAP calls go to {base_url}/preregistroenvios.

Usage

The CorreosSdk facade and container binding use the configured credentials:

use SmartDato\CorreosSdk\Facades\CorreosSdk;

$correos = CorreosSdk::getFacadeRoot();

Or construct the client yourself:

use SmartDato\CorreosSdk\CorreosSdk;

$correos = new CorreosSdk(
    baseUrl: 'https://your-correos-host',
    username: 'your-username',
    password: 'your-password',
);

Pre-register a shipment

Calls the PreRegistroMultibulto SOAP operation.

use SmartDato\CorreosSdk\Enums\DeliveryModeEnum;
use SmartDato\CorreosSdk\Enums\LabelModeEnum;
use SmartDato\CorreosSdk\Enums\PostageTypeEnum;
use SmartDato\CorreosSdk\Payloads\AddressPayload;
use SmartDato\CorreosSdk\Payloads\ParcelPayload;
use SmartDato\CorreosSdk\Payloads\ShipmentPayload;
use SmartDato\CorreosSdk\Payloads\ShippingPartyPayload;

$result = $correos->createShipment(new ShipmentPayload(
    date: '...',                // sent as FechaOperacion
    parcelCount: 1,
    senderInfo: new ShippingPartyPayload(
        name: 'Sender S.L.',
        address: new AddressPayload(address: 'Calle Mayor 1', city: 'Madrid'),
        zipcode: '28013',
        phone: '910000000',
        email: 'sender@example.com',
    ),
    receiverInfo: new ShippingPartyPayload(
        name: 'Jane Doe',
        address: new AddressPayload(address: 'Avinguda Diagonal 100', city: 'Barcelona'),
        zipcode: '08019',
        phone: '930000000',
        email: 'jane@example.com',
    ),
    parcels: [
        new ParcelPayload(parcelNumber: 1, weight: 1.5, length: 30, height: 20, width: 10),
    ],
    totalWeight: 1.5,
    labelCode: 'your-labeler-code', // CodEtiquetador, issued by Correos
    productCode: 'your-product-code', // CodProducto
    postageType: PostageTypeEnum::POSTAGE_PAID,   // TipoFranqueo
    deliveryMode: DeliveryModeEnum::STANDARD,     // ModalidadEntrega
    modDevLabel: (int) LabelModeEnum::PDF->value,
));

$result['request'];  // raw SOAP request XML
$result['response']; // raw SOAP response XML

createShipment() returns the raw SOAP request and response rather than a parsed object, and throws SoapFault on transport errors.

Values such as the operation date and weights are passed to Correos unchanged — the SDK does not enforce a date format or weight unit, so use whatever your Correos contract specifies.

postageType and deliveryMode default to POSTAGE_PAID and STANDARD.

Track a shipment

$events = $correos->getTracking('your-shipment-code');

Returns the decoded JSON from Correos's eventos_envio_servicio_auth endpoint, or an empty array when the body is not JSON.

The underlying HTTP exchange of the last call stays available for logging:

$correos->lastRequest();  // ?Illuminate\Http\Client\Request, also set when the connection failed
$correos->lastResponse(); // ?Illuminate\Http\Client\Response

Enums

Enum Cases
DeliveryModeEnum STANDARD (ST), IN_SELECTED_BRANCH (LS), IN_REFERENCE_BRANCH (OR), CITYPAQ (CP)
PostageTypeEnum POSTAGE_PAID (FP), MACHINE_FRANKING (FM), CASH (ES), ONLINE_PAYMENT (ON)
LabelModeEnum XML (1), PDF (2), ZPL (3)
WeightTypeEnum REAL (R), VOLUMETRIC (V)

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.