PendingAuthorization.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php
  2. /**
  3. * Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License").
  6. * You may not use this file except in compliance with the License.
  7. * A copy of the License is located at
  8. *
  9. * http://aws.amazon.com/apache2.0
  10. *
  11. * or in the "license" file accompanying this file. This file is distributed
  12. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied. See the License for the specific language governing
  14. * permissions and limitations under the License.
  15. */
  16. namespace Amazon\Payment\Model;
  17. use Amazon\Payment\Api\Data\PendingAuthorizationInterface;
  18. use Amazon\Payment\Model\ResourceModel\PendingAuthorization as PendingAuthorizationResourceModel;
  19. use Magento\Framework\Data\Collection\AbstractDb;
  20. use Magento\Framework\Model\AbstractModel;
  21. use Magento\Framework\Model\Context;
  22. use Magento\Framework\Model\ResourceModel\AbstractResource;
  23. use Magento\Framework\Registry;
  24. use Magento\Framework\Stdlib\DateTime\DateTimeFactory;
  25. use Magento\Sales\Api\Data\OrderInterface;
  26. class PendingAuthorization extends AbstractModel implements PendingAuthorizationInterface
  27. {
  28. /**
  29. * @var DateTimeFactory
  30. */
  31. private $dateFactory;
  32. /**
  33. * @var boolean
  34. */
  35. private $lockOnLoad = false;
  36. /**
  37. * PendingCapture constructor.
  38. *
  39. * @param Context $context
  40. * @param Registry $registry
  41. * @param DateTimeFactory $dateFactory
  42. * @param AbstractResource|null $resource
  43. * @param AbstractDb|null $resourceCollection
  44. * @param array $data
  45. */
  46. public function __construct(
  47. Context $context,
  48. Registry $registry,
  49. DateTimeFactory $dateFactory,
  50. AbstractResource $resource = null,
  51. AbstractDb $resourceCollection = null,
  52. array $data = []
  53. ) {
  54. parent::__construct(
  55. $context,
  56. $registry,
  57. $resource,
  58. $resourceCollection,
  59. $data
  60. );
  61. $this->dateFactory = $dateFactory;
  62. }
  63. /**
  64. * {@inheritDoc}
  65. */
  66. protected function _construct()
  67. {
  68. $this->_init(PendingAuthorizationResourceModel::class);
  69. }
  70. /**
  71. * {@inheritDoc}
  72. */
  73. public function getOrderId()
  74. {
  75. return $this->getData(PendingAuthorizationInterface::ORDER_ID);
  76. }
  77. /**
  78. * {@inheritDoc}
  79. */
  80. public function setOrderId($orderId)
  81. {
  82. return $this->setData(PendingAuthorizationInterface::ORDER_ID, $orderId);
  83. }
  84. /**
  85. * {@inheritDoc}
  86. */
  87. public function getAuthorizationId()
  88. {
  89. return $this->getData(PendingAuthorizationInterface::AUTHORIZATION_ID);
  90. }
  91. /**
  92. * {@inheritDoc}
  93. */
  94. public function setAuthorizationId($authorizationId)
  95. {
  96. return $this->setData(PendingAuthorizationInterface::AUTHORIZATION_ID, $authorizationId);
  97. }
  98. /**
  99. * {@inheritDoc}
  100. */
  101. public function getCaptureId()
  102. {
  103. return $this->getData(PendingAuthorizationInterface::CAPTURE_ID);
  104. }
  105. /**
  106. * {@inheritDoc}
  107. */
  108. public function setCaptureId($captureId)
  109. {
  110. return $this->setData(PendingAuthorizationInterface::CAPTURE_ID, $captureId);
  111. }
  112. /**
  113. * {@inheritDoc}
  114. */
  115. public function getPaymentId()
  116. {
  117. return $this->getData(PendingAuthorizationInterface::PAYMENT_ID);
  118. }
  119. /**
  120. * {@inheritDoc}
  121. */
  122. public function setPaymentId($paymentId)
  123. {
  124. return $this->setData(PendingAuthorizationInterface::PAYMENT_ID, $paymentId);
  125. }
  126. /**
  127. * {@inheritDoc}
  128. */
  129. public function isCapture()
  130. {
  131. return (bool)$this->getData(PendingAuthorizationInterface::CAPTURE);
  132. }
  133. /**
  134. * {@inheritDoc}
  135. */
  136. public function setCapture($capture)
  137. {
  138. return $this->setData(PendingAuthorizationInterface::CAPTURE, $capture);
  139. }
  140. /**
  141. * {@inheritDoc}
  142. */
  143. public function isProcessed()
  144. {
  145. return (bool)$this->getData(PendingAuthorizationInterface::PROCESSED);
  146. }
  147. /**
  148. * {@inheritDoc}
  149. */
  150. public function setProcessed($processed)
  151. {
  152. return $this->setData(PendingAuthorizationInterface::PROCESSED, $processed);
  153. }
  154. /**
  155. * {@inheritDoc}
  156. */
  157. public function setCreatedAt($createdAt)
  158. {
  159. return $this->setData(PendingAuthorizationInterface::CREATED_AT, $createdAt);
  160. }
  161. /**
  162. * {@inheritDoc}
  163. */
  164. public function getCreatedAt()
  165. {
  166. return $this->getData(PendingAuthorizationInterface::CREATED_AT);
  167. }
  168. /**
  169. * {@inheritDoc}
  170. */
  171. public function setUpdatedAt($updatedAt)
  172. {
  173. return $this->setData(PendingAuthorizationInterface::UPDATED_AT, $updatedAt);
  174. }
  175. /**
  176. * {@inheritDoc}
  177. */
  178. public function getUpdatedAt()
  179. {
  180. return $this->getData(PendingAuthorizationInterface::UPDATED_AT);
  181. }
  182. /**
  183. * {@inheritDoc}
  184. */
  185. public function setOrder(OrderInterface $order)
  186. {
  187. $this->setOrderId($order->getId());
  188. $this->setPaymentId($order->getPayment()->getId());
  189. return $this;
  190. }
  191. /**
  192. * {@inheritDoc}
  193. */
  194. public function beforeSave()
  195. {
  196. if (! $this->getId()) {
  197. $this->setCreatedAt($this->dateFactory->create()->gmtDate());
  198. }
  199. $this->setUpdatedAt($this->dateFactory->create()->gmtDate());
  200. return parent::beforeSave();
  201. }
  202. /**
  203. * {@inheritDoc}
  204. */
  205. public function setLockOnLoad($lockOnLoad)
  206. {
  207. $this->lockOnLoad = $lockOnLoad;
  208. return $this;
  209. }
  210. /**
  211. * {@inheritDoc}
  212. */
  213. public function hasLockOnLoad()
  214. {
  215. return $this->lockOnLoad;
  216. }
  217. }