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