myparcelbe / sdk
This package is designed to send and receive data from MyParcel by means of an API.
Requires
- php: >=5.6.5
Requires (Dev)
- phpunit/phpunit: ^5.5
- dev-master
- v1.3.11
- v1.3.10
- v1.3.9
- v1.3.8
- v1.3.7
- v1.3.6
- v1.3.5
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.2.0-beta.2
- v1.2.0-beta.1
- v1.1.10
- v1.1.9
- v1.1.8
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.1
- v1.0.0
- v0.2.12
- v0.2.11
- v0.2.10
- v0.2.7
- v0.2.6
- v0.2.4
- v0.2.3
- 0.2.2
- 0.1.0
- dev-develop
- dev-multi-carrier
This package is not auto-updated.
Last update: 2020-01-15 17:54:51 UTC
README
- Installation
- Installation without composer
- Requirements
- Quick start and examples
- Available Methods
- Contribute
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 myparcelbe/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.
- Download the package zip (SDKvx.x.x.zip).
- Unzip the contents of the zip, and upload the vendor directory to your server.
- In your project, require the file src/AutoLoader.php
- You can now use the SDK in your project
Requirements
The MyParcel SDK works on php versions 5.6, 7.x. Also the php curl extension needs to be installed.
Quick start and examples
$myParcelCollection = new \MyParcelBE\Sdk\src\Helper\MyParcelCollection(); $consignment = (new \MyParcelBE\Sdk\src\Model\Repository\MyParcelConsignmentRepository()) ->setApiKey('api_key_from_MyParcel_backoffice') ->setReferenceId('Order 1203') ->setCountry('BE') ->setPerson('Piet Hier') ->setCompany('Piet BV') ->setFullStreet('Plein 1945 55b') ->setPostalCode('2231JE') ->setCity('Amsterdam') ->setEmail('test@test.nl'); $myParcelCollection ->addConsignment($consignment) ->setPdfOfLabels() ->downloadPdfOfLabels() ->setUserAgent('name_of_cms', '1.0');
Available Methods
$myParcelCollection = new \MyParcelBE\Sdk\src\Helper\MyParcelCollection(); $consignment = (new \MyParcelBE\Sdk\src\Model\Repository\MyParcelConsignmentRepository()) ->setApiKey('api_key_from_MyParcel_backoffice') ->setReferenceId('Order 1203') ->setCountry('BE') ->setPerson('Piet Hier') ->setCompany('Piet BV') ->setFullStreet('Plein 1945 55b') ->setPostalCode('2231JE') ->setPackageType(1) ->setCity('Amsterdam') ->setEmail('test@test.nl') ->setPhone('+31 (0)634213465') ->setLargeFormat(true) ->setOnlyRecipient(true) ->setSignature(true) ->setReturn(true) ->setInsurance(250) ->setLabelDescription('Order 10034'); $myParcelCollection ->addConsignment($consignment)
User-agent
To give us insight into which CMS system you make a connection from, you should send a User-Agent. If you're using a known CMS system it's required. You must send the name of the CMS system followed by a version number. A version is not required.
->setUserAgent('name_of_cms', '1.0')
Submitting full address
->setFullStreet('Plein 1945 55b')
Submitting address in pieces
->setStreet('Plein 1945') ->setNumber((string)55) ->setBoxNumber('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 \MyParcelBE\Sdk\src\Helper\MyParcelCollection(); foreach ($yourShipments as $yourShipment) { $consignment = (new \MyParcelBE\Sdk\src\Model\Repository\MyParcelConsignmentRepository()) ->setApiKey('api_key_from_MyParcel_backoffice') ->setReferenceId($yourShipment->getOrderId() ->setName('Piet Hier'); /** @todo; set all info */ $myParcelCollection ->setUserAgent('name_of_cms', '1.0') ->addConsignment($consignment) }
Later on
In a new request, you can get all the data again.
$consignment = (new \MyParcelBE\Sdk\src\Model\Repository\MyParcelConsignmentRepository()) ->setApiKey('api_key_from_MyParcel_backoffice') ->setReferenceId('Order 1203'); // or setMyParcelConsignmentId(123456) $myParcelCollection ->addConsignment($consignment) ->setLatestData(); $consignments = $myParcelCollection ->getConsignments(); $firstConsignment = $consignments[0]; $status = $firstConsignment->getStatus(); $barcode = $firstConsignment->getBarcode();
Contribute
- Check for open issues or open a new issue to start a discussion around a bug or feature.
- Fork the repository on GitHub to start making your changes.
- Write one or more tests for the new feature or that expose the bug.
- Make code changes to implement the feature or fix the bug.
- Send a pull request to get your changes merged and published.