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

[WIZ-42] Add MondialRelay support #360

Merged
merged 16 commits into from
Nov 19, 2018
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

### New features

- Added `Wizaplace\SDK\Basket\BasketService::setMondialRelayPickupPoint`
- Added `Wizaplace\SDK\Shipping\MondialRelayService` and its associated classes
- Added `Wizaplace\SDK\Vendor\Order\OrderService::generateMondialRelayLabel`
- Added `\Wizaplace\SDK\Order\OrganisationOrderService::getOrder`
- Added attribute `hidden` to `\Wizaplace\SDK\Organisation\OrganisationBasket`

Expand Down Expand Up @@ -68,7 +71,7 @@ Compatible with Wizaplace 1.27.0
### New features

- Added optional parameters `$billing` and `$shipping` to `\Wizaplace\SDK\User\UserService::register`
- Added `\Wizaplace\SDK\Order\Order::getCompanyName`
- Added `\Wizaplace\SDK\Order\Order::getCompanyName`
youbs marked this conversation as resolved.
Show resolved Hide resolved

### Corrections

Expand Down
28 changes: 27 additions & 1 deletion src/Basket/BasketService.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,16 @@ public function mergeBaskets(string $targetBasketId, string $sourceBasketId)
}

/**
* Sets a pickup point as the basket's shipping destination.
* Sets a pickup point as the basket's shipping destination for a
* Chrono Relais shipping type.
*
* @param SetPickupPointCommand $command
* @throws SomeParametersAreInvalid
*/
public function setPickupPoint(SetPickupPointCommand $command): void
{
$command->validate();

$this->client->post('basket/'.$command->getBasketId().'/chronorelais-pickup-point', [
RequestOptions::JSON => [
'pickupPointId' => $command->getPickupPointId(),
Expand All @@ -441,6 +443,30 @@ public function setPickupPoint(SetPickupPointCommand $command): void
]);
}

/**
* Sets a pickup point as the basket's shipping destination for a
* Mondial Relay shipping type.
*
* @param SetPickupPointCommand $command
*
* @return array The full address
*
* @throws SomeParametersAreInvalid
*/
public function setMondialRelayPickupPoint(SetPickupPointCommand $command): array
{
$command->validate();

return $this->client->post(sprintf('basket/%s/mondialrelay-pickup-point', $command->getBasketId()), [
RequestOptions::JSON => [
'pickupPointId' => $command->getPickupPointId(),
'title' => $command->getTitle()->getValue(),
'firstName' => $command->getFirstName(),
'lastName' => $command->getLastName(),
],
]);
}

private static function serializeComment(Comment $comment): array
{
return $comment->toArray();
Expand Down
16 changes: 16 additions & 0 deletions src/Order/ShippingAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,20 @@

final class ShippingAddress extends Address
{
/** @var string|null */
private $pickupPointId;

/**
* @internal
*/
public function __construct(array $data)
{
parent::__construct($data);
$this->pickupPointId = $data['pickupPointId'];
}

public function getPickupPointId(): ?string
{
return $this->pickupPointId;
}
}
31 changes: 31 additions & 0 deletions src/Shipping/MondialRelayBrandCode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* @copyright Copyright (c) Wizacha
* @license Proprietary
*/
declare(strict_types = 1);

namespace Wizaplace\SDK\Shipping;

class MondialRelayBrandCode
{
/**
* @var string
*/
private $value;

public function __construct(string $value)
{
$this->value = $value;
}

public function getValue(): string
{
return $this->value;
}

public function __toString()
{
return $this->value;
}
}
37 changes: 37 additions & 0 deletions src/Shipping/MondialRelayLabel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* @copyright Copyright (c) Wizacha
* @license Proprietary
*/
declare(strict_types = 1);

namespace Wizaplace\SDK\Shipping;

class MondialRelayLabel
{
/**
* @var string
*/
private $trackingNumber;

/**
* @var string
*/
private $labelUrl;

public function __construct(array $data)
{
$this->trackingNumber = $data['tracking_number'];
$this->labelUrl = $data['label_url'];
}

public function getTrackingNumber(): string
{
return $this->trackingNumber;
}

public function getLabelUrl(): string
{
return $this->labelUrl;
}
}
84 changes: 84 additions & 0 deletions src/Shipping/MondialRelayOpening.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* @author Wizacha DevTeam <dev@wizacha.com>
* @copyright Copyright (c) Wizacha
* @license Proprietary
*/
declare(strict_types = 1);

namespace Wizaplace\SDK\Shipping;

use function theodorejb\polycast\to_int;

class MondialRelayOpening
{
/**
* Day of the week. 0 = Monday
*
* @var int
*/
private $day;

/**
* The hour at which the relay point opens for the 1st time interval of the day.
* Ex: 0930
*
* @var string
*/
private $openingHour1; // phpcs:ignore

/**
* The hour at which the relay point closes for the 1st time interval of the day.
*
* @var string
*/
private $openingHour2; // phpcs:ignore

/**
* The hour at which the relay point opens for the 2nd time interval of the day.
*
* @var string
*/
private $openingHour3; // phpcs:ignore

/**
* The hour at which the relay point closes for the 2nd time interval of the day.
*
* @var string
*/
private $openingHour4; // phpcs:ignore

public function __construct(array $data)
{
$this->day = to_int($data['day']);
$this->openingHour1 = $data['openingHour1'];
$this->openingHour2 = $data['openingHour2'];
$this->openingHour3 = $data['openingHour3'];
$this->openingHour4 = $data['openingHour4'];
}

public function getDay(): int
{
return $this->day;
}

public function getOpeningHour1(): string
{
return $this->openingHour1;
}

public function getOpeningHour2(): string
{
return $this->openingHour2;
}

public function getOpeningHour3(): string
{
return $this->openingHour3;
}

public function getOpeningHour4(): string
{
return $this->openingHour4;
}
}
Loading