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

Add shipping option for insurance #43

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bea87fd
Added insurance
avido Nov 18, 2020
76124d6
Set currency for insurance
avido Nov 18, 2020
0823fd2
Added unit test for insurance
avido Nov 18, 2020
29bed45
Updated readme
avido Nov 18, 2020
0854014
Merge branch 'main' into avido/feature-shipping-option-insurance
mvdnbrk Nov 18, 2020
83db9f0
Formatting
mvdnbrk Nov 18, 2020
aa460b3
Merge branch 'main' into avido/feature-shipping-option-insurance
mvdnbrk Nov 18, 2020
75434e3
Review changes
avido Nov 18, 2020
b013f05
Updated readme
avido Nov 18, 2020
12229b3
Merge branch 'main' into avido/feature-shipping-option-insurance
avido Nov 18, 2020
3b6a1c9
Merge branch 'avido/feature-shipping-option-insurance' of github.com:…
avido Nov 18, 2020
072cef8
Update insurance attribute argument to array, updated default options
avido Nov 18, 2020
b41f41a
Set insurance empty array, refactored toArray to remove empty arrays
avido Nov 18, 2020
acef318
Cast response to array
avido Nov 19, 2020
20702a4
Added test for retrieval of shipment with insurance
avido Nov 19, 2020
0aa3251
Updated readme
avido Nov 19, 2020
573e7ab
Formatting
mvdnbrk Nov 19, 2020
0d2740d
Change `reject` method
mvdnbrk Nov 19, 2020
a5f2b5c
Formatting
mvdnbrk Nov 19, 2020
477c12a
Formatting
mvdnbrk Nov 20, 2020
82513d3
Added money resource
avido Nov 23, 2020
fa3eeca
Updated insurance related tests
avido Nov 23, 2020
ef72358
Restred Shipments endpoint
avido Nov 23, 2020
1aac64e
Updated insurance for shippingOptions
avido Nov 23, 2020
fc56301
Updated method 'insurance' for parcel resource
avido Nov 23, 2020
563433c
Updated insurance attribute
avido Nov 23, 2020
06ed09c
Fix wrong type for insurance in defaultOptions
avido Nov 23, 2020
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
18 changes: 9 additions & 9 deletions src/Resources/Parcel.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ public function ageCheck(): self
return $this;
}

/**
* Set Insurance for parcel (only applicable for package_type 1)
* @param int $amount - in cents
* @param string $currency
* @return $this
*/
public function insurance(int $amount, string $currency = 'EUR'): self
public function insurance(int $cents, string $currency = 'EUR'): self
{
$this->options->setInsurance($amount, $currency);

$this->options->setInsuranceAttribute([
'amount' => $cents,
'currency' => $currency
]);
if ($this->recipient->cc === 'NL') {
mvdnbrk marked this conversation as resolved.
Show resolved Hide resolved
$this->onlyRecipient();
$this->signature();
}
return $this;
mvdnbrk marked this conversation as resolved.
Show resolved Hide resolved
mvdnbrk marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
23 changes: 9 additions & 14 deletions src/Resources/ShipmentOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class ShipmentOptions extends BaseResource
/** @var bool */
public $signature;

/** @var array|null */
public $insurance;
/** @var array */
public $insurance = [];

public function __construct(array $attributes = [])
{
Expand All @@ -50,6 +50,10 @@ public function setDefaultOptions(): self
$this->package_type = PackageType::PACKAGE;
$this->delivery_type = DeliveryType::STANDARD;
$this->only_recipient = false;
$this->insurance = [
'amount' => 0,
'currency' => 'EUR'
];

mvdnbrk marked this conversation as resolved.
Show resolved Hide resolved
return $this;
}
Expand All @@ -64,19 +68,10 @@ public function setDescriptionAttribute(string $value): void
$this->label_description = $value;
}

/**
* Set Insurance amount. Only applicable for package_type = 1 (package)
* @param int $value
* @param string $currency
* @return $this
*/
public function setInsurance(int $value, string $currency = 'EUR'): self
public function setInsuranceAttribute(array $insurance = []): self
mvdnbrk marked this conversation as resolved.
Show resolved Hide resolved
{
if ($this->package_type === 1) {
$this->insurance = [
'amount' => $value,
'currency' => $currency
];
if ($this->package_type === PackageType::PACKAGE) {
$this->insurance = $insurance;
}

return $this;
Expand Down