Skip to content

rhamoudi/sdk

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MyParcel SDK



Please, star this repository if you use this repository. ⭐

Installation with composer

This SDK uses composer.

Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

For more information on how to use/install composer, please visit: https://github.com/composer/composer

To install the MyParcel SDK into your project, simply

$ composer require myparcelnl/sdk

Installation without composer

If you don't have experience with composer, it is possible to use the SDK without using composer.

You can download the zip on the projects releases page.

  1. Download the package zip (SDKvx.x.x.zip).
  2. Unzip the contents of the zip, and upload the vendor directory to your server.
  3. In your project, require the file src/AutoLoader.php
  4. You can now use the SDK in your project

Requirements

The MyParcel SDK works on php versions 5.6, 7.0 and 7.1. Also the php curl extension needs to be installed.

Quick start and examples

$myParcelCollection = new MyParcelCollection();

$consignment = (new MyParcelConsignmentRepository())
    ->setApiKey('api_key_from_MyParcel_backoffice')
    ->setReferenceId('Order 1203')
    ->setCountry('NL')
    ->setPerson('Piet Hier')
    ->setCompany('Piet BV')
    ->setFullStreet('Plein 1945 55b')
    ->setPostalCode('2231JE')
    ->setCity('Amsterdam')
    ->setEmail('[email protected]');
    
$myParcelCollection
    ->addConsignment($consignment)
    ->setPdfOfLabels()
    ->downloadPdfOfLabels();

Available Methods

$myParcelCollection = new MyParcelCollection();

$consignment = (new MyParcelConsignmentRepository())
    ->setApiKey('api_key_from_MyParcel_backoffice')
    ->setReferenceId('Order 1203')
    ->setCountry('NL')
    ->setPerson('Piet Hier')
    ->setCompany('Piet BV')
    ->setFullStreet('Plein 1945 55b')
    ->setPostalCode('2231JE')
    ->setPackageType(1)
    ->setCity('Amsterdam')
    ->setEmail('[email protected]')
    ->setPhone('+31 (0)634213465')
    ->setLargeFormat(true)
    ->setOnlyRecipient(true)
    ->setSignature(true)
    ->setReturn(true)
    ->setInsurance(250)
    ->setLabelDescription('Order 10034');
    
$myParcelCollection
    ->addConsignment($consignment)

Submitting address in pieces

    ->setStreet('Plein 1945')
    ->setNumber((string)55)
    ->setNumberSuffix('b')

Create concept

$myParcelCollection->createConcepts();

Download labels

$myParcelCollection->setPdfOfLabels();
$myParcelCollection->downloadPdfOfLabels();

Get label link

$myParcelCollection
    ->setLinkOfLabels()
    ->getLinkOfLabels()

MyParcel consignment id

If you don't use setReferenceId(), you can also use the MyParcelConsignmentId when you create a concept: After setPdfOfLabels(), setLinkOfLabels() and createConcepts(), you can save the api id to your database. With this id you can easily retrieve the latest status.

$consignment->getMyParcelConsignmentId();

Get status

After setPdfOfLabels(), setLinkOfLabels() and createConcepts() you can get the status.

$status = $consignment->getStatus();

Get barcode

The barcode is available after setPdfOfLabels() and setLinkOfLabels()

$barcode = $consignment->getBarcode();

Multiple shipments

To create multiple consignments or get one pdf with multiple consignments, set multiple consignments. It's faster and cleaner.

$myParcelCollection = new MyParcelCollection();

foreach ($yourShipments as $yourShipment) {

    $consignment = (new MyParcelConsignmentRepository())
        ->setApiKey('api_key_from_MyParcel_backoffice')
        ->setReferenceId($yourShipment->getOrderId()
        ->setName('Piet Hier');
        /** @todo; set all info */
        
    $myParcelCollection
        ->addConsignment($consignment)
}

Later on

In a new request, you can get all the data again.

$consignment = (new MyParcelConsignmentRepository())
    ->setApiKey('api_key_from_MyParcel_backoffice')
    ->setReferenceId('Order 1203'); // or setMyParcelConsignmentId(123456)

$myParcelCollection
    ->addConsignment($consignment)
    ->setLatestData();

$consignment = $myParcelCollection
    ->getOneConsignment();

$status = $consignment->getStatus();
$barcode = $consignment->getBarcode();

Contribute

  1. Check for open issues or open a new issue to start a discussion around a bug or feature.
  2. Fork the repository on GitHub to start making your changes.
  3. Write one or more tests for the new feature or that expose the bug.
  4. Make code changes to implement the feature or fix the bug.
  5. Send a pull request to get your changes merged and published.

About

The sdk to use in your favorite framework

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%