Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Rev\ReversalLib\Request\CreateReversal\Product;
  4.  
  5. use Rev\ReversalLib\Exception\CreateReversal\Product\ProductRequestException;
  6. use Rev\ReversalLib\Request\RequestInterface;
  7.  
  8. /**
  9. * Class AbstractProductRequest
  10. * @package Rev\ReversalLib\Request\CreateReversal\Product
  11. */
  12. abstract class AbstractProductRequest implements RequestInterface
  13. {
  14. //common fields mapping
  15. const SRN_STORAGE_ID = 'srn_storage_id';
  16. const SERIAL_NUMBER = 'serial_number';
  17. const SERVICE_SHEET = 'service_sheet';
  18. const IGNORE_REVERSAL = 'ignore_reversal';
  19. const REVERSED_PRICE = 'reversed_price';
  20.  
  21. /** @var int */
  22. protected $productId;
  23.  
  24. /** @var int */
  25. protected $srnStorageId;
  26.  
  27. /** @var string */
  28. protected $serialNumber;
  29.  
  30. /** @var int */
  31. protected $serviceSheet;
  32.  
  33. /** @var float */
  34. protected $reversedPrice;
  35.  
  36. /**
  37. * @return int
  38. */
  39. public function getProductId()
  40. {
  41. return $this->productId;
  42. }
  43.  
  44. /**
  45. * @param int $productId
  46. * @return AbstractProductRequest
  47. */
  48. public function setProductId($productId)
  49. {
  50. $this->productId = (int)$productId;
  51. return $this;
  52. }
  53.  
  54. /**
  55. * @return int
  56. */
  57. public function getSrnStorageId()
  58. {
  59. return $this->srnStorageId;
  60. }
  61.  
  62. /**
  63. * @param int $srnStorageId
  64. * @return AbstractProductRequest
  65. */
  66. public function setSrnStorageId($srnStorageId)
  67. {
  68. $this->srnStorageId = (int)$srnStorageId;
  69. return $this;
  70. }
  71.  
  72. /**
  73. * @return string
  74. */
  75. public function getSerialNumber()
  76. {
  77. return $this->serialNumber;
  78. }
  79.  
  80. /**
  81. * @param string $serialNumber
  82. * @return AbstractProductRequest
  83. */
  84. public function setSerialNumber($serialNumber)
  85. {
  86. $this->serialNumber = $serialNumber;
  87. return $this;
  88. }
  89.  
  90. /**
  91. * @return int
  92. */
  93. public function getServiceSheet()
  94. {
  95. return $this->serviceSheet;
  96. }
  97.  
  98. /**
  99. * @param int $serviceSheet
  100. * @return AbstractProductRequest
  101. */
  102. public function setServiceSheet($serviceSheet)
  103. {
  104. $this->serviceSheet = (int)$serviceSheet;
  105. return $this;
  106. }
  107.  
  108. /**
  109. * @return float
  110. */
  111. public function getReversedPrice()
  112. {
  113. return $this->reversedPrice;
  114. }
  115.  
  116. /**
  117. * @param float $reversedPrice
  118. * @return AbstractProductRequest
  119. */
  120. public function setReversedPrice($reversedPrice)
  121. {
  122. $this->reversedPrice = (float)$reversedPrice;
  123. return $this;
  124. }
  125.  
  126. /**
  127. * @return mixed|void
  128. * @throws ProductRequestException
  129. */
  130. public function validateFields()
  131. {
  132. if (!is_int($this->productId) || $this->productId < 1) {
  133. throw new ProductRequestException(
  134. 'Invalid value received for product with id ' . $this->productId
  135. );
  136. }
  137.  
  138. if (!is_int($this->srnStorageId) || $this->srnStorageId < 1) {
  139. throw new ProductRequestException(
  140. 'Invalid value received for ' . self::SRN_STORAGE_ID . ':' . $this->srnStorageId
  141. );
  142. }
  143. }
  144.  
  145. /**
  146. * @param array $data
  147. * @throws ProductRequestException
  148. */
  149. public function fromArray(array $data)
  150. {
  151. if (array_key_exists(self::SRN_STORAGE_ID, $data)) {
  152. $this->srnStorageId = $data[self::SRN_STORAGE_ID];
  153. }
  154.  
  155. if (array_key_exists(self::SERIAL_NUMBER, $data)) {
  156. $this->serialNumber = $data[self::SERIAL_NUMBER];
  157. }
  158.  
  159. if (array_key_exists(self::SERVICE_SHEET, $data)) {
  160. $this->serviceSheet = $data[self::SERVICE_SHEET];
  161. }
  162.  
  163. if (array_key_exists(self::REVERSED_PRICE, $data)) {
  164. $this->reversedPrice = $data[self::REVERSED_PRICE];
  165. }
  166. }
  167.  
  168. /**
  169. * @return array|mixed
  170. */
  171. public function toArray()
  172. {
  173. return array(
  174. self::SERIAL_NUMBER => $this->serialNumber,
  175. self::SERVICE_SHEET => $this->serviceSheet,
  176. self::SRN_STORAGE_ID => $this->srnStorageId,
  177. self::REVERSED_PRICE => $this->reversedPrice,
  178. );
  179. }
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement