Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c760c91
commit 0378e2c
Showing
10 changed files
with
520 additions
and
315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
|
||
namespace LAShowroom\TaxJarBundle\Model; | ||
|
||
use Webmozart\Assert\Assert; | ||
|
||
class BaseRequest | ||
{ | ||
/** | ||
* @var Address | ||
*/ | ||
protected $fromAddress; | ||
|
||
/** | ||
* @var Address | ||
*/ | ||
protected $toAddress; | ||
|
||
/** | ||
* @var float | ||
*/ | ||
protected $amount; | ||
|
||
/** | ||
* @var float | ||
*/ | ||
protected $shipping; | ||
|
||
/** | ||
* @return Address | ||
*/ | ||
public function getFromAddress() | ||
{ | ||
return $this->fromAddress; | ||
} | ||
|
||
/** | ||
* @param Address $fromAddress | ||
*/ | ||
public function setFromAddress(Address $fromAddress) | ||
{ | ||
$this->fromAddress = $fromAddress; | ||
} | ||
|
||
/** | ||
* @return Address | ||
*/ | ||
public function getToAddress() | ||
{ | ||
return $this->toAddress; | ||
} | ||
|
||
/** | ||
* @param Address $toAddress | ||
*/ | ||
public function setToAddress(Address $toAddress) | ||
{ | ||
$this->toAddress = $toAddress; | ||
} | ||
|
||
/** | ||
* @return float | ||
*/ | ||
public function getAmount() | ||
{ | ||
return $this->amount; | ||
} | ||
|
||
/** | ||
* @param float $amount | ||
*/ | ||
public function setAmount($amount) | ||
{ | ||
Assert::float($amount); | ||
|
||
$this->amount = $amount; | ||
} | ||
|
||
/** | ||
* @return float | ||
*/ | ||
public function getShipping() | ||
{ | ||
return $this->shipping; | ||
} | ||
|
||
/** | ||
* @param float $shipping | ||
*/ | ||
public function setShipping($shipping) | ||
{ | ||
Assert::float($shipping); | ||
|
||
$this->shipping = $shipping; | ||
} | ||
|
||
protected function toArray() | ||
{ | ||
$result = []; | ||
|
||
if (!empty($this->fromAddress)) { | ||
$result = array_merge($result, $this->fromAddress->toArray('from_')); | ||
} | ||
|
||
if (!empty($this->toAddress)) { | ||
$result = array_merge($result, $this->toAddress->toArray('to_')); | ||
} | ||
|
||
$result = array_merge($result, [ | ||
'amount' => $this->getAmount(), | ||
'shipping' => $this->getShipping(), | ||
]); | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.