Orderline.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. /**
  3. * This file is part of the Klarna KP module
  4. *
  5. * (c) Klarna Bank AB (publ)
  6. *
  7. * For the full copyright and license information, please view the NOTICE
  8. * and LICENSE files that were distributed with this source code.
  9. */
  10. namespace Klarna\Kp\Model\Api\Request;
  11. use Klarna\Kp\Api\Data\OrderlineInterface;
  12. /**
  13. * Class Orderline
  14. *
  15. * @package Klarna\Kp\Model\Api\Request
  16. */
  17. class Orderline implements OrderlineInterface
  18. {
  19. use \Klarna\Kp\Model\Api\Export;
  20. /**
  21. * @var string
  22. */
  23. private $type;
  24. /**
  25. * @var string
  26. */
  27. private $reference;
  28. /**
  29. * @var string
  30. */
  31. private $name;
  32. /**
  33. * @var int
  34. */
  35. private $quantity;
  36. /**
  37. * @var string
  38. */
  39. private $quantity_unit;
  40. /**
  41. * @var int
  42. */
  43. private $unit_price;
  44. /**
  45. * @var int
  46. */
  47. private $tax_rate;
  48. /**
  49. * @var int
  50. */
  51. private $total_amount;
  52. /**
  53. * @var int
  54. */
  55. private $total_discount_amount;
  56. /**
  57. * @var int
  58. */
  59. private $total_tax_amount;
  60. /**
  61. * @var string
  62. */
  63. private $product_url;
  64. /**
  65. * @var string
  66. */
  67. private $image_url;
  68. /**
  69. * Constructor.
  70. *
  71. * @param array $data
  72. */
  73. public function __construct($data = [])
  74. {
  75. foreach ($data as $key => $value) {
  76. if (property_exists($this, $key)) {
  77. $this->$key = $value;
  78. $this->exports[] = $key;
  79. }
  80. }
  81. }
  82. /**
  83. * Orderline type
  84. *
  85. * Possible values:
  86. *
  87. * * physical (default)
  88. * * discount
  89. * * shipping_fee
  90. *
  91. * @param string $type
  92. */
  93. public function setType($type)
  94. {
  95. $this->type = $type;
  96. }
  97. /**
  98. * Descriptive item name.
  99. *
  100. * @param string $name
  101. */
  102. public function setName($name)
  103. {
  104. $this->name = $name;
  105. }
  106. /**
  107. * @param string $product_url
  108. */
  109. public function setProductUrl($product_url)
  110. {
  111. $this->product_url = $product_url;
  112. }
  113. /**
  114. * @param string $image_url
  115. */
  116. public function setImageUrl($image_url)
  117. {
  118. $this->image_url = $image_url;
  119. }
  120. /**
  121. * The item quantity.
  122. *
  123. * @param int $quantity
  124. */
  125. public function setQuantity($quantity)
  126. {
  127. $this->quantity = $quantity;
  128. }
  129. /**
  130. * Descriptive unit, e.g. kg, pcs.
  131. *
  132. * @param string $quantity_unit
  133. */
  134. public function setQuantityUnit($quantity_unit)
  135. {
  136. $this->quantity_unit = $quantity_unit;
  137. }
  138. /**
  139. * Includes tax, excludes discount. Implicit decimal (eg 1000 instead of 10.00)
  140. *
  141. * @param int $unit_price
  142. */
  143. public function setUnitPrice($unit_price)
  144. {
  145. $this->unit_price = $unit_price;
  146. }
  147. /**
  148. * In percent, two implicit decimals, i.e. 2500 = 25%.
  149. *
  150. * @param int $tax_rate
  151. */
  152. public function setTaxRate($tax_rate)
  153. {
  154. $this->tax_rate = $tax_rate;
  155. }
  156. /**
  157. * Must be within ±1 of total_amount - total_amount 10000 / (10000 + tax_rate). Negative when type is discount.
  158. *
  159. * @param int $total_tax_amount
  160. */
  161. public function setTotalTaxAmount($total_tax_amount)
  162. {
  163. $this->total_tax_amount = $total_tax_amount;
  164. }
  165. /**
  166. * Includes tax. Implicit decimal (eg 1000 instead of 10.00)
  167. *
  168. * @param int $total_discount_amount
  169. */
  170. public function setTotalDiscountAmount($total_discount_amount)
  171. {
  172. $this->total_discount_amount = $total_discount_amount;
  173. }
  174. /**
  175. * Includes tax and discount. Must match (quantity * unit_price) + total discount amount within ±quantity.
  176. *
  177. * @param int $total_amount
  178. */
  179. public function setTotalAmount($total_amount)
  180. {
  181. $this->total_amount = $total_amount;
  182. }
  183. /**
  184. * Article number, SKU or similar.
  185. *
  186. * @param string $reference
  187. */
  188. public function setReference($reference)
  189. {
  190. $this->reference = $reference;
  191. }
  192. /**
  193. * @return int
  194. */
  195. public function getTotal()
  196. {
  197. return $this->total_amount;
  198. }
  199. }