diff --git a/composer.json b/composer.json index 8bfd7420..151b8c98 100755 --- a/composer.json +++ b/composer.json @@ -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"], diff --git a/src/Helper/MyParcelCollection.php b/src/Helper/MyParcelCollection.php index 662bb8f8..2e704779 100644 --- a/src/Helper/MyParcelCollection.php +++ b/src/Helper/MyParcelCollection.php @@ -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 @@ -368,7 +395,7 @@ 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()'); @@ -376,7 +403,7 @@ public function 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'); @@ -611,4 +638,4 @@ private function getConsignmentsSortedByKey() return $aConsignments; } -} \ No newline at end of file +} diff --git a/src/Model/MyParcelRequest.php b/src/Model/MyParcelRequest.php index c8cf0585..e23cf039 100644 --- a/src/Model/MyParcelRequest.php +++ b/src/Model/MyParcelRequest.php @@ -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 @@ -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 @@ -283,4 +292,4 @@ public function getUserAgentFromComposer() return null; } -} \ No newline at end of file +}