Skip to content

Commit b65894e

Browse files
author
dimoncheg12
committed
market code standart
1 parent 5f30b76 commit b65894e

5 files changed

Lines changed: 43 additions & 37 deletions

File tree

Block/Widget/Redirect.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
namespace Fondy\Fondy\Block\Widget;
43

54
/**

Controller/Url/FondySuccess.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
<?php
2-
32
namespace Fondy\Fondy\Controller\Url;
43

54
use Magento\Framework\App\Action\Action;
65
use Magento\Sales\Model\Order;
6+
use Symfony\Component\Config\Definition\Exception\Exception;
77

88
class FondySuccess extends Action
99
{
1010
/** @var \Magento\Framework\View\Result\PageFactory */
1111
protected $resultPageFactory;
12+
/**
13+
* @var \Magento\Framework\Controller\Result\JsonFactory
14+
*/
15+
protected $jsonResultFactory;
1216

13-
17+
/**
18+
* FondySuccess constructor.
19+
* @param \Magento\Framework\App\Action\Context $context
20+
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
21+
* @param \Magento\Framework\Controller\Result\JsonFactory $jsonResultFactory
22+
*
23+
*/
1424
public function __construct(
1525
\Magento\Framework\App\Action\Context $context,
16-
\Magento\Framework\View\Result\PageFactory $resultPageFactory
17-
)
18-
{
26+
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
27+
\Magento\Framework\Controller\Result\JsonFactory $jsonResultFactory
28+
) {
1929
$this->resultPageFactory = $resultPageFactory;
30+
$this->jsonResultFactory = $jsonResultFactory;
2031
parent::__construct($context);
2132
}
2233

@@ -32,8 +43,8 @@ public function execute()
3243
$data = $this->getRequest()->getPostValue();
3344
if (empty($data)) {
3445
$callback = json_decode(file_get_contents("php://input"));
35-
if(empty($callback))
36-
die();
46+
if (empty($callback))
47+
throw new Exception(__('Request Parameter is not matched.'));
3748
$data = array();
3849
foreach ($callback as $key => $val) {
3950
$data[$key] = $val;
@@ -44,7 +55,10 @@ public function execute()
4455
*/
4556
$model = 'Fondy\Fondy\Model\Fondy';
4657
$paymentMethod = $this->_objectManager->create($model);
47-
$paymentMethod->processResponse($data);
58+
$response = $paymentMethod->processResponse($data);
59+
$result = $this->jsonResultFactory->create();
60+
$result->setData(['Result' => $response]);
61+
return $result;
4862
}
4963

5064
}

Controller/Url/Submit.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
namespace Fondy\Fondy\Controller\Url;
43

54
use Magento\Framework\App\Action\Action;
@@ -9,16 +8,17 @@
98
class Submit extends Action
109
{
1110
/** @var \Magento\Framework\View\Result\PageFactory */
12-
protected $resultPageFactory;
13-
14-
protected $fondy;
11+
public $resultPageFactory;
12+
/**
13+
* @var \Fondy\Fondy\Block\Widget\Redirect
14+
*/
15+
public $fondy;
1516

1617
public function __construct(
1718
\Magento\Framework\App\Action\Context $context,
1819
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
1920
\Fondy\Fondy\Block\Widget\Redirect $fondy_form
20-
)
21-
{
21+
) {
2222
$this->resultPageFactory = $resultPageFactory;
2323
$this->fondy = $fondy_form;
2424
parent::__construct($context);
@@ -29,10 +29,9 @@ public function execute()
2929
$page = $this->resultPageFactory->create();
3030
$post_data = $this->fondy->getPostData();
3131
$request = $this->doRequest($post_data);
32-
$url = json_decode($request, TRUE);
32+
$url = json_decode($request, true);
3333
if (isset($url['response']['checkout_url'])) {
34-
header("Location: " . $url['response']['checkout_url']);
35-
exit();
34+
$this->_redirect->redirect($this->_response, $url['response']['checkout_url']);
3635
}
3736

3837
return $page;

Model/Fondy.php

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
namespace Fondy\Fondy\Model;
43

54
use Magento\Quote\Api\Data\CartInterface;
@@ -68,8 +67,8 @@ public function __construct(
6867
\Magento\Sales\Model\OrderFactory $orderFactory,
6968
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
7069
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
71-
array $data = [])
72-
{
70+
array $data = []
71+
) {
7372
$this->orderFactory = $orderFactory;
7473
$this->urlBuilder = $urlBuilder;
7574
$this->_transactionBuilder = $builderInterface;
@@ -261,13 +260,9 @@ public function getPostData($orderId)
261260
private function checkFondyResponse($response)
262261
{
263262
$this->_logger->debug("checking parameters");
264-
foreach (
265-
[
266-
"order_id",
267-
"order_status",
268-
"signature"
269-
]
270-
as $param) {
263+
foreach (["order_id",
264+
"order_status",
265+
"signature"] as $param) {
271266
if (!isset($response[$param])) {
272267
$this->_logger->debug("Pay URL: required field \"{$param}\" is missing");
273268
return false;
@@ -289,20 +284,19 @@ private function checkFondyResponse($response)
289284
}
290285

291286
/**
292-
* Вызывается при запросе callback URL со стороны Fondy
293-
*
294287
* @param $responseData
288+
* @return string
295289
*/
296290
public function processResponse($responseData)
297291
{
298292
if (empty($responseData))
299-
die('No Data');
293+
return 'No Data';
300294
if ($responseData['product_id'] == 'FondyDirect') {
301295
$this->_code = 'fondy_direct';
302296
} elseif ($responseData['product_id'] == 'Fondy') {
303297
$this->_code = 'fondy';
304298
} else {
305-
die(__("FAIL"));
299+
return 'FAIL';
306300
}
307301
$debugData = ['response' => $responseData];
308302
$this->_logger->debug("processResponse", $debugData);
@@ -312,12 +306,12 @@ public function processResponse($responseData)
312306
$order = $this->getOrder($orderId);
313307
$state = $order->getStatus();
314308
if (!empty($state) && $order && ($this->_processOrder($order, $responseData) === true)) {
315-
die(__("Ok"));
316-
}else{
317-
die(__("FAIL NO ORDER DEBIT METHOD"));
309+
return 'OK';
310+
} else {
311+
return 'FAIL';
318312
}
319313
}
320-
die(__("FAIL"));
314+
return 'FAIL';
321315
}
322316

323317
/**

view/frontend/templates/html/fondy_form.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<script type="text/javascript">
1111
require(["jquery"], function ($) {
1212
$(document).ready(function () {
13-
setTimeout(function() {$('#FONDY_payment_form').submit(); }, 1500);
13+
setTimeout(function() {$('#FONDY_payment_form').submit(); }, 1500);
1414
});
1515
});
1616
</script>

0 commit comments

Comments
 (0)