|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace B2Binpay\Payment\Controller\Adminhtml\System\Config; |
|
4
|
|
|
|
|
5
|
|
|
use Magento\Backend\App\Action; |
|
|
|
|
|
|
6
|
|
|
use Magento\Backend\App\Action\Context; |
|
|
|
|
|
|
7
|
|
|
use Magento\Framework\Controller\Result\JsonFactory; |
|
|
|
|
|
|
8
|
|
|
use Magento\Store\Model\StoreManagerInterface; |
|
|
|
|
|
|
9
|
|
|
use B2Binpay\Payment\Model\Adapter\B2BinpayAdapterFactory; |
|
10
|
|
|
use B2Binpay\Exception\B2BinpayException; |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class Check |
|
14
|
|
|
*/ |
|
15
|
|
|
class Check extends Action |
|
16
|
|
|
{ |
|
17
|
|
|
const SECRET_MASK = '******'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var \Magento\Framework\App\RequestInterface |
|
|
|
|
|
|
21
|
|
|
*/ |
|
22
|
|
|
private $request; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var JsonFactory |
|
26
|
|
|
*/ |
|
27
|
|
|
private $resultJsonFactory; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var StoreManagerInterface |
|
31
|
|
|
*/ |
|
32
|
|
|
private $storeManager; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var B2BinpayAdapterFactory |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $adapterFactory; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Auth constructor. |
|
41
|
|
|
* |
|
42
|
|
|
* @param Context $context |
|
43
|
|
|
* @param JsonFactory $resultJsonFactory |
|
44
|
|
|
* @param StoreManagerInterface $storeManager |
|
45
|
|
|
* @param B2BinpayAdapterFactory $adapterFactory |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct( |
|
48
|
|
|
Context $context, |
|
49
|
|
|
JsonFactory $resultJsonFactory, |
|
50
|
|
|
StoreManagerInterface $storeManager, |
|
51
|
|
|
B2BinpayAdapterFactory $adapterFactory |
|
52
|
|
|
) { |
|
53
|
|
|
$this->request = $context->getRequest(); |
|
54
|
|
|
$this->storeManager = $storeManager; |
|
55
|
|
|
$this->resultJsonFactory = $resultJsonFactory; |
|
56
|
|
|
$this->adapterFactory = $adapterFactory; |
|
57
|
|
|
parent::__construct($context); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Admin controller for auth params test |
|
62
|
|
|
* |
|
63
|
|
|
* - Check API Key/Secret |
|
64
|
|
|
* - Check Wallet ids |
|
65
|
|
|
* |
|
66
|
|
|
* @return \Magento\Framework\Controller\Result\Json |
|
|
|
|
|
|
67
|
|
|
* @throws \Magento\Framework\Exception\NoSuchEntityException |
|
68
|
|
|
*/ |
|
69
|
|
|
public function execute() |
|
70
|
|
|
{ |
|
71
|
|
|
$result = $this->resultJsonFactory->create(); |
|
72
|
|
|
|
|
73
|
|
|
$storeId = $this->storeManager->getStore()->getId(); |
|
74
|
|
|
$authKey = $this->request->getParam('auth_key'); |
|
75
|
|
|
$authSecret = $this->request->getParam('auth_secret'); |
|
76
|
|
|
$wallets = $this->request->getParam('wallets'); |
|
77
|
|
|
$testing = ('1' === $this->request->getParam('is_test')); |
|
78
|
|
|
|
|
79
|
|
|
if (empty($authKey)) { |
|
80
|
|
|
return $result->setData([ |
|
81
|
|
|
'success' => false, |
|
82
|
|
|
'message' => __('You need to fill Auth API Key') |
|
|
|
|
|
|
83
|
|
|
]); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
if (empty($authSecret)) { |
|
87
|
|
|
return $result->setData([ |
|
88
|
|
|
'success' => false, |
|
89
|
|
|
'message' => __('You need to fill Auth API Secret') |
|
90
|
|
|
]); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
if (empty($wallets)) { |
|
94
|
|
|
return $result->setData([ |
|
95
|
|
|
'success' => false, |
|
96
|
|
|
'message' => __('You need to fill Wallets') |
|
97
|
|
|
]); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
if ($authSecret === $this::SECRET_MASK) { |
|
101
|
|
|
$authSecret = null; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
$b2binpay = $this->adapterFactory->create( |
|
105
|
|
|
$storeId, |
|
106
|
|
|
$authKey, |
|
107
|
|
|
$authSecret, |
|
108
|
|
|
$testing |
|
109
|
|
|
); |
|
110
|
|
|
|
|
111
|
|
|
try { |
|
112
|
|
|
$b2binpay->getAuthToken(); |
|
113
|
|
|
} catch (B2BinpayException $e) { |
|
114
|
|
|
return $result->setData([ |
|
115
|
|
|
'success' => false, |
|
116
|
|
|
'message' => __('Wrong Auth API Key/Secret') |
|
117
|
|
|
]); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
foreach (explode('_', $wallets) as $wallet) { |
|
121
|
|
|
try { |
|
122
|
|
|
$b2binpay->getWallet($wallet); |
|
123
|
|
|
} catch (B2BinpayException $e) { |
|
124
|
|
|
return $result->setData([ |
|
125
|
|
|
'success' => false, |
|
126
|
|
|
'message' => __('Wrong Wallet ID: ' . $wallet) |
|
127
|
|
|
]); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
return $result->setData([ |
|
132
|
|
|
'success' => true, |
|
133
|
|
|
'message' => __('Success') |
|
134
|
|
|
]); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @return bool |
|
139
|
|
|
*/ |
|
140
|
|
|
protected function _isAllowed() |
|
141
|
|
|
{ |
|
142
|
|
|
return $this->_authorization->isAllowed('B2Binpay_Payment::config'); |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|
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