GeneratorFactory.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Signifyd\Model\MessageGenerators;
  7. use Magento\Framework\ObjectManagerInterface;
  8. use Magento\Signifyd\Model\MessageGeneratorInterface;
  9. /**
  10. * Creates instance of message generator based on received type of message.
  11. */
  12. class GeneratorFactory
  13. {
  14. /**
  15. * Type of message for Signifyd case creation.
  16. * @var string
  17. */
  18. private static $caseCreation = 'cases/creation';
  19. /**
  20. * Type of message for Signifyd case re-scoring.
  21. * @var string
  22. */
  23. private static $caseRescore = 'cases/rescore';
  24. /**
  25. * Type of message for Signifyd case reviewing
  26. * @var string
  27. */
  28. private static $caseReview = 'cases/review';
  29. /**
  30. * Type of message of Signifyd guarantee completion
  31. * @var string
  32. */
  33. private static $guaranteeCompletion = 'guarantees/completion';
  34. /**
  35. * Type of message of Signifyd guarantee creation
  36. * @var string
  37. */
  38. private static $guaranteeCreation = 'guarantees/creation';
  39. /**
  40. * Type of message of Signifyd guarantee canceling
  41. * @var string
  42. */
  43. private static $guaranteeCancel = 'guarantees/cancel';
  44. /**
  45. * UpdatingServiceFactory constructor.
  46. *
  47. * @param ObjectManagerInterface $objectManager
  48. */
  49. public function __construct(ObjectManagerInterface $objectManager)
  50. {
  51. $this->objectManager = $objectManager;
  52. }
  53. /**
  54. * Creates instance of message generator.
  55. * Throws exception if type of message generator does not have implementations.
  56. *
  57. * @param string $type
  58. * @return GeneratorInterface
  59. * @throws \InvalidArgumentException
  60. */
  61. public function create($type)
  62. {
  63. $className = PatternGenerator::class;
  64. switch ($type) {
  65. case self::$caseCreation:
  66. $classConfig = [
  67. 'template' => 'Signifyd Case %1 has been created for order.',
  68. 'requiredParams' => ['caseId']
  69. ];
  70. break;
  71. case self::$caseRescore:
  72. $classConfig = [];
  73. $className = CaseRescore::class;
  74. break;
  75. case self::$caseReview:
  76. $classConfig = [
  77. 'template' => 'Case Update: Case Review was completed. Review Deposition is %1.',
  78. 'requiredParams' => ['reviewDisposition']
  79. ];
  80. break;
  81. case self::$guaranteeCompletion:
  82. $classConfig = [
  83. 'template' => 'Case Update: Guarantee Disposition is %1.',
  84. 'requiredParams' => ['guaranteeDisposition']
  85. ];
  86. break;
  87. case self::$guaranteeCreation:
  88. $classConfig = [
  89. 'template' => 'Case Update: Case is submitted for guarantee.'
  90. ];
  91. break;
  92. case self::$guaranteeCancel:
  93. $classConfig = [
  94. 'template' => 'Case Update: Case guarantee has been cancelled.'
  95. ];
  96. break;
  97. default:
  98. throw new \InvalidArgumentException('Specified message type does not supported.');
  99. }
  100. return $this->objectManager->create($className, $classConfig);
  101. }
  102. }