Skip to content

Commit

Permalink
Update to v1.5.0
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
EdieLemoine authored Nov 8, 2018
2 parents 765a7e9 + 7adbed4 commit c3e6056
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 19 deletions.
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ Note: If you still make the request with additional options, bear in mind that y
This package type is available for NL, EU and global shipments. The label for this shipment is unpaid meaning that you will need to pay the postal office/courier to send this letter/package. Therefore, it does not support additional options.

#### 4: Digital stamp
This package type is only available for NL shipments and does not support any additional options. Its price is calculated using the package weight.
This package type is only available for NL shipments and does not support any additional options. Its price is calculated using the package weight, which is set using `setPhysicalProperties()`.

```php
->setPackageType(4)
->setPhysicalProperties(['weight' => 300]); // weight in grams (required)
```

> Note: This shipment will appear on your invoice on shipment_status 2 (pending - registered) instead of all other shipment types, which don't appear until shipment status 3. Read more: https://myparcelnl.github.io/api/#6_A_1
Expand Down Expand Up @@ -204,20 +209,21 @@ $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
->setNumberSuffix('b') // Suffix
->setStreet('Plein 1945') / Street
->setNumber((string)55) // Number
->setNumberSuffix('b') // Suffix

->setCity('Amsterdam') // City
->setPostalCode('2231JE') // Postal code
->setCountry('NL') // Country
->setCity('Amsterdam') // City
->setPostalCode('2231JE') // Postal code
->setCountry('NL') // Country

// Available package types:
// 1: Package (default)
// 2: Mailbox package
// 3: Letter
// 4: Digital stamp
->setPackageType(1)

// Options (https://myparcelnl.github.io/api/#6_A_3)
Expand All @@ -240,7 +246,10 @@ $consignment = (new \MyParcelNL\Sdk\src\Model\Repository\MyParcelConsignmentRepo
->setPickupNumber('32')
->setPickupPostalCode('1234 AB')
->setPickupCity('Hoofddorp')


// Physical properties
->setPhysicalProperties(['weight' => 73]) // Array with physical properties of the shipment. Currently only used to set the weight in grams for digital stamps (which is required)

// Non-EU shipment attributes: see https://myparcelnl.github.io/api/#7_E
->setInvoice()
->setContents()
Expand Down Expand Up @@ -294,6 +303,9 @@ $consignment
->getDeliveryRemark()
->getDeliveryType()

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

// Non-EU attributes
->getInvoice()
->getContents()
Expand All @@ -311,7 +323,7 @@ This object is embedded in the MyParcelConsignment object for global shipments a
->setClassification(0111) // Example: 0111 = "Growing of cereals (except rice), leguminous crops and oil seeds"
->setCountry('NL') // Country of origin
->setDescription('Cereal grains')
->setItemValue({"amount": 200, "currency": "EUR"}) // Must be array with amount and currency like in the example
->setItemValue(["amount" => 200, "currency" => "EUR"]) // Must be array with amount and currency like in the example
->setWeight() // The total weight for these items in whole grams. Between 0 and 20000 grams.

->getAmount()
Expand Down
133 changes: 133 additions & 0 deletions Tests/SendConsignments/SendDigitalStampTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php

use MyParcelNL\sdk\Concerns\HasCustomItems;
use MyParcelNL\Sdk\src\Helper\MyParcelCollection;
use MyParcelNL\Sdk\src\Model\Repository\MyParcelConsignmentRepository;


/**
* Class SendDigitalStampTest
* @package MyParcelNL\Sdk\tests\SendDigitalStampTest
*/
class SendDigitalStampTest extends \PHPUnit_Framework_TestCase
{
use HasCustomItems;

/**
* Test one shipment with createConcepts()
* @throws \Exception
*/
public function testSendOneConsignment()
{
error_reporting(E_ALL);
ini_set('display_errors', 1);
if (getenv('API_KEY') == null) {
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31. PhpStorm example: http://take.ms/sgpgU5\n\033[0m";
return $this;
}

foreach ($this->additionProvider() as $consignmentTest) {

$myParcelCollection = new MyParcelCollection();

$consignment = (new MyParcelConsignmentRepository())
->setApiKey($consignmentTest['api_key'])
->setPackageType(4)
->setCountry($consignmentTest['cc'])
->setPerson($consignmentTest['person'])
->setCompany($consignmentTest['company'])
->setFullStreet($consignmentTest['full_street'])
->setPostalCode($consignmentTest['postal_code'])
->setCity($consignmentTest['city'])
->setEmail('your_email@test.nl')
->setPhone($consignmentTest['phone'])
->setPhysicalProperties($consignmentTest['physical_properties']);

if (key_exists('package_type', $consignmentTest)) {
$consignment->setPackageType($consignmentTest['package_type']);
}

if (key_exists('label_description', $consignmentTest)) {
$consignment->setLabelDescription($consignmentTest['label_description']);
}

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

$this->assertEquals(true, preg_match("#^https://api.myparcel.nl/pdfs#", $myParcelCollection->getLinkOfLabels()), 'Can\'t get link of PDF');

echo "\033[32mGenerated digital stamp shipment: \033[0m";
print_r($myParcelCollection->getLinkOfLabels());
echo "\n\033[0m";
}
}

/**
* Data for the test
*
* @return array
*/
public function additionProvider()
{
return [
[
'api_key' => getenv('API_KEY'),
'cc' => 'NL',
'person' => 'Reindert',
'company' => 'Big Sale BV',
'full_street_test' => 'Plein 1940-45 3b',
'full_street' => 'Plein 1940-45 3 b',
'street' => 'Plein 1940-45',
'number' => 3,
'number_suffix' => 'b',
'postal_code' => '2231JE',
'city' => 'Rijnsburg',
'phone' => '123456',
'package_type' => 4,
'label_description' => 112345,
'physical_properties' => [
'weight' => 76
]
],
[
'api_key' => getenv('API_KEY'),
'cc' => 'NL',
'person' => 'Reindert',
'company' => 'Big Sale BV',
'full_street_test' => 'Plein 1940-45 3b',
'full_street' => 'Plein 1940-45 3 b',
'street' => 'Plein 1940-45',
'number' => 3,
'number_suffix' => 'b',
'postal_code' => '2231JE',
'city' => 'Rijnsburg',
'phone' => '123456',
'package_type' => 4,
'label_description' => 112345,
'physical_properties' => [
'weight' => 1999
]
],
[
'api_key' => getenv('API_KEY'),
'cc' => 'NL',
'person' => 'Reindert',
'company' => 'Big Sale BV',
'full_street_test' => 'Plein 1940-45 3b',
'full_street' => 'Plein 1940-45 3 b',
'street' => 'Plein 1940-45',
'number' => 3,
'number_suffix' => 'b',
'postal_code' => '2231JE',
'city' => 'Rijnsburg',
'phone' => '123456',
'package_type' => 4,
'label_description' => 112345,
'physical_properties' => [
'weight' => 0
]
],
];
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "myparcelnl/sdk",
"version": "v1.4.1",
"version": "v1.5.0",
"description": "This package is designed to send and receive data from MyParcel by means of an API.",
"homepage": "https://www.myparcel.nl",
"tags": ["MyParcel", "My Parcel", "Post NL", "PostNL"],
Expand Down
1 change: 0 additions & 1 deletion src/Helper/MyParcelCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ public function createConcepts()
->sendRequest();

$consignment->setMyParcelConsignmentId($request->getResult()['data']['ids'][0]['id']);

}
}
}
Expand Down
30 changes: 27 additions & 3 deletions src/Model/MyParcelConsignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ class MyParcelConsignment
*/
private $insurance = 0;

