IpnHandlerFactory.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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\Ipn;
  17. use Amazon\Core\Helper\Data;
  18. use Magento\Framework\ObjectManagerInterface;
  19. use AmazonPay\IpnHandlerInterface;
  20. use Psr\Log\LoggerAwareInterface;
  21. use Psr\Log\LoggerInterface;
  22. class IpnHandlerFactory implements IpnHandlerFactoryInterface
  23. {
  24. /**
  25. * @var ObjectManagerInterface
  26. */
  27. private $objectManager;
  28. /**
  29. * @var string
  30. */
  31. private $instanceName;
  32. /**
  33. * @var LoggerInterface
  34. */
  35. private $logger;
  36. /**
  37. * @var Data
  38. */
  39. private $coreHelper;
  40. public function __construct(
  41. ObjectManagerInterface $objectManager,
  42. LoggerInterface $logger,
  43. Data $coreHelper,
  44. $instanceName = '\\AmazonPay\\IpnHandlerInterface'
  45. ) {
  46. $this->objectManager = $objectManager;
  47. $this->instanceName = $instanceName;
  48. $this->logger = $logger;
  49. $this->coreHelper = $coreHelper;
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function create($headers, $body)
  55. {
  56. $handler = $this->objectManager->create(
  57. $this->instanceName,
  58. ['requestHeaders' => $headers, 'requestBody' => $body]
  59. );
  60. if ($handler instanceof LoggerAwareInterface && $this->coreHelper->isLoggingEnabled()) {
  61. $handler->setLogger($this->logger);
  62. }
  63. return $handler;
  64. }
  65. }