Skip to content

Commit

Permalink
Merge pull request #104 from myparcelnl/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
RichardPerdaan authored Mar 29, 2019
2 parents 246ea7d + 3c4e52f commit 2844d55
Show file tree
Hide file tree
Showing 46 changed files with 6,942 additions and 1,574 deletions.
119 changes: 35 additions & 84 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ This SDK connects to the MyParcel API using PHP.
## Installation

### Requirements
The MyParcel SDK works with PHP versions 5.4, 5.6 and 7.x. The [PHP cURL extension](http://php.net/manual/en/book.curl.php) needs to be installed.
The MyParcel SDK works with PHP version >= 5.6.5. The [PHP cURL extension](http://php.net/manual/en/book.curl.php) needs to be installed.
For support for PHP version 5.4 you can use release 1.x.

### 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://getcomposer.org/
Expand All @@ -45,17 +46,16 @@ You can download the zip on the project's [releases page](https://github.com/myp

## Quick start and examples
Add the following lines to your project to import the SDK classes for creating shipments.

```php
use MyParcelNL\Sdk\src\Helper\MyParcelCollection;
use MyParcelNL\Sdk\src\Model\Repository\MyParcelConsignmentRepository;
use MyParcelNL\Sdk\src\Model\Repository\MyParcelConsignment;
```

### Create a consignment
This example uses only the required methods to create a shipment and download its label.

```php
$consignment = (new MyParcelConsignmentRepository())
$consignment = (new MyParcelConsignment())
->setApiKey('api_key_from_MyParcel_backoffice')
->setReferenceId('Order 146')
->setCountry('NL')
Expand All @@ -82,9 +82,9 @@ $myParcelCollection = (new MyParcelCollection())
// Loop through your shipments, adding each to the same MyParcelCollection()
foreach ($yourShipments as $yourShipment) {

$consignment = (new MyParcelConsignmentRepository())
$consignment = (new MyParcelConsignment())
->setApiKey('api_key_from_MyParcel_backoffice')
->setReferenceId($yourShipment['reference_id']) // Note: Make sure every shipment gets a unique reference ID
->setReferenceId($yourShipment['reference_id'])
->setPerson($yourShipment['name'])
->setPostalCode($yourShipment['postal_code'])
->setFullStreet($yourShipment['full_street'])
Expand Down Expand Up @@ -150,9 +150,12 @@ Available options:
- return: Return the package to the sender when the recipient is not home.
- Set: `setReturn(true)`
- Get: `isReturn()`
- large_format: This option must be specified if the dimensions of the package are between 100 x 70 x 50 and 175 x 78 x 58 cm. If the scanned dimensions from the carrier indicate that this package is large format and it has not been specified then it will be added to the shipment in the billing process. This option is also available for EU shipments.
- large_format: This option must be specified if the dimensions of the package are between 100 x 70 x 50 and 175 x 78 x 58 cm. If the scanned dimensions from the carrier indicate that this package is large format and it has not been specified then it will be added to the shipment in the billing process. This option is also available for EU shipments.
- Set: `setLargeFormat(true)`
- Get: `isLargeFormat()`
- age_check: The Customer/Consumer must sign for the package and only receive it when he is at least 18 years.
- Set: `setAgeCheck(true)`
- Get: `hasAgeCheck()`
- insurance: This option allows a shipment to be insured up to certain amount. NL shipments can be insured for 5000,- euros. EU shipments must be insured for 500,- euros. Global shipments must be insured for 200,- euros. The following shipment options are mandatory when insuring an NL shipment: only_recipient and signature.
- Set: `setInsurance(250)` (amount in EUR)
- Get: `getInsurance()`
Expand All @@ -162,7 +165,7 @@ More information: https://myparcelnl.github.io/api/#6_A_3
### Retrieve data from a consignment
Most attributes that have a set...() method also have a get...() method to retrieve the data. View [all methods](#myparcelconsignment) for consignments here.
```php
$consignment = new MyParcelConsignmentRepository();
$consignment = new MyParcelConsignment();

echo $consignment->getFullStreet();
echo $consignment->getPerson();
Expand Down Expand Up @@ -207,11 +210,9 @@ This is a list of all the classes in this SDK and their available methods.
`MyParcelNL/Sdk/src/Model`

#### MyParcelConsignment
:warning: Access these methods through `\MyParcelNL\Sdk\src\Model\Repository\MyParcelConsignmentRepository` (which extends `MyParcelConsignment`).

```MyParcelNL/Sdk/src/Model/MyParcelConsignment.php```
```php
$consignment = (new \MyParcelNL\Sdk\src\Model\Repository\MyParcelConsignmentRepository())
$consignment = (new \MyParcelNL\Sdk\src\Model\Repository\MyParcelConsignment())
->setApiKey('api_key_from_MyParcel_backoffice')
->setReferenceId('Order 1203')

Expand All @@ -221,7 +222,7 @@ $consignment = (new \MyParcelNL\Sdk\src\Model\Repository\MyParcelConsignmentRepo
->setPhone('+31 612345678') // Phone number
->setCompany('Piet BV') // Company

->setFullStreet('Plein 1945 55b') // Street, number and suffix in one line
->setFullStreet('Plein 1945 55b') // Street, number and suffix in one line
// OR send the street data separately:
->setStreet('Plein 1945') / Street
->setNumber((string)55) // Number
Expand Down Expand Up @@ -267,6 +268,11 @@ $consignment = (new \MyParcelNL\Sdk\src\Model\Repository\MyParcelConsignmentRepo
->setContents()
->addItem();

// Convert pickup data from checkout
// You can use these if you use the following code in your checkout: https://github.com/myparcelnl/checkout
->setDeliveryDateFromCheckout()
->setPickupAddressFromCheckout()

// Get attributes from consignment
$consignment
->getApiKey()
Expand All @@ -289,9 +295,13 @@ $consignment
->getStreetAdditionalInfo()
->getNumber()
->getNumberSuffix()
->getFullStreet()
->getPostalCode()
->getCity()
->getCountry()
->isCdCountry()
->isCorrectAddress()
->isEuCountry()

// Package type
->getPackageType()
Expand All @@ -312,16 +322,16 @@ $consignment

// Delivery
->getDeliveryDate()
->getDeliveryRemark()
->getDeliveryType()

// Physical properties (digital stamps or non-EU shipments)
->getPhysicalProperties()

// Non-EU attributes
->getInvoice()
->getContents()
->getItems();
->getItems()
->getTotalWeight()
```

#### MyParcelCustomsItem
Expand All @@ -348,52 +358,12 @@ This object is embedded in the MyParcelConsignment object for global shipments a
->isFullyFilledItem()
```

#### MyParcelRequest
This model represents one request

```MyParcelNL/Sdk/src/Model/MyParcelRequest.php```
```php
->sendRequest()
->setRequestParameters()
->setUserAgent()

->getError()
->getResult()
->getUserAgent()
->getUserAgentFromComposer()
```

#### Repository\MyParcelConsignmentRepository
The repository of a MyParcel consignment.

```MyParcelNL/Sdk/src/Model/Repository/MyParcelConsignmentRepository.php```
```php
->setFullStreet('Street 23b, 1234 AB City')

->apiDecode()
->apiEncode()
->encodeReturnShipment()

// Convert pickup data from checkout
// You can use these if you use the following code in your checkout: https://github.com/myparcelnl/checkout
->setDeliveryDateFromCheckout()
->setPickupAddressFromCheckout()

->getDeliveryTypeFromCheckout()

->getFullStreet()
->getTotalWeight()

->isCdCountry()
->isCorrectAddress()
->isEuCountry()
```

### Helpers
```MyParcelNL/Sdk/src/Helper```

#### MyParcelCollection
Stores all data to communicate with the MyParcel API.
Stores all consignments to communicate with the MyParcel API.
MyParcelCollection also contains almost [all methods](https://laravel.com/docs/5.7/collections) from Laravel Collections. If you use Laravel it also extends \Illuminate\Support\Collection.

```MyParcelNL/Sdk/src/Helper/MyParcelCollection.php```
```php
Expand All @@ -402,19 +372,21 @@ Stores all data to communicate with the MyParcel API.
// Get consignments from the collection
->getConsignments()
->getConsignmentByApiId()
->getConsignmentByReferenceId()
->getConsignmentsByReferenceId()

->clearConsignmentsCollection() // Clear the collection

->createConcepts() // Create concept shipment in the MyParcel Backoffice
// Clear the collection
->clearConsignmentsCollection()

// Create or delete concept shipments in the MyParcel Backoffice
->createConcepts()
->deleteConcepts()

->getOneConsignment()
->getRequestBody()

->sendReturnLabelMails() // Send return label to customer. The customer can pay and download the label
->setLatestData() // Set id and run this function to update all the information about this shipment
->setLatestDataWithoutIds()
->setLatestDataWithoutIds() // Receive the last created shipments

->setLinkOfLabels()
->getLinkOfLabels()
Expand All @@ -425,32 +397,11 @@ Stores all data to communicate with the MyParcel API.

// To give us insight into which CMS system you're connecting 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.
// You must send the name of the CMS system (required) followed by a version number (optional).
->setUserAgent('name_of_cms', '1.0')
->getUserAgent()
```

#### MyParcelCurl
Curl to use in the MyParcel API.

```MyParcelNL/Sdk/src/Helper/MyParcelCurl.php```
```php
->addOption()
->addOptions()
->close()
->connect()
->getErrno()
->getError()
->getInfo()
->multiRequest()
->read()
->setConfig()
->setOptions()
->setUserAgent()
->write()
```


## Contribute

1. Check for open issues or open a new issue to start a discussion around a bug or feature.
Expand Down
26 changes: 0 additions & 26 deletions Tests/GetConsignments/GetMultipleConsignments.php

This file was deleted.

4 changes: 2 additions & 2 deletions Tests/ReturnLabelTest/SendReturnLabelMailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private function getCollectionWithParentConsignment()
->setCountry($consignmentTest['cc'])
->setPerson($consignmentTest['person'])
->setCompany($consignmentTest['company'])
->setFullStreet($consignmentTest['full_street_test'])
->setFullStreet($consignmentTest['full_street_input'])
->setPostalCode($consignmentTest['postal_code'])
->setCity($consignmentTest['city'])
->setEmail($consignmentTest['email'])
Expand All @@ -77,7 +77,7 @@ private function additionProviderNewConsignment()
'person' => 'Piet',
'email' => '[email protected]',
'company' => 'Mega Store',
'full_street_test' => 'Koestraat 55',
'full_street_input' => 'Koestraat 55',
'number_suffix' => '',
'postal_code' => '2231JE',
'city' => 'Katwijk',
Expand Down
Loading

0 comments on commit 2844d55

Please sign in to comment.