Ipn.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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\Controller\Payment;
  17. use Amazon\Core\Helper\Data;
  18. use Amazon\Core\Model\Config\Source\UpdateMechanism;
  19. use Amazon\Payment\Api\Ipn\CompositeProcessorInterface;
  20. use Amazon\Payment\Ipn\IpnHandlerFactoryInterface;
  21. use Magento\Framework\App\Action\Action;
  22. use Magento\Framework\App\Action\Context;
  23. use Magento\Framework\App\RequestInterface;
  24. use Magento\Framework\App\ResponseInterface;
  25. use Magento\Framework\Exception\NotFoundException;
  26. class Ipn extends Action
  27. {
  28. /**
  29. * @var IpnHandlerFactoryInterface
  30. */
  31. private $ipnHandlerFactory;
  32. /**
  33. * @var CompositeProcessorInterface
  34. */
  35. private $compositeProcessor;
  36. /**
  37. * @var Data
  38. */
  39. private $coreHelper;
  40. public function __construct(
  41. Context $context,
  42. IpnHandlerFactoryInterface $ipnHandlerFactory,
  43. CompositeProcessorInterface $compositeProcessor,
  44. Data $coreHelper
  45. ) {
  46. parent::__construct($context);
  47. $this->ipnHandlerFactory = $ipnHandlerFactory;
  48. $this->compositeProcessor = $compositeProcessor;
  49. $this->coreHelper = $coreHelper;
  50. }
  51. public function execute()
  52. {
  53. if (UpdateMechanism::IPN !== $this->coreHelper->getUpdateMechanism()) {
  54. throw new NotFoundException(__('IPN not enabled.'));
  55. }
  56. $headers = $this->_request->getHeaders()->toArray();
  57. $body = $this->_request->getContent();
  58. $ipnHandler = $this->ipnHandlerFactory->create($headers, $body);
  59. $ipnData = $ipnHandler->toArray();
  60. $this->compositeProcessor->process($ipnData);
  61. }
  62. }