Skip to content

Commit

Permalink
Add from/return address to request shipment data
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxxMD committed Mar 23, 2021
1 parent bfad021 commit 94c6f20
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
42 changes: 42 additions & 0 deletions src/Models/Request/Base/BaseShipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ abstract class BaseShipment implements ShipmentContract {
*/
protected $toAddress;

/**
* @var BaseAddress
*/
protected $fromAddress;

/**
* @var BaseAddress
*/
protected $returnAddress;

/**
* @var BasePackaging
*/
Expand Down Expand Up @@ -101,6 +111,38 @@ public function setToAddress($toAddress)
$this->toAddress = $toAddress;
}

/**
* @return BaseAddress
*/
public function getFromAddress()
{
return $this->fromAddress;
}

/**
* @param $fromAddress
*/
public function setFromAddress($fromAddress)
{
$this->fromAddress = $fromAddress;
}

/**
* @return BaseAddress
*/
public function getReturnAddress()
{
return $this->returnAddress;
}

/**
* @param $returnAddress
*/
public function setReturnAddress($returnAddress)
{
$this->toAddress = $returnAddress;
}

/**
* @return BasePackaging
*/
Expand Down
20 changes: 20 additions & 0 deletions src/Models/Request/Contracts/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ public function getToAddress();
*/
public function setToAddress($toAddress);

/**
* @return Address
*/
public function getFromAddress();

/**
* @param string $fromAddress
*/
public function setFromAddress($fromAddress);

/**
* @return Address
*/
public function getReturnAddress();

/**
* @param string $returnAddress
*/
public function setReturnAddress($returnAddress);

/**
* @return Packaging
*/
Expand Down
10 changes: 8 additions & 2 deletions src/Models/Request/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Fulfillment\Postage\Models\Traits\SimpleSerializable;
use Fulfillment\Postage\Models\Traits\ValidatableBase;
use Respect\Validation\Validator as v;
use Fulfillment\Postage\Models\Request\Contracts\Address;
use Fulfillment\Postage\Models\Request\Contracts\Packaging;

class Shipment extends BaseShipment implements Validatable {
use ValidatableBase;
Expand All @@ -19,6 +21,8 @@ public function __construct($data = null)
$this->weight = ArrayUtil::get($data['weight']);
$this->description = ArrayUtil::get($data['description'], 'E-Commerce Online Purchase');
$this->toAddress = ArrayUtil::get($data['toAddress']);
$this->returnAddress = ArrayUtil::get($data['returnAddress']);
$this->fromAddress = ArrayUtil::get($data['fromAddress']);
$this->packaging = ArrayUtil::get($data['packaging']);
$this->commodityItems = ArrayUtil::get($data['commodityItems']);
}
Expand All @@ -29,8 +33,10 @@ public function getValidationRules()
return [
v::attribute('weightType', v::stringType()),
v::attribute('weight', v::notEmpty()->numeric()),
v::attribute('toAddress', v::instance('\Fulfillment\Postage\Models\Request\Contracts\Address')->callback([$this->getToAddress(), 'validate'])),
v::attribute('packaging', v::oneOf(v::nullType()(), v::instance('Fulfillment\Models\Postage\Request\Contracts\Packaging'))),
v::attribute('toAddress', v::instance(Address::class)->callback([$this->getToAddress(), 'validate'])),
v::attribute('fromAddress', v::instance(Address::class)->callback([$this->getToAddress(), 'validate']), false),
v::attribute('returnAddress', v::instance(Address::class)->callback([$this->getToAddress(), 'validate']), false),
v::attribute('packaging', v::oneOf(v::nullType()(), v::instance(Packaging::class))),
v::attribute('commodityItems', v::arrayVal()),
];

Expand Down

0 comments on commit 94c6f20

Please sign in to comment.