OrderAdapter.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Gateway\Data\Order;
  7. use Magento\Payment\Gateway\Data\AddressAdapterInterface;
  8. use Magento\Payment\Gateway\Data\OrderAdapterInterface;
  9. use Magento\Sales\Model\Order;
  10. /**
  11. * Class OrderAdapter
  12. */
  13. class OrderAdapter implements OrderAdapterInterface
  14. {
  15. /**
  16. * @var Order
  17. */
  18. private $order;
  19. /**
  20. * @var AddressAdapter
  21. */
  22. private $addressAdapterFactory;
  23. /**
  24. * @param Order $order
  25. * @param AddressAdapterFactory $addressAdapterFactory
  26. */
  27. public function __construct(
  28. Order $order,
  29. AddressAdapterFactory $addressAdapterFactory
  30. ) {
  31. $this->order = $order;
  32. $this->addressAdapterFactory = $addressAdapterFactory;
  33. }
  34. /**
  35. * Returns currency code
  36. *
  37. * @return string
  38. */
  39. public function getCurrencyCode()
  40. {
  41. return $this->order->getBaseCurrencyCode();
  42. }
  43. /**
  44. * Returns order increment id
  45. *
  46. * @return string
  47. */
  48. public function getOrderIncrementId()
  49. {
  50. return $this->order->getIncrementId();
  51. }
  52. /**
  53. * Returns customer ID
  54. *
  55. * @return int|null
  56. */
  57. public function getCustomerId()
  58. {
  59. return $this->order->getCustomerId();
  60. }
  61. /**
  62. * Returns billing address
  63. *
  64. * @return AddressAdapterInterface|null
  65. */
  66. public function getBillingAddress()
  67. {
  68. if ($this->order->getBillingAddress()) {
  69. return $this->addressAdapterFactory->create(
  70. ['address' => $this->order->getBillingAddress()]
  71. );
  72. }
  73. return null;
  74. }
  75. /**
  76. * Returns shipping address
  77. *
  78. * @return AddressAdapterInterface|null
  79. */
  80. public function getShippingAddress()
  81. {
  82. if ($this->order->getShippingAddress()) {
  83. return $this->addressAdapterFactory->create(
  84. ['address' => $this->order->getShippingAddress()]
  85. );
  86. }
  87. return null;
  88. }
  89. /**
  90. * Returns order store id
  91. *
  92. * @return int
  93. */
  94. public function getStoreId()
  95. {
  96. return $this->order->getStoreId();
  97. }
  98. /**
  99. * Returns order id
  100. *
  101. * @return int
  102. */
  103. public function getId()
  104. {
  105. return $this->order->getEntityId();
  106. }
  107. /**
  108. * Returns order grand total amount
  109. *
  110. * @return float|null
  111. */
  112. public function getGrandTotalAmount()
  113. {
  114. return $this->order->getBaseGrandTotal();
  115. }
  116. /**
  117. * Returns list of line items in the cart
  118. *
  119. * @return \Magento\Sales\Api\Data\OrderItemInterface[]
  120. */
  121. public function getItems()
  122. {
  123. return $this->order->getItems();
  124. }
  125. /**
  126. * Gets the remote IP address for the order.
  127. *
  128. * @return string|null Remote IP address.
  129. */
  130. public function getRemoteIp()
  131. {
  132. return $this->order->getRemoteIp();
  133. }
  134. }