SubjectReader.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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\Gateway\Helper;
  17. use Magento\Checkout\Model\Session;
  18. use Amazon\Payment\Api\Data\QuoteLinkInterfaceFactory;
  19. use Amazon\Core\Helper\Data;
  20. use Magento\Quote\Model\Quote;
  21. use Magento\Payment\Gateway\Helper;
  22. use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
  23. /**
  24. * Class SubjectReader
  25. * Consolidates commonly used calls
  26. */
  27. class SubjectReader
  28. {
  29. /**
  30. * @var QuoteLinkInterfaceFactory
  31. */
  32. private $quoteLinkFactory;
  33. /**
  34. * @var Session
  35. */
  36. private $checkoutSession;
  37. /**
  38. * @var Data
  39. */
  40. private $coreHelper;
  41. /**
  42. * SubjectReader constructor.
  43. *
  44. * @param Session $checkoutSession
  45. * @param QuoteLinkInterfaceFactory $quoteLinkInterfaceFactory
  46. * @param Data $coreHelper
  47. */
  48. public function __construct(
  49. Session $checkoutSession,
  50. QuoteLinkInterfaceFactory $quoteLinkInterfaceFactory,
  51. Data $coreHelper
  52. ) {
  53. $this->quoteLinkFactory = $quoteLinkInterfaceFactory;
  54. $this->checkoutSession = $checkoutSession;
  55. $this->coreHelper = $coreHelper;
  56. }
  57. /**
  58. * Reads payment from subject
  59. *
  60. * @param array $subject
  61. * @return PaymentDataObjectInterface
  62. */
  63. public function readPayment(array $subject)
  64. {
  65. return Helper\SubjectReader::readPayment($subject);
  66. }
  67. /**
  68. * Reads amount from subject
  69. *
  70. * @param array $subject
  71. * @return mixed
  72. */
  73. public function readAmount(array $subject)
  74. {
  75. return Helper\SubjectReader::readAmount($subject);
  76. }
  77. /**
  78. * Gets quote from current checkout session and returns store ID
  79. *
  80. * @return int
  81. */
  82. public function getStoreId()
  83. {
  84. $quote = $this->getQuote();
  85. return $quote->getStoreId();
  86. }
  87. /**
  88. * Get unique Amazon ID for order from custom table
  89. *
  90. * @return mixed
  91. */
  92. public function getAmazonId()
  93. {
  94. $quoteLink = $this->getQuoteLink();
  95. return $quoteLink->getAmazonOrderReferenceId();
  96. }
  97. /**
  98. * @return \Magento\Quote\Model\Quote
  99. */
  100. public function getQuote()
  101. {
  102. return $this->checkoutSession->getQuote();
  103. }
  104. /**
  105. * @return \Amazon\Payment\Model\QuoteLink
  106. */
  107. public function getQuoteLink($quote_id = '')
  108. {
  109. $quoteLink = $this->quoteLinkFactory->create();
  110. if (!$quote_id) {
  111. $quote = $this->getQuote();
  112. $quoteLink->load($quote->getId(), 'quote_id');
  113. } else {
  114. $quoteLink->load($quote_id, 'quote_id');
  115. }
  116. return $quoteLink;
  117. }
  118. /**
  119. * @return \Magento\Sales\Model\Order
  120. */
  121. public function getOrder()
  122. {
  123. return $this->checkoutSession->getLastRealOrder();
  124. }
  125. }