Skip to content

Commit

Permalink
Merge pull request #32 from myparcelnl/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Reindert authored Oct 26, 2017
2 parents ed0fca9 + d700588 commit 7fc3e85
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
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.2.4",
"version": "v1.3.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
33 changes: 30 additions & 3 deletions src/Helper/MyParcelCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,33 @@ public function createConcepts()

return $this;
}

/**
* Delete concepts in MyParcel
*
* @return $this
* @throws \Exception
*/
public function deleteConcepts()
{
/* @var $consignments MyParcelConsignmentRepository[] */
foreach ($this->getConsignmentsSortedByKey() as $key => $consignments) {
foreach ($consignments as $consignment) {
if ($consignment->getMyParcelConsignmentId() !== null) {
$request = (new MyParcelRequest())
->setUserAgent($this->getUserAgent())
->setRequestParameters(
$key,
$consignment->getMyParcelConsignmentId(),
MyParcelRequest::REQUEST_HEADER_DELETE
)
->sendRequest('DELETE');
}
}
}

return $this;
}

/**
* Get all current data
Expand Down Expand Up @@ -368,15 +395,15 @@ public function setPdfOfLabels($positions = false)
* @return $this
* @throws \Exception
*/
public function downloadPdfOfLabels()
public function downloadPdfOfLabels($inline_download = false)
{
if ($this->label_pdf == null) {
throw new \Exception('First set label_pdf key with setPdfOfLabels() before running downloadPdfOfLabels()');
}

header('Content-Type: application/pdf');
header('Content-Length: ' . strlen($this->label_pdf));
header('Content-disposition: attachment; filename="' . self::PREFIX_PDF_FILENAME . gmdate('Y-M-d H-i-s') . '.pdf"');
header('Content-disposition: '.($inline_download === true ? "inline" : "attachment").'; filename="' . self::PREFIX_PDF_FILENAME . gmdate('Y-M-d H-i-s') . '.pdf"');
header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
Expand Down Expand Up @@ -611,4 +638,4 @@ private function getConsignmentsSortedByKey()

return $aConsignments;
}
}
}
11 changes: 10 additions & 1 deletion src/Model/MyParcelRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class MyParcelRequest
const REQUEST_HEADER_RETRIEVE_LABEL_LINK = 'Accept: application/json; charset=utf8';
const REQUEST_HEADER_RETRIEVE_LABEL_PDF = 'Accept: application/pdf';
const REQUEST_HEADER_RETURN = 'Content-Type: application/vnd.return_shipment+json; charset=utf-8';
const REQUEST_HEADER_DELETE = 'Accept: application/json; charset=utf8';

/**
* @var string
Expand Down Expand Up @@ -141,6 +142,14 @@ public function sendRequest($method = 'POST', $uri = self::REQUEST_TYPE_SHIPMENT
$body = $this->body;

$request->write('POST', $url, '1.1', $header, $body);
} else if ($method == 'DELETE') {

//complete request url
if ($this->body) {
$url .= '/' . $this->body;
}

$request->write('DELETE', $url, '1.1', $header);
} else {

//complete request url
Expand Down Expand Up @@ -283,4 +292,4 @@ public function getUserAgentFromComposer()

return null;
}
}
}

0 comments on commit 7fc3e85

Please sign in to comment.