Skip to content

Commit f2d3146

Browse files
author
Sander de Vos
committed
Parcel data object
1 parent bb73177 commit f2d3146

File tree

5 files changed

+68
-5
lines changed

5 files changed

+68
-5
lines changed

src/Contracts/SendcloudContract.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace Soved\Laravel\Sendcloud\Contracts;
44

5-
use Soved\Laravel\Sendcloud\Data\RecipientData;
5+
use Soved\Laravel\Sendcloud\Data\ParcelData;
6+
use Soved\Laravel\Sendcloud\Data\SenderData;
67

78
interface SendcloudContract
89
{
@@ -15,7 +16,7 @@ public function getParcels(array $optionalParameters = []): array;
1516

1617
public function getParcel(int $id): array;
1718

18-
public function createParcel(RecipientData $recipient, array $optionalParameters = []): array;
19+
public function createParcel(ParcelData $parcel, SenderData $sender = null): array;
1920

2021
public function shippingMethods(array $optionalParameters = []): array;
2122
}

src/Data/ParcelData.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Soved\Laravel\Sendcloud\Data;
4+
5+
class ParcelData extends RecipientData
6+
{
7+
public int $sender_address;
8+
public string $customs_invoice_nr;
9+
public int $customs_shipment_type;
10+
public string $external_reference;
11+
public int $quantity;
12+
public int $to_service_point;
13+
public int $insured_value;
14+
public int $total_insured_value;
15+
public string $order_number;
16+
public string $shipment_uuid;
17+
public array $parcel_items;
18+
public string $weight;
19+
public bool $is_return;
20+
public string $total_order_value;
21+
public bool $request_label;
22+
public bool $request_label_async;
23+
public ShipmentData $shipment;
24+
public bool $apply_shipping_rules;
25+
}

src/Data/RecipientData.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
class RecipientData extends Data
66
{
77
public string $name;
8+
public string $company_name;
89
public string $address;
10+
public string $address_2;
911
public string $house_number;
1012
public string $city;
1113
public string $postal_code;
14+
public string $to_post_number;
1215
public string $country;
16+
public string $country_state;
17+
public int $telephone;
18+
public string $email;
1319

1420
public array $required = [
1521
'name',

src/Data/SenderData.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Soved\Laravel\Sendcloud\Data;
4+
5+
class SenderData extends Data
6+
{
7+
public string $from_name;
8+
public string $from_company_name;
9+
public string $from_address_1;
10+
public string $from_address_2;
11+
public string $from_house_number;
12+
public string $from_city;
13+
public string $from_postal_code;
14+
public string $from_country;
15+
public int $from_telephone;
16+
public string $from_email;
17+
18+
public array $required = [
19+
'from_name',
20+
'from_address_1',
21+
'from_house_number',
22+
'from_city',
23+
'from_postal_code',
24+
'from_country',
25+
];
26+
}

src/Sendcloud.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
namespace Soved\Laravel\Sendcloud;
44

55
use Illuminate\Support\Facades\Http;
6-
use Soved\Laravel\Sendcloud\Data\RecipientData;
6+
use Soved\Laravel\Sendcloud\Data\ParcelData;
7+
use Soved\Laravel\Sendcloud\Data\SenderData;
78
use Soved\Laravel\Sendcloud\Contracts\SendcloudContract;
89

910
class Sendcloud implements SendcloudContract
@@ -24,9 +25,13 @@ public function getParcel(int $id): array
2425
return $this->request('get', $endpoint);
2526
}
2627

27-
public function createParcel(RecipientData $recipient, array $optionalParameters = []): array
28+
public function createParcel(ParcelData $parcel, SenderData $sender = null): array
2829
{
29-
$data = ['parcel' => $recipient->toArray() + $optionalParameters];
30+
$data = ['parcel' => $parcel->toArray()];
31+
32+
if (! is_null($sender)) {
33+
$data['parcel'] += $sender->toArray();
34+
}
3035

3136
return $this->request('post', self::PARCELS_ENDPOINT, $data);
3237
}

0 commit comments

Comments
 (0)