/**
* @var array
*/
private $physical_properties = [];

/**
* @var int
*/
Expand Down Expand Up @@ -1007,6 +1012,28 @@ public function setInsurance($insurance)
return $this;
}

/**
* Required: Yes for non-EU shipments and digital stamps
*
* @param array $physical_properties
*
* @return MyParcelConsignment
*/
public function setPhysicalProperties($physical_properties)
{
$this->physical_properties = $physical_properties;

return $this;
}

/**
* @return array
*/
public function getPhysicalProperties()
{
return $this->physical_properties;
}

/**
* @return integer
*/
Expand Down Expand Up @@ -1090,9 +1117,6 @@ public function addItem($item)
return $this;
}




/**
* @return string
*/
Expand Down
20 changes: 16 additions & 4 deletions src/Model/Repository/MyParcelConsignmentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class MyParcelConsignmentRepository extends MyParcelConsignment
const DEFAULT_DELIVERY_TYPE = self::DELIVERY_TYPE_STANDARD;

const PACKAGE_TYPE_NORMAL = 1;
const PACKAGE_TYPE_DIGITAL_STAMP = 4;

const DEFAULT_PACKAGE_TYPE = self::PACKAGE_TYPE_NORMAL;

Expand Down Expand Up @@ -515,7 +516,8 @@ private function encodeExtraOptions() {
);
$this
->encodePickup()
->encodeInsurance();
->encodeInsurance()
->encodePhysicalProperties();
}

if ($this->isEuCountry()) {
Expand Down Expand Up @@ -569,6 +571,18 @@ private function encodeInsurance()
return $this;
}

private function encodePhysicalProperties()
{
if (empty($this->getPhysicalProperties()) && $this->getPackageType() != self::PACKAGE_TYPE_DIGITAL_STAMP) {
return $this;
}
if ($this->getPackageType() == self::PACKAGE_TYPE_DIGITAL_STAMP && !isset($this->getPhysicalProperties()['weight'])) {
throw new \Exception('Weight in physical properties must be set for digital stamp shipments.');
}

$this->consignmentEncoded['physical_properties'] = $this->getPhysicalProperties();
}

/**
* @return $this
* @throws \Exception
Expand Down Expand Up @@ -604,9 +618,7 @@ private function encodeCdCountry()
'items' => $items,
'invoice' => $this->getLabelDescription(),
],
'physical_properties' => [
'weight' => $this->getTotalWeight()
]
'physical_properties' => $this->getPhysicalProperties() + ['weight' => $this->getTotalWeight()],
]
);

Expand Down

0 comments on commit c3e6056

Please sign in to comment.