Skip to content

Commit 53e7197

Browse files
committed
Added parcel->cancel() method
1 parent 651f85b commit 53e7197

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/Endpoints/AbstractEndpoint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected function restRead($id, array $filters): AbstractResource
9494
* @return AbstractResource|null
9595
* @throws ApiException
9696
*/
97-
protected function restDelete($id, array $body = []): AbstractResource
97+
protected function restDelete($id, array $body = []): ?AbstractResource
9898
{
9999
if (empty($id)) {
100100
throw new ApiException('Invalid resource id.');

src/Endpoints/ParcelEndpoint.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use Imbue\SendCloud\Exceptions\ApiException;
66
use Imbue\SendCloud\Resources\Collections\ParcelCollection;
7+
use Imbue\SendCloud\Resources\GenericStatus;
78
use Imbue\SendCloud\Resources\Parcel;
9+
use Imbue\SendCloud\Resources\ResourceFactory;
810

911
class ParcelEndpoint extends AbstractEndpoint
1012
{
@@ -59,4 +61,20 @@ public function create(array $data = [])
5961
{
6062
return $this->restCreate($data);
6163
}
64+
65+
/**
66+
* @param array $data
67+
* @return GenericStatus
68+
* @throws ApiException
69+
*/
70+
public function cancel(string $id)
71+
{
72+
$result = $this->client->performHttpCall(
73+
self::REST_CREATE,
74+
"{$this->getResourcePath()}/{$id}/cancel",
75+
$this->parseRequestBody([])
76+
);
77+
78+
return ResourceFactory::createFromApiResult($result, new GenericStatus($this->client));
79+
}
6280
}

src/Resources/GenericStatus.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Imbue\SendCloud\Resources;
4+
5+
class GenericStatus extends AbstractResource
6+
{
7+
/** @var string */
8+
public $status;
9+
/** @var string */
10+
public $message;
11+
}

0 commit comments

Comments
 (0)