1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright © Getnet. All rights reserved. |
4
|
|
|
* |
5
|
|
|
* @author Bruno Elisei <[email protected]> |
6
|
|
|
* See LICENSE for license details. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Getnet\SplitExampleMagento\Controller\Adminhtml\Order; |
10
|
|
|
|
11
|
|
|
use Getnet\PaymentMagento\Model\Console\Command\Marketplace\PaymentRelease as ModelPaymentRelease; |
|
|
|
|
12
|
|
|
use Getnet\SplitExampleMagento\Helper\Data; |
13
|
|
|
use Magento\Backend\App\Action; |
14
|
|
|
use Magento\Backend\App\Action\Context; |
15
|
|
|
use Magento\Framework\Controller\ResultFactory; |
16
|
|
|
use Magento\Framework\Controller\ResultInterface; |
17
|
|
|
use Magento\Framework\Message\ManagerInterface; |
18
|
|
|
use Magento\Framework\Serialize\Serializer\Json; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class Payment Release - Generate Payment Release. |
22
|
|
|
*/ |
23
|
|
|
class PaymentRelease extends Action |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Authorization level of a basic admin session. |
27
|
|
|
* |
28
|
|
|
* @see _isAllowed() |
29
|
|
|
*/ |
30
|
|
|
public const ADMIN_RESOURCE = 'Getnet_SplitExampleMagento::payment_release'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var ResultFactory |
34
|
|
|
*/ |
35
|
|
|
protected $resultResultFactory; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var Json |
39
|
|
|
*/ |
40
|
|
|
protected $json; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var Data |
44
|
|
|
*/ |
45
|
|
|
protected $helper; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var ModelPaymentRelease |
49
|
|
|
*/ |
50
|
|
|
protected $modelPaymentRelease; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var ManagerInterface |
54
|
|
|
*/ |
55
|
|
|
protected $messageManager; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var \Magento\Framework\Stdlib\DateTime\DateTime |
59
|
|
|
*/ |
60
|
|
|
protected $date; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface |
64
|
|
|
*/ |
65
|
|
|
protected $timezone; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param Context $context |
69
|
|
|
* @param ResultFactory $resultResultFactory |
70
|
|
|
* @param Json $json |
71
|
|
|
* @param Data $helper |
72
|
|
|
* @param ModelPaymentRelease $modelPaymentRelease |
73
|
|
|
* @param ManagerInterface $messageManager |
74
|
|
|
* @param \Magento\Framework\Stdlib\DateTime\DateTime $date |
75
|
|
|
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone |
76
|
|
|
*/ |
77
|
|
|
public function __construct( |
78
|
|
|
Context $context, |
79
|
|
|
ResultFactory $resultResultFactory, |
80
|
|
|
Json $json, |
81
|
|
|
Data $helper, |
82
|
|
|
ModelPaymentRelease $modelPaymentRelease, |
83
|
|
|
ManagerInterface $messageManager, |
84
|
|
|
\Magento\Framework\Stdlib\DateTime\DateTime $date, |
85
|
|
|
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone |
86
|
|
|
) { |
87
|
|
|
$this->resultResultFactory = $resultResultFactory; |
88
|
|
|
$this->json = $json; |
89
|
|
|
$this->helper = $helper; |
90
|
|
|
$this->modelPaymentRelease = $modelPaymentRelease; |
91
|
|
|
$this->messageManager = $messageManager; |
92
|
|
|
$this->date = $date; |
93
|
|
|
$this->timezone = $timezone; |
94
|
|
|
parent::__construct($context); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* ACL. |
99
|
|
|
* |
100
|
|
|
* @return bool |
101
|
|
|
* @SuppressWarnings(PHPMD.CamelCaseMethodName) |
102
|
|
|
*/ |
103
|
|
|
protected function _isAllowed() |
104
|
|
|
{ |
105
|
|
|
return $this->_authorization->isAllowed(self::ADMIN_RESOURCE); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Execute. |
110
|
|
|
* |
111
|
|
|
* @return ResultInterface |
112
|
|
|
*/ |
113
|
|
|
public function execute() |
114
|
|
|
{ |
115
|
|
|
$orderId = (int) $this->getRequest()->getParam('order_id'); |
116
|
|
|
$days = $this->helper->getDaysOfRelease(); |
117
|
|
|
$days = $days ? $days : 1; |
118
|
|
|
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); |
119
|
|
|
$date = new \DateTime(); |
120
|
|
|
$date->add(new \DateInterval('P'.$days.'D')); |
121
|
|
|
$date = $date->format('Y-m-d\TH:i:s\Z'); |
122
|
|
|
|
123
|
|
|
try { |
124
|
|
|
/** @var $modelPaymentRelease modelPaymentRelease */ |
125
|
|
|
$modelPaymentRelease = $this->modelPaymentRelease->createPaymentRelease($orderId, $date); |
126
|
|
|
if ($modelPaymentRelease->getSuccess()) { |
127
|
|
|
$this->messageManager->addSuccess('Payment released'); |
|
|
|
|
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
if ($modelPaymentRelease->getMessage()) { |
131
|
|
|
foreach ($modelPaymentRelease->getDetails() as $message) { |
132
|
|
|
$messageInfo = __( |
133
|
|
|
'Error: %1, description: %2', |
134
|
|
|
$message['error_code'], |
135
|
|
|
$message['description_detail'] |
136
|
|
|
); |
137
|
|
|
$this->messageManager->addError($messageInfo); |
|
|
|
|
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
} catch (\Exception $exc) { |
141
|
|
|
$this->messageManager->addError($exc->getMessage()); |
|
|
|
|
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
$resultRedirect->setUrl($this->_redirect->getRefererUrl()); |
|
|
|
|
145
|
|
|
|
146
|
|
|
return $resultRedirect; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths