Skip to content
Open
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
17 changes: 15 additions & 2 deletions src/Resources/Parcel.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,24 @@ public function signature(): self
return $this;
}

/**
* Set the amount for "Insured" in EUR.
*
* @param int|float $value
* @return $this
*/
public function setInsured($value): self
{
$this->options->setInsured($value);

return $this;
}

/**
* Set the shipment options for this parcel.
*
* @param \Mvdnbrk\DhlParcel\Resources\ShipmentOptions|array $value
* @return void
* @return void
*/
public function setOptionsAttribute($value): void
{
Expand Down Expand Up @@ -115,7 +128,7 @@ public function servicePoint(string $value): self
* Set the amount for "Cash On Delivery" in EUR.
*
* @param int|float $value
* @return $this
* @return $this
*/
public function cashOnDelivery($value): self
{
Expand Down
20 changes: 20 additions & 0 deletions src/Resources/ShipmentOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class ShipmentOptions extends BaseResource
/** @var bool */
public $signature;

/** @var int|float */
protected $insured;

public function __construct(array $attributes = [])
{
$this->setDefaultOptions();
Expand Down Expand Up @@ -90,6 +93,17 @@ public function setCashOnDelivery($value): void
$this->cash_on_delivery = $value;
}

/**
* Set the amount for the option "INS" in EUR.
*
* @param int|float $value
* @return void
*/
public function setInsured($value): void
{
$this->insured = $value;
}

public function toArray(): array
{
return collect()
Expand Down Expand Up @@ -136,6 +150,12 @@ public function toArray(): array
'key' => 'EVE',
]);
})
->when($this->insured, function ($collection) {
return $collection->push([
'key' => 'INS',
'input' => $this->insured,
]);
})
->all();
}
}
22 changes: 22 additions & 0 deletions tests/Unit/Resources/ShipmentOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,26 @@ public function to_array_with_cash_on_delivery()
],
], $array);
}

/** @test */
public function to_array_with_insured()
{
$options = new ShipmentOptions([
'insured' => 150,
]);

$array = $options->toArray();

$this->assertIsArray($array);

$this->assertEquals([
[
'key' => 'DOOR',
],
[
'key' => 'INS',
'input' => 150,
],
], $array);
}
}