Skip to content

Commit abe7f81

Browse files
author
Roman Lytvynenko
committed
Merge branch 'MC-31574' of https://github.com/magento-mpi/magento2ce into Tango-PR-02-25-2020-23
2 parents d4a778e + d97a419 commit abe7f81

File tree

15 files changed

+419
-5
lines changed

15 files changed

+419
-5
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Payment\Block\Transparent;
7+
8+
use Magento\Framework\UrlInterface;
9+
use Magento\Framework\View\Element\Template;
10+
use Magento\Framework\View\Element\Template\Context;
11+
12+
/**
13+
* Redirect block for register specific params in layout
14+
*/
15+
class Redirect extends Template
16+
{
17+
/**
18+
* Route path key to make redirect url.
19+
*/
20+
private const ROUTE_PATH = 'route_path';
21+
22+
/**
23+
* @var UrlInterface
24+
*/
25+
private $url;
26+
27+
/**
28+
* @param Context $context
29+
* @param UrlInterface $url
30+
* @param array $data
31+
*/
32+
public function __construct(
33+
Context $context,
34+
UrlInterface $url,
35+
array $data = []
36+
) {
37+
$this->url = $url;
38+
parent::__construct($context, $data);
39+
}
40+
41+
/**
42+
* Returns url for redirect.
43+
*
44+
* @return string
45+
*/
46+
public function getRedirectUrl(): string
47+
{
48+
return $this->url->getUrl($this->getData(self::ROUTE_PATH));
49+
}
50+
51+
/**
52+
* Returns params to be redirected.
53+
*
54+
* @return array
55+
*/
56+
public function getPostParams(): array
57+
{
58+
return (array)$this->_request->getPostValue();
59+
}
60+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/** @var \Magento\Payment\Block\Transparent\Redirect $block */
8+
$params = $block->getPostParams();
9+
$redirectUrl = $block->getRedirectUrl();
10+
?>
11+
<html>
12+
<head></head>
13+
<body onload="document.forms['proxy_form'].submit()">
14+
<form id="proxy_form" action="<?= $block->escapeUrl($redirectUrl) ?>"
15+
method="POST" hidden enctype="application/x-www-form-urlencoded" class="no-display">
16+
<?php foreach ($params as $name => $value):?>
17+
<input value="<?= $block->escapeHtmlAttr($value) ?>" name="<?= $block->escapeHtmlAttr($name) ?>" type="hidden"/>
18+
<?php endforeach?>
19+
</form>
20+
</body>
21+
</html>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/** @var \Magento\Payment\Block\Transparent\Redirect $block */
8+
$params = $block->getPostParams();
9+
$redirectUrl = $block->getRedirectUrl();
10+
?>
11+
<html>
12+
<head></head>
13+
<body onload="document.forms['proxy_form'].submit()">
14+
<form id="proxy_form" action="<?= $block->escapeUrl($redirectUrl) ?>"
15+
method="POST" hidden enctype="application/x-www-form-urlencoded" class="no-display">
16+
<?php foreach ($params as $name => $value):?>
17+
<input value="<?= $block->escapeHtmlAttr($value) ?>" name="<?= $block->escapeHtmlAttr($name) ?>" type="hidden"/>
18+
<?php endforeach?>
19+
</form>
20+
</body>
21+
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Paypal\Controller\Adminhtml\Transparent;
7+
8+
/**
9+
* Class for redirecting the Paypal response result to Magento controller.
10+
*/
11+
class Redirect extends \Magento\Paypal\Controller\Transparent\Redirect
12+
{
13+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Paypal\Controller\Transparent;
7+
8+
use Magento\Framework\App\Action\Context;
9+
use Magento\Framework\App\Action\HttpPostActionInterface;
10+
use Magento\Framework\App\CsrfAwareActionInterface;
11+
use Magento\Framework\App\Request\InvalidRequestException;
12+
use Magento\Framework\App\RequestInterface;
13+
use Magento\Framework\Controller\ResultInterface;
14+
use Magento\Framework\Exception\LocalizedException;
15+
use Magento\Framework\View\Result\LayoutFactory;
16+
use Magento\Payment\Model\Method\Logger;
17+
use Magento\Paypal\Model\Payflow\Transparent;
18+
19+
/**
20+
* Class for redirecting the Paypal response result to Magento controller.
21+
*/
22+
class Redirect extends \Magento\Framework\App\Action\Action implements CsrfAwareActionInterface, HttpPostActionInterface
23+
{
24+
/**
25+
* @var LayoutFactory
26+
*/
27+
private $resultLayoutFactory;
28+
29+
/**
30+
* @var Transparent
31+
*/
32+
private $transparent;
33+
34+
/**
35+
* @var Logger
36+
*/
37+
private $logger;
38+
39+
/**
40+
* Constructor
41+
*
42+
* @param Context $context
43+
* @param LayoutFactory $resultLayoutFactory
44+
* @param Transparent $transparent
45+
* @param Logger $logger
46+
*/
47+
public function __construct(
48+
Context $context,
49+
LayoutFactory $resultLayoutFactory,
50+
Transparent $transparent,
51+
Logger $logger
52+
) {
53+
$this->resultLayoutFactory = $resultLayoutFactory;
54+
$this->transparent = $transparent;
55+
$this->logger = $logger;
56+
57+
parent::__construct($context);
58+
}
59+
60+
/**
61+
* @inheritDoc
62+
*/
63+
public function createCsrfValidationException(
64+
RequestInterface $request
65+
): ?InvalidRequestException {
66+
return null;
67+
}
68+
69+
/**
70+
* @inheritDoc
71+
*/
72+
public function validateForCsrf(RequestInterface $request): ?bool
73+
{
74+
return true;
75+
}
76+
77+
/**
78+
* Saves the payment in quote
79+
*
80+
* @return ResultInterface
81+
* @throws LocalizedException
82+
*/
83+
public function execute()
84+
{
85+
$gatewayResponse = (array)$this->getRequest()->getPostValue();
86+
$this->logger->debug(
87+
['PayPal PayflowPro redirect:' => $gatewayResponse],
88+
$this->transparent->getDebugReplacePrivateDataKeys(),
89+
$this->transparent->getDebugFlag()
90+
);
91+
92+
$resultLayout = $this->resultLayoutFactory->create();
93+
$resultLayout->addDefaultHandle();
94+
$resultLayout->getLayout()->getUpdate()->load(['transparent_payment_redirect']);
95+
96+
return $resultLayout;
97+
}
98+
}

app/code/Magento/Paypal/Model/Payflow/Service/Request/SecureToken.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ public function requestToken(Quote $quote, array $urls = [])
7070
$request->setCurrency($quote->getBaseCurrencyCode());
7171
$request->setCreatesecuretoken('Y');
7272
$request->setSecuretokenid($this->mathRandom->getUniqueHash());
73-
$request->setReturnurl($urls['return_url'] ?? $this->url->getUrl('paypal/transparent/response'));
74-
$request->setErrorurl($urls['error_url'] ?? $this->url->getUrl('paypal/transparent/response'));
75-
$request->setCancelurl($urls['cancel_url'] ?? $this->url->getUrl('paypal/transparent/response'));
73+
$request->setReturnurl($urls['return_url'] ?? $this->url->getUrl('paypal/transparent/redirect'));
74+
$request->setErrorurl($urls['error_url'] ?? $this->url->getUrl('paypal/transparent/redirect'));
75+
$request->setCancelurl($urls['cancel_url'] ?? $this->url->getUrl('paypal/transparent/redirect'));
7676
$request->setDisablereceipt('TRUE');
7777
$request->setSilenttran('TRUE');
7878

app/code/Magento/Paypal/Model/Payflow/Service/Response/Transaction.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
use Magento\Sales\Api\Data\OrderPaymentInterface;
2020

2121
/**
22-
* Class Transaction
22+
* Process PayPal transaction response.
23+
*
2324
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2425
*/
2526
class Transaction
@@ -90,7 +91,7 @@ public function getResponseObject($gatewayTransactionResponse)
9091
$response = $this->transparent->mapGatewayResponse((array) $gatewayTransactionResponse, $response);
9192

9293
$this->logger->debug(
93-
(array) $gatewayTransactionResponse,
94+
['PayPal PayflowPro response:' => (array)$gatewayTransactionResponse],
9495
(array) $this->transparent->getDebugReplacePrivateDataKeys(),
9596
(bool) $this->transparent->getDebugFlag()
9697
);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Paypal\Plugin;
9+
10+
use Magento\Framework\App\Request\Http;
11+
use Magento\Framework\Session\SessionStartChecker;
12+
13+
/**
14+
* Intended to preserve session cookie after submitting POST form from PayPal to Magento controller.
15+
*/
16+
class TransparentSessionChecker
17+
{
18+
private const TRANSPARENT_REDIRECT_PATH = 'paypal/transparent/redirect';
19+
20+
/**
21+
* @var Http
22+
*/
23+
private $request;
24+
25+
/**
26+
* @param Http $request
27+
*/
28+
public function __construct(
29+
Http $request
30+
) {
31+
$this->request = $request;
32+
}
33+
34+
/**
35+
* Prevents session starting while instantiating PayPal transparent redirect controller.
36+
*
37+
* @param SessionStartChecker $subject
38+
* @param bool $result
39+
* @return bool
40+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
41+
*/
42+
public function afterCheck(SessionStartChecker $subject, bool $result): bool
43+
{
44+
if ($result === false) {
45+
return false;
46+
}
47+
48+
return strpos((string)$this->request->getPathInfo(), self::TRANSPARENT_REDIRECT_PATH) === false;
49+
}
50+
}

app/code/Magento/Paypal/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,7 @@
252252
</argument>
253253
</arguments>
254254
</type>
255+
<type name="Magento\Framework\Session\SessionStartChecker">
256+
<plugin name="transparent_session_checker" type="Magento\Paypal\Plugin\TransparentSessionChecker"/>
257+
</type>
255258
</config>

app/code/Magento/Paypal/etc/frontend/page_types.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<type id="paypal_payflow_form" label="Paypal Payflow Form"/>
1515
<type id="transparent" label="Paypal Payflow TR Form"/>
1616
<type id="transparent_payment_response" label="Paypal Payflow TR Response"/>
17+
<type id="transparent_payment_redirect" label="Paypal Payflow TR Redirect"/>
1718
<type id="paypal_payflow_returnurl" label="Paypal Payflow Return URL"/>
1819
<type id="paypal_payflowadvanced_cancelpayment" label="Paypal Payflow Advanced Cancel Payment"/>
1920
<type id="paypal_payflowadvanced_form" label="Paypal Payflow Advanced Form"/>

0 commit comments

Comments
 (0)