2017 © Pedro Peláez
 

library myparcel-php-api

MyParcel API client for PHP

image

mvdnbrk/myparcel-php-api

MyParcel API client for PHP

  • Sunday, February 4, 2018
  • by mvdnbrk
  • Repository
  • 1 Watchers
  • 0 Stars
  • 13 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 86 % Grown

The README.md

MyParcel API client for PHP

PHP version ![Latest Version on Packagist][ico-version] Software License [![Tests][ico-tests]][link-tests] ![StyleCI][ico-code-style] Total Downloads, (*1)

MyParcel makes sending packages easy., (*2)

MyParcel API documentation, (*3)

Requirements

To use the MyParcel API client, the following things are required:, (*4)

Installation

You can install the package via composer:, (*5)

``` bash composer require mvdnbrk/myparcel-php-api, (*6)


## Getting started Initialize the MyParcel client and set your API key: ``` php $myparcel = new \Mvdnbrk\MyParcel\Client(); $myparcel->setApiKey('your-api-key');

Create a parcel

``` php $parcel = new \Mvdnbrk\MyParcel\Resources\Parcel([ 'reference' => 'your own reference for the parcel', 'recipient' => [ 'first_name' => 'John', 'last_name' => 'Doe' 'street' => 'Poststraat', 'number' => '1', 'number_suffix' => 'A', 'postal_code' => '1234AA', 'city' => 'Amsterdam', 'cc' => 'NL', ] ]);, (*7)


### Create a shipment ``` php $shipment = $myparcel->shipments->create($parcel); // Get the `id` of the shipment. You may save this value for later reference. $shipment->id;

You have created your first shipment!, (*8)

Retrieve a label

A label can be retrieved by using $shipment->id. This will return a label in A6 format as a string., (*9)

$myparcel->labels->get($shipment->id);

Or you may pass the Shipment instance directly to this method:, (*10)

$myparcel->labels->get($shipment);

The label format is A6 by default, you may change this by calling the setFormatA4 method:, (*11)

$myparcel->labels->setFormatA4()->get($shipment);

Setting delivery options for a parcel

You can set delivery options for a parcel by passing in the options directly when you create a parcel:, (*12)

``` php $parcel = new \Mvdnbrk\MyParcel\Resources\Parcel([ ... 'recipient' => [ ... ], 'options' => [ 'description' => 'Description on the label', 'signature' => true, ... ], ]);, (*13)


Or you may use a method like `signature`, `onlyRecipient`, `returnToSender`, `ageCheck` and `labelDescription`. You may call any of these methods after constructing the parcel: ``` php $parcel->labelDescription('Your description.') ->ageCheck() ->onlyRecipient() ->returnToSender() ->signature();

Mailbox package, (*14)

This package type is only available for shipments in the Netherlands that fit in a standard mailbox., (*15)

``` php $parcel->mailboxpackage();, (*16)


### Send a parcel to a service point You may send a parcel to a PostNL service point where a customer can pick up the parcel: ``` php $parcel = new \Mvdnbrk\MyParcel\Resources\Parcel([ 'recipient' => [ ... ], 'pickup' => [ 'name' => 'Name of the location', 'street' => 'Poststraat', 'number' => '1', 'postal_code' => '1234AA', 'city' => 'Amsterdam', 'cc' => 'NL, ] ]);

Retrieve service points

$servicepoints = $myparcel->servicePoints->setPostalcode('1234AA')->setHousenumber('1')->get();

This will return a collection of ServicePoint objects:, (*17)

$servicepoints->each(function ($item) {
    $item->id;
    $item->name;
    $item->latitude;
    $item->longitude;
    $item->distance;
    $item->distanceForHumans();
    $item->opening_hours;
});

Get a shipment

You can get a shipment by id or your own reference., (*18)

``` php $shipment = $myparcel->shipments->get($id);, (*19)

$shipment = $myparcel->shipments->getByReference('your own reference');, (*20)

// Get the barcode for the shipment: $shipment->barcode;, (*21)

// Get the current status: $shipment->status;, (*22)


### Track a shipment You can get detailed track and trace information for a shipment. ``` php $tracktrace = $myparcel->tracktrace->get($id); // Links: $tracktrace->link; $tracktrace->link_portal; // Check if the shipment is delivered: $tracktrace->isDelivered; // Get current state of the shipment: $tracktrace->code; $tracktrace->description; $tracktrace->datetime; // Get all traces for the shipment, this will return a collection with // all traces in descending order, including the current state: $tracktrace->items; // Convert all items to an array: $tracktrace->items->all()

Usage with Laravel

You may incorporate this package in your Laravel application by using this package., (*23)

Changelog

Please see CHANGELOG for more information what has changed recently., (*24)

Testing

bash $ composer test, (*25)

Contributing

Please see CONTRIBUTING for details., (*26)

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities., (*27)

Credits

License

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

The Versions

04/02 2018

dev-master

9999999-dev https://github.com/mvdnbrk/myparcel-php-api

MyParcel API client for PHP

  Sources   Download

MIT

The Requires

  • php ~5.6|~7.0

 

The Development Requires

php myparcel