Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/create parcel and label at the same time #17

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "jouwweb/sendcloud",
"name": "retrobak/sendcloud",
"description": "Provides a client to interact with the Sendcloud API in an object-oriented way.",
"keywords": [
"sendcloud",
Expand Down
55 changes: 55 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,61 @@ public function createParcel(
}
}

/**
* @param Address $shippingAddress
* @param int|null $servicePointId
* @param string|null $orderNumber
* @param int|null $weight
* @param string|null $customsInvoiceNumber
* @param int|null $customsShipmentType
* @param array|null $items
* @param string|null $postNumber
* @param ShippingMethod|int $shippingMethod
* @param SenderAddress|int|Address|null $senderAddress Passing null will pick Sendcloud's default. An Address will
* @return Parcel
* @throws SendCloudRequestException
*/
public function createParcelWithLabel(
Address $shippingAddress,
?int $servicePointId,
?string $orderNumber = null,
?int $weight = null,
?string $customsInvoiceNumber = null,
?int $customsShipmentType = null,
?array $items = null,
?string $postNumber = null,
$shippingMethod,
$senderAddress
)
{
$parcelData = $this->getParcelData(
null,
$shippingAddress,
$servicePointId,
$orderNumber,
$weight,
true,
$shippingMethod,
$senderAddress,
$customsInvoiceNumber,
$customsShipmentType,
$items,
$postNumber
);

try {
$response = $this->guzzleClient->post('parcels', [
'json' => [
'parcel' => $parcelData,
],
]);

return new Parcel(json_decode((string)$response->getBody(), true)['parcel']);
} catch (TransferException $exception) {
throw $this->parseGuzzleException($exception, 'Could not create parcel in Sendcloud.');
}
}

/**
* Update details of an existing parcel.
*
Expand Down