PaymentDataObjectFactory.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Gateway\Data;
  7. use Magento\Framework\ObjectManagerInterface;
  8. use Magento\Payment\Model\InfoInterface;
  9. use Magento\Sales\Model\Order\Payment;
  10. class PaymentDataObjectFactory implements PaymentDataObjectFactoryInterface
  11. {
  12. /**
  13. * Object Manager instance
  14. *
  15. * @var ObjectManagerInterface
  16. */
  17. private $objectManager;
  18. /**
  19. * @var Order\OrderAdapterFactory
  20. */
  21. private $orderAdapterFactory;
  22. /**
  23. * @var Quote\QuoteAdapterFactory
  24. */
  25. private $quoteAdapterFactory;
  26. /**
  27. * Factory constructor
  28. *
  29. * @param ObjectManagerInterface $objectManager
  30. * @param Order\OrderAdapterFactory $orderAdapterFactory
  31. * @param Quote\QuoteAdapterFactory $quoteAdapterFactory
  32. */
  33. public function __construct(
  34. ObjectManagerInterface $objectManager,
  35. Order\OrderAdapterFactory $orderAdapterFactory,
  36. Quote\QuoteAdapterFactory $quoteAdapterFactory
  37. ) {
  38. $this->objectManager = $objectManager;
  39. $this->orderAdapterFactory = $orderAdapterFactory;
  40. $this->quoteAdapterFactory = $quoteAdapterFactory;
  41. }
  42. /**
  43. * Creates Payment Data Object
  44. *
  45. * @param InfoInterface $paymentInfo
  46. * @return PaymentDataObjectInterface
  47. */
  48. public function create(InfoInterface $paymentInfo)
  49. {
  50. if ($paymentInfo instanceof Payment) {
  51. $data['order'] = $this->orderAdapterFactory->create(
  52. ['order' => $paymentInfo->getOrder()]
  53. );
  54. } elseif ($paymentInfo instanceof \Magento\Quote\Model\Quote\Payment) {
  55. $data['order'] = $this->quoteAdapterFactory->create(
  56. ['quote' => $paymentInfo->getQuote()]
  57. );
  58. }
  59. $data['payment'] = $paymentInfo;
  60. return $this->objectManager->create(
  61. \Magento\Payment\Gateway\Data\PaymentDataObject::class,
  62. $data
  63. );
  64. }
  65. }