Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Rev\ReversalLib\Request\CreateReversal\Product;
- use Rev\ReversalLib\Exception\CreateReversal\Product\ProductRequestException;
- use Rev\ReversalLib\Request\RequestInterface;
- /**
- * Class AbstractProductRequest
- * @package Rev\ReversalLib\Request\CreateReversal\Product
- */
- abstract class AbstractProductRequest implements RequestInterface
- {
- //common fields mapping
- const SRN_STORAGE_ID = 'srn_storage_id';
- const SERIAL_NUMBER = 'serial_number';
- const SERVICE_SHEET = 'service_sheet';
- const IGNORE_REVERSAL = 'ignore_reversal';
- const REVERSED_PRICE = 'reversed_price';
- /** @var int */
- protected $productId;
- /** @var int */
- protected $srnStorageId;
- /** @var string */
- protected $serialNumber;
- /** @var int */
- protected $serviceSheet;
- /** @var float */
- protected $reversedPrice;
- /**
- * @return int
- */
- public function getProductId()
- {
- return $this->productId;
- }
- /**
- * @param int $productId
- * @return AbstractProductRequest
- */
- public function setProductId($productId)
- {
- $this->productId = (int)$productId;
- return $this;
- }
- /**
- * @return int
- */
- public function getSrnStorageId()
- {
- return $this->srnStorageId;
- }
- /**
- * @param int $srnStorageId
- * @return AbstractProductRequest
- */
- public function setSrnStorageId($srnStorageId)
- {
- $this->srnStorageId = (int)$srnStorageId;
- return $this;
- }
- /**
- * @return string
- */
- public function getSerialNumber()
- {
- return $this->serialNumber;
- }
- /**
- * @param string $serialNumber
- * @return AbstractProductRequest
- */
- public function setSerialNumber($serialNumber)
- {
- $this->serialNumber = $serialNumber;
- return $this;
- }
- /**
- * @return int
- */
- public function getServiceSheet()
- {
- return $this->serviceSheet;
- }
- /**
- * @param int $serviceSheet
- * @return AbstractProductRequest
- */
- public function setServiceSheet($serviceSheet)
- {
- $this->serviceSheet = (int)$serviceSheet;
- return $this;
- }
- /**
- * @return float
- */
- public function getReversedPrice()
- {
- return $this->reversedPrice;
- }
- /**
- * @param float $reversedPrice
- * @return AbstractProductRequest
- */
- public function setReversedPrice($reversedPrice)
- {
- $this->reversedPrice = (float)$reversedPrice;
- return $this;
- }
- /**
- * @return mixed|void
- * @throws ProductRequestException
- */
- public function validateFields()
- {
- if (!is_int($this->productId) || $this->productId < 1) {
- throw new ProductRequestException(
- 'Invalid value received for product with id ' . $this->productId
- );
- }
- if (!is_int($this->srnStorageId) || $this->srnStorageId < 1) {
- throw new ProductRequestException(
- 'Invalid value received for ' . self::SRN_STORAGE_ID . ':' . $this->srnStorageId
- );
- }
- }
- /**
- * @param array $data
- * @throws ProductRequestException
- */
- public function fromArray(array $data)
- {
- if (array_key_exists(self::SRN_STORAGE_ID, $data)) {
- $this->srnStorageId = $data[self::SRN_STORAGE_ID];
- }
- if (array_key_exists(self::SERIAL_NUMBER, $data)) {
- $this->serialNumber = $data[self::SERIAL_NUMBER];
- }
- if (array_key_exists(self::SERVICE_SHEET, $data)) {
- $this->serviceSheet = $data[self::SERVICE_SHEET];
- }
- if (array_key_exists(self::REVERSED_PRICE, $data)) {
- $this->reversedPrice = $data[self::REVERSED_PRICE];
- }
- }
- /**
- * @return array|mixed
- */
- public function toArray()
- {
- return array(
- self::SERIAL_NUMBER => $this->serialNumber,
- self::SERVICE_SHEET => $this->serviceSheet,
- self::SRN_STORAGE_ID => $this->srnStorageId,
- self::REVERSED_PRICE => $this->reversedPrice,
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement