From 59c567aa00be96d9da08d5eeb905ce0c449dca15 Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Wed, 27 Mar 2024 00:14:39 +0100 Subject: [PATCH] Improve Sendcloud error handling, prevent multiple form submission --- classes/Carrier/SendCloud/Data/Document.php | 3 +++ classes/Carrier/SendCloud/Data/Label.php | 13 +++++++++++++ .../Carrier/SendCloud/Data/ParcelCreationError.php | 3 +++ classes/Carrier/SendCloud/Data/Shipment.php | 12 ++++++++++++ classes/Carrier/SendCloud/Data/Status.php | 12 ++++++++++++ classes/Carrier/SendCloud/SendCloudApi.php | 6 +++--- www/lib/class.versanddienstleister.php | 1 + www/lib/versandarten/content/createshipment.tpl | 4 +++- 8 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 classes/Carrier/SendCloud/Data/Label.php create mode 100644 classes/Carrier/SendCloud/Data/Shipment.php create mode 100644 classes/Carrier/SendCloud/Data/Status.php diff --git a/classes/Carrier/SendCloud/Data/Document.php b/classes/Carrier/SendCloud/Data/Document.php index 023b6176..12f773d1 100644 --- a/classes/Carrier/SendCloud/Data/Document.php +++ b/classes/Carrier/SendCloud/Data/Document.php @@ -8,6 +8,9 @@ namespace Xentral\Carrier\SendCloud\Data; +/** + * Documents object for a parcel + */ class Document { public const TYPE_LABEL = 'label'; diff --git a/classes/Carrier/SendCloud/Data/Label.php b/classes/Carrier/SendCloud/Data/Label.php new file mode 100644 index 00000000..7ca90bfb --- /dev/null +++ b/classes/Carrier/SendCloud/Data/Label.php @@ -0,0 +1,13 @@ +sendRequest($uri, null, true, ['parcel' => $parcel->toApiRequest()], [200,400]); switch ($response['code']) { case 200: @@ -91,8 +91,8 @@ class SendCloudApi } break; case 400: - if (isset($response->error)) - return $response->error->message; + if (isset($response['body']->error)) + return $response['body']->error->message; break; } throw SendcloudApiException::fromResponse($response); diff --git a/www/lib/class.versanddienstleister.php b/www/lib/class.versanddienstleister.php index 79491d41..28db5bd2 100644 --- a/www/lib/class.versanddienstleister.php +++ b/www/lib/class.versanddienstleister.php @@ -469,6 +469,7 @@ abstract class Versanddienstleister CustomsInfo::CUSTOMS_TYPE_RETURN => 'Rücksendung' ]; $json['messages'] = []; + $json['submitting'] = false; $json['form']['services'] = [ Product::SERVICE_PREMIUM => false ]; diff --git a/www/lib/versandarten/content/createshipment.tpl b/www/lib/versandarten/content/createshipment.tpl index e9d9f97d..d524c75f 100644 --- a/www/lib/versandarten/content/createshipment.tpl +++ b/www/lib/versandarten/content/createshipment.tpl @@ -229,7 +229,7 @@ SPDX-License-Identifier: LicenseRef-EGPL-3.1
-   +  
@@ -261,12 +261,14 @@ SPDX-License-Identifier: LicenseRef-EGPL-3.1 methods: { submit: function () { let app = this; + app.submitting = true; let xhr = new XMLHttpRequest(); xhr.open('POST', location.href, true); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.onload = function () { let json = JSON.parse(this.response); app.messages = json.messages; + app.submitting = false; } xhr.send(JSON.stringify($.extend({submit:'print'}, this.form))); },