mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2024-11-14 12:07:15 +01:00
Merge pull request #131 from exciler/sendcloud_errors
Improve Sendcloud error handling, prevent multiple form submission
This commit is contained in:
commit
520fab99db
@ -8,6 +8,9 @@
|
||||
|
||||
namespace Xentral\Carrier\SendCloud\Data;
|
||||
|
||||
/**
|
||||
* Documents object for a parcel
|
||||
*/
|
||||
class Document
|
||||
{
|
||||
public const TYPE_LABEL = 'label';
|
||||
|
13
classes/Carrier/SendCloud/Data/Label.php
Normal file
13
classes/Carrier/SendCloud/Data/Label.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\SendCloud\Data;
|
||||
|
||||
/**
|
||||
* Label object for a parcel
|
||||
*/
|
||||
class Label
|
||||
{
|
||||
public string $labelPrinter;
|
||||
/** @var string[] $normalPrinter */
|
||||
public array $normalPrinter;
|
||||
}
|
@ -8,6 +8,9 @@
|
||||
|
||||
namespace Xentral\Carrier\SendCloud\Data;
|
||||
|
||||
/**
|
||||
* Error returned during parcel creation
|
||||
*/
|
||||
class ParcelCreationError
|
||||
{
|
||||
public int $Code;
|
||||
|
12
classes/Carrier/SendCloud/Data/Shipment.php
Normal file
12
classes/Carrier/SendCloud/Data/Shipment.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\SendCloud\Data;
|
||||
|
||||
/**
|
||||
* Shipping method object for a parcel
|
||||
*/
|
||||
class Shipment
|
||||
{
|
||||
public int $id;
|
||||
public int $name;
|
||||
}
|
12
classes/Carrier/SendCloud/Data/Status.php
Normal file
12
classes/Carrier/SendCloud/Data/Status.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Carrier\SendCloud\Data;
|
||||
|
||||
/**
|
||||
* Status object for a parcel
|
||||
*/
|
||||
class Status
|
||||
{
|
||||
public int $id;
|
||||
public string $message;
|
||||
}
|
@ -79,7 +79,7 @@ class SendCloudApi
|
||||
*/
|
||||
public function CreateParcel(ParcelCreation $parcel): ParcelResponse|string|null
|
||||
{
|
||||
$uri = self::PROD_BASE_URI . '/parcels';
|
||||
$uri = self::PROD_BASE_URI . '/parcels?errors=verbose-carrier';
|
||||
$response = $this->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);
|
||||
|
@ -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
|
||||
];
|
||||
|
@ -229,7 +229,7 @@ SPDX-License-Identifier: LicenseRef-EGPL-3.1
|
||||
</table>
|
||||
</div>
|
||||
<div>
|
||||
<input class="btnGreen" type="submit" value="{|Paketmarke drucken|}" name="drucken">
|
||||
<input class="btnGreen" type="submit" value="{|Paketmarke drucken|}" name="drucken" :disabled="submitting">
|
||||
<!--<input type="button" value="{|Andere Versandart auswählen|}" name="anders"> -->
|
||||
</div>
|
||||
</div>
|
||||
@ -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)));
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user