cleverage/colissimo-bundle

Simple colissimo REST bundle for Symfony

Installs: 2 568

Dependents: 0

Suggesters: 0

Security: 0

Stars: 7

Watchers: 4

Forks: 3

Open Issues: 0

Type:symfony-bundle

v1.1.0 2023-12-05 08:55 UTC

This package is auto-updated.

Last update: 2024-11-05 10:46:29 UTC


README

Introduction

This bundle provides services to access and consume the Colissimo WS.

Services

Requirements

  • Php >= 7.4
  • Symfony 4, 5 or 6

Installation

Pretty simple with Composer, run

composer require cleverage/colissimo-bundle

Register bundle inside your application :

// config/bundles.php
CleverAge\ColissimoBundle\CleverAgeColissimoBundle::class => ['all' => true],

Configuration example :

Inside config/packages/cleverage_colissimo.yaml

clever_age_colissimo:
  testModeEnabled: true
  auth:
    contractNumber: '22020'
    password: 'password'
  letter:
    service:
      commercialName: 'CommercialName'
    sender:
      companyName: 'CompanyName'
      line0: null
      line1: null
      line2: '9 rue André darbon'
      line3: null
      countryCode: 'FR'
      zipCode: '33300'
      city: 'Bordeaux'

Usage examples :

Get pickup points

class PickupPointsController extends AbstractController
{
    private PickupPointsService $pickupPointsService;

    public function __construct(
        PickupPointsService $pickupPointsService
    ) {
        $this->pickupPointsService = $pickupPointsService;
    }

    public function index()
    {
        $searchModel = new PickupPointsSearchModel(
            '33300',
            'Bordeaux',
            'FR',
            '18/07/2022',
        );

        // Return an array of PickupPoint::class
        $pickupPoints = $this->pickupPointsService->call($searchModel);

        foreach ($pickupPoints as $pickupPoint) {
            // Get data by identifier.
            // @see PickupPoint to show all identifiers available.
            echo $pickupPoint->get('id'); // 987178
            echo $pickupPoint->get('name'); // ALEX TISSUS
        }

        // ....
    }
}

Get pickup point by ID

class PickupPointByIdController extends AbstractController
{
    private PickupPointByIdService $pickupPointByIdService;

    public function __construct(
        PickupPointByIdService $pickupPointByIdService
    ) {
        $this->pickupPointByIdService = $pickupPointByIdService;
    }

    public function index()
    {
        $searchByIdModel = new PickupPointSearchByIdModel('987178', '18/07/2022');
        $pickupPoint = $this->pickupPointByIdService->call($searchByIdModel);

        if (null !== $pickupPoint) {
            echo $pickupPoint->get('name'); // ALEX TISSUS
        }

        // ....
    }
}

Tracking

class TrackingController extends AbstractController
{
    private TrackingService $trackingService;

    public function __construct(
        TrackingService $trackingService
    ) {
        $this->trackingService = $trackingService;
    }

    public function index()
    {
        $trackingSearchModel = new TrackingSearchModel();
        $trackingSearchModel
            ->setLang('FR') // FR is set by default. This line is optionnal.
            ->setParcelNumber('ABNUABSASNLK');

        $tracking = $this->trackingService->call($trackingSearchModel);

        $tracking->getParcel();
        $tracking->getSteps();
        $tracking->getEvents();

        // @see TrackingResponse::class for usable getters.
        // ....
    }
}

Shipping

class ShippingController extends AbstractController
{
    private ShippingService $shippingService;

    public function __construct(
        ShippingService $shippingService
    ) {
        $this->shippingService = $shippingService;
    }

    public function index()
    {
        $label = new Label();

        $outputFormat = new OutputFormat();
        $outputFormat->setOutputPrintingType(OutputPrintingType::ZPL_10x10_300dpi);

        $label->setOutputFormat($outputFormat);

        $letter = new Letter();

        $service = new Letter\Service();
        $service->setProductCode(ProductCode::DOM)
            ->setDepositDate((new \DateTime())->format('Y-d-m'))
            ->setOrderNumber('orderNumber');

        $letter->setService($service);

        $parcel = new Letter\Parcel();
        $parcel->setWeight(3);
        // If it's delivery on pickup point
        $parcel->setPickupLocationId('987178');

        $letter->setParcel($parcel);

        $addressee = new Letter\Addressee();
        $addressee->setEmail('test@clever-age.com')
            ->setFirstName('John')
            ->setLastName('Doe')
            ->setLine2('9 rue André darbon')
            ->setCity('Bordeaux')
            ->setCountryCode('FR')
            ->setZipCode('33300');

        $letter->setAddressee($addressee);

        $label->setLetter($letter);

        $shipping = $this->shippingService->call($label);

        echo $shipping->getParcelNumber(); // AIAOBOIABS
        echo $shipping->getPdfUrl(); // null or the pdf url.
        echo $shipping->getParcelNumberPartner(); // null or the parcel number partner.
        echo $shipping->getFields(); // Array of custom fields.

        // ...
    }
}

Product inter

class ProductInterController extends AbstractController
{
    private ProductInterService $productInterService;

    public function __construct(
        ProductInterService $productInterService
    ) {
        $this->productInterService = $productInterService;
    }

    public function index()
    {
        $productInter = new ProductInter();
        $productInter->setCountryCode('FR')
            ->setZipCode('33300')
            ->setProductCode(ProductCode::DOM)
            ->setInsurance(false) // Default false. Optional.
            ->setNonMachinable(false) // Default false. Optional.
            ->setReturnReceipt(false); // Default false. Optional.

        $response = $this->productInterService->call($productInter);

        $response->getProduct(); // Array of product codes.
        $response->getReturnTypeChoice(); // Array of return choice types.

        // ...
    }
}

License

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