@@ -12,8 +12,9 @@ class ParcelCreation extends ParcelBase
12
12
{
13
13
public ?int $ SenderAddressId = null ;
14
14
15
- public function toApiRequest (): array {
16
- return [
15
+ public function toApiRequest (): array
16
+ {
17
+ $ data = [
17
18
'name ' => $ this ->Name ,
18
19
'company_name ' => $ this ->CompanyName ,
19
20
'address ' => $ this ->Address ,
@@ -32,16 +33,19 @@ public function toApiRequest(): array {
32
33
'total_order_value ' => number_format ($ this ->TotalOrderValue , 2 , '. ' , null ),
33
34
'country_state ' => $ this ->CountryState ,
34
35
'sender_address ' => $ this ->SenderAddressId ,
35
- 'customs_invoice_nr ' => $ this ->CustomsInvoiceNr ,
36
- 'customs_shipment_type ' => $ this ->CustomsShipmentType ,
37
36
'external_reference ' => $ this ->ExternalReference ,
38
37
'total_insured_value ' => $ this ->TotalInsuredValue ?? 0 ,
39
- 'parcel_items ' => array_map (fn (ParcelItem $ item )=> $ item ->toApiRequest (), $ this ->ParcelItems ),
38
+ 'parcel_items ' => array_map (fn (ParcelItem $ item ) => $ item ->toApiRequest (), $ this ->ParcelItems ),
40
39
'is_return ' => $ this ->IsReturn ,
41
40
'length ' => $ this ->Length ,
42
41
'width ' => $ this ->Width ,
43
42
'height ' => $ this ->Height ,
44
43
];
45
- }
44
+ if ($ this ->CustomsInvoiceNr !== null )
45
+ $ data ['customs_invoice_nr ' ] = $ this ->CustomsInvoiceNr ;
46
+ if ($ this ->CustomsShipmentType !== null )
47
+ $ data ['customs_shipment_type ' ] = $ this ->CustomsShipmentType ;
46
48
49
+ return $ data ;
50
+ }
47
51
}
0 commit comments