Skip to content

Commit 58bceae

Browse files
author
Sander de Vos
committed
Cancel parcels
1 parent f2d3146 commit 58bceae

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Supported endpoints:
66
- `GET` parcels
77
- `GET` parcels/{id}
88
- `POST` parcels
9+
- `POST` parcels/{id}/cancel
910
- `GET` shipping_methods
1011

1112
[![tests](https://github.com/sander3/laravel-sendcloud/workflows/Laravel/badge.svg)](https://github.com/sander3/laravel-sendcloud/actions?query=workflow%3ALaravel)

src/Sendcloud.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ public function createParcel(ParcelData $parcel, SenderData $sender = null): arr
3636
return $this->request('post', self::PARCELS_ENDPOINT, $data);
3737
}
3838

39+
public function deleteParcel(int $id): array
40+
{
41+
$endpoint = self::PARCELS_ENDPOINT.'/'.$id.'/cancel';
42+
43+
return $this->request('post', $endpoint, [], false);
44+
}
45+
3946
public function shippingMethods(array $optionalParameters = []): array
4047
{
4148
$query = http_build_query($optionalParameters);
@@ -45,13 +52,15 @@ public function shippingMethods(array $optionalParameters = []): array
4552
return $this->request('get', $endpoint);
4653
}
4754

48-
private function request(string $method, string $endpoint, array $data = null): array
55+
private function request(string $method, string $endpoint, array $data = [], bool $throwException = true): array
4956
{
5057
$response = Http::withBasicAuth(config('sendcloud.key'), config('sendcloud.secret'))
5158
->{$method}($this->getUrl($endpoint), $data);
5259

53-
// Throw an exception if a client or server error occurred...
54-
$response->throw();
60+
if ($throwException) {
61+
// Throw an exception if a client or server error occurred...
62+
$response->throw();
63+
}
5564

5665
return $response->json();
5766
}

0 commit comments

Comments
 (0)