From 1967db911f446ca3b47c54dd082745ed65066875 Mon Sep 17 00:00:00 2001 From: Cornelis21 <30620801+Cornelis21@users.noreply.github.com> Date: Tue, 1 Aug 2017 11:08:27 +0200 Subject: [PATCH 1/4] Update MyParcelCollection.php --- src/Helper/MyParcelCollection.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Helper/MyParcelCollection.php b/src/Helper/MyParcelCollection.php index 73c6cc74..943851f7 100644 --- a/src/Helper/MyParcelCollection.php +++ b/src/Helper/MyParcelCollection.php @@ -365,7 +365,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()'); @@ -373,7 +373,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'); @@ -551,4 +551,4 @@ private function getConsignmentsSortedByKey() return $aConsignments; } -} \ No newline at end of file +} From 3ec17a74d2bccbaf171abd262595c51f2e945e34 Mon Sep 17 00:00:00 2001 From: Cornelis21 <30620801+Cornelis21@users.noreply.github.com> Date: Tue, 1 Aug 2017 14:57:26 +0200 Subject: [PATCH 2/4] Added delete request type --- src/Model/MyParcelRequest.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Model/MyParcelRequest.php b/src/Model/MyParcelRequest.php index cc89db33..74eb0b73 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 @@ -142,6 +143,15 @@ public function sendRequest($method = 'POST', $uri = self::REQUEST_TYPE_SHIPMENT $request->setConfig($config) ->write('POST', $url, '1.1', $header, $body); + } else if ($method == 'DELETE') { + + //complete request url + if ($this->body) { + $url .= '/' . $this->body; + } + + $request->setConfig($config) + ->write('DELETE', $url, '1.1', $header); } else { //complete request url @@ -269,4 +279,4 @@ public function getUserAgentFromComposer() return null; } -} \ No newline at end of file +} From 1fd7d39bcd7f4e9397d13df9b0438177a7070e06 Mon Sep 17 00:00:00 2001 From: Cornelis21 <30620801+Cornelis21@users.noreply.github.com> Date: Tue, 1 Aug 2017 15:01:23 +0200 Subject: [PATCH 3/4] Added deleteConcepts() function --- src/Helper/MyParcelCollection.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Helper/MyParcelCollection.php b/src/Helper/MyParcelCollection.php index 943851f7..d28f268d 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(); + } + } + } + + return $this; + } /** * Get all current data From 94b6eb35fb3668bc3edae1005db89a616349f64b Mon Sep 17 00:00:00 2001 From: Cornelis21 <30620801+Cornelis21@users.noreply.github.com> Date: Tue, 1 Aug 2017 15:02:38 +0200 Subject: [PATCH 4/4] Forgot 'DELETE' method --- src/Helper/MyParcelCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Helper/MyParcelCollection.php b/src/Helper/MyParcelCollection.php index d28f268d..e3a99e90 100644 --- a/src/Helper/MyParcelCollection.php +++ b/src/Helper/MyParcelCollection.php @@ -259,7 +259,7 @@ public function deleteConcepts() $consignment->getMyParcelConsignmentId(), MyParcelRequest::REQUEST_HEADER_DELETE ) - ->sendRequest(); + ->sendRequest('DELETE'); } } }