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;
|
namespace Xentral\Carrier\SendCloud\Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Documents object for a parcel
|
||||||
|
*/
|
||||||
class Document
|
class Document
|
||||||
{
|
{
|
||||||
public const TYPE_LABEL = 'label';
|
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;
|
namespace Xentral\Carrier\SendCloud\Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error returned during parcel creation
|
||||||
|
*/
|
||||||
class ParcelCreationError
|
class ParcelCreationError
|
||||||
{
|
{
|
||||||
public int $Code;
|
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
|
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]);
|
$response = $this->sendRequest($uri, null, true, ['parcel' => $parcel->toApiRequest()], [200,400]);
|
||||||
switch ($response['code']) {
|
switch ($response['code']) {
|
||||||
case 200:
|
case 200:
|
||||||
@ -91,8 +91,8 @@ class SendCloudApi
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 400:
|
case 400:
|
||||||
if (isset($response->error))
|
if (isset($response['body']->error))
|
||||||
return $response->error->message;
|
return $response['body']->error->message;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
throw SendcloudApiException::fromResponse($response);
|
throw SendcloudApiException::fromResponse($response);
|
||||||
|
@ -469,6 +469,7 @@ abstract class Versanddienstleister
|
|||||||
CustomsInfo::CUSTOMS_TYPE_RETURN => 'Rücksendung'
|
CustomsInfo::CUSTOMS_TYPE_RETURN => 'Rücksendung'
|
||||||
];
|
];
|
||||||
$json['messages'] = [];
|
$json['messages'] = [];
|
||||||
|
$json['submitting'] = false;
|
||||||
$json['form']['services'] = [
|
$json['form']['services'] = [
|
||||||
Product::SERVICE_PREMIUM => false
|
Product::SERVICE_PREMIUM => false
|
||||||
];
|
];
|
||||||
|
@ -229,7 +229,7 @@ SPDX-License-Identifier: LicenseRef-EGPL-3.1
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<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"> -->
|
<!--<input type="button" value="{|Andere Versandart auswählen|}" name="anders"> -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -261,12 +261,14 @@ SPDX-License-Identifier: LicenseRef-EGPL-3.1
|
|||||||
methods: {
|
methods: {
|
||||||
submit: function () {
|
submit: function () {
|
||||||
let app = this;
|
let app = this;
|
||||||
|
app.submitting = true;
|
||||||
let xhr = new XMLHttpRequest();
|
let xhr = new XMLHttpRequest();
|
||||||
xhr.open('POST', location.href, true);
|
xhr.open('POST', location.href, true);
|
||||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||||
xhr.onload = function () {
|
xhr.onload = function () {
|
||||||
let json = JSON.parse(this.response);
|
let json = JSON.parse(this.response);
|
||||||
app.messages = json.messages;
|
app.messages = json.messages;
|
||||||
|
app.submitting = false;
|
||||||
}
|
}
|
||||||
xhr.send(JSON.stringify($.extend({submit:'print'}, this.form)));
|
xhr.send(JSON.stringify($.extend({submit:'print'}, this.form)));
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user