IpnFactory.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Model;
  7. class IpnFactory
  8. {
  9. /**
  10. * Object Manager instance
  11. *
  12. * @var \Magento\Framework\ObjectManagerInterface
  13. */
  14. protected $_objectManager = null;
  15. /**
  16. * @var array
  17. */
  18. protected $mapping = [];
  19. /**
  20. * Factory constructor
  21. *
  22. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  23. * @param array $mapping
  24. */
  25. public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager, array $mapping = [])
  26. {
  27. $this->_objectManager = $objectManager;
  28. $this->mapping = $mapping;
  29. }
  30. /**
  31. * Create class instance with specified parameters
  32. *
  33. * @param array $data
  34. * @return \Magento\Paypal\Model\IpnInterface
  35. */
  36. public function create(array $data = [])
  37. {
  38. $type = isset($data['data']['txn_type']) ? $data['data']['txn_type'] : '';
  39. $instanceType = isset($this->mapping[$type]) ? $this->mapping[$type] : \Magento\Paypal\Model\Ipn::class;
  40. return $this->_objectManager->create($instanceType, $data);
  41. }
  42. }