Payflow.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Controller;
  7. /**
  8. * Payflow Checkout Controller
  9. */
  10. abstract class Payflow extends \Magento\Framework\App\Action\Action
  11. {
  12. /**
  13. * @var \Magento\Checkout\Model\Session
  14. */
  15. protected $_checkoutSession;
  16. /**
  17. * @var \Magento\Sales\Model\OrderFactory
  18. */
  19. protected $_orderFactory;
  20. /**
  21. * @var \Psr\Log\LoggerInterface
  22. */
  23. protected $_logger;
  24. /**
  25. * @var \Magento\Paypal\Model\PayflowlinkFactory
  26. */
  27. protected $_payflowModelFactory;
  28. /**
  29. * @var \Magento\Paypal\Helper\Checkout
  30. */
  31. protected $_checkoutHelper;
  32. /**
  33. * Redirect block name
  34. * @var string
  35. */
  36. protected $_redirectBlockName = 'payflow.link.iframe';
  37. /**
  38. * @var \Magento\Sales\Api\PaymentFailuresInterface
  39. */
  40. private $paymentFailures;
  41. /**
  42. * @param \Magento\Framework\App\Action\Context $context
  43. * @param \Magento\Checkout\Model\Session $checkoutSession
  44. * @param \Magento\Sales\Model\OrderFactory $orderFactory
  45. * @param \Magento\Paypal\Model\PayflowlinkFactory $payflowModelFactory
  46. * @param \Magento\Paypal\Helper\Checkout $checkoutHelper
  47. * @param \Psr\Log\LoggerInterface $logger
  48. * @param \Magento\Sales\Api\PaymentFailuresInterface|null $paymentFailures
  49. */
  50. public function __construct(
  51. \Magento\Framework\App\Action\Context $context,
  52. \Magento\Checkout\Model\Session $checkoutSession,
  53. \Magento\Sales\Model\OrderFactory $orderFactory,
  54. \Magento\Paypal\Model\PayflowlinkFactory $payflowModelFactory,
  55. \Magento\Paypal\Helper\Checkout $checkoutHelper,
  56. \Psr\Log\LoggerInterface $logger,
  57. \Magento\Sales\Api\PaymentFailuresInterface $paymentFailures = null
  58. ) {
  59. parent::__construct($context);
  60. $this->_checkoutSession = $checkoutSession;
  61. $this->_orderFactory = $orderFactory;
  62. $this->_logger = $logger;
  63. $this->_payflowModelFactory = $payflowModelFactory;
  64. $this->_checkoutHelper = $checkoutHelper;
  65. $this->paymentFailures = $paymentFailures ?: $this->_objectManager->get(
  66. \Magento\Sales\Api\PaymentFailuresInterface::class
  67. );
  68. }
  69. /**
  70. * Cancel order, return quote to customer
  71. *
  72. * @param string $errorMsg
  73. * @return false|string
  74. */
  75. protected function _cancelPayment($errorMsg = '')
  76. {
  77. $errorMsg = trim(strip_tags($errorMsg));
  78. $order = $this->_checkoutSession->getLastRealOrder();
  79. if ($order->getId()) {
  80. $this->paymentFailures->handle((int)$order->getQuoteId(), $errorMsg);
  81. }
  82. $gotoSection = false;
  83. $this->_checkoutHelper->cancelCurrentOrder($errorMsg);
  84. if ($this->_checkoutSession->restoreQuote()) {
  85. //Redirect to payment step
  86. $gotoSection = 'paymentMethod';
  87. }
  88. return $gotoSection;
  89. }
  90. }