Skip to content

Commit b6b38d5

Browse files
committed
Merge remote-tracking branch 'origin/MC-31573' into 2.4-develop-pr16
2 parents d178e25 + 45b9e19 commit b6b38d5

File tree

14 files changed

+419
-5
lines changed

14 files changed

+419
-5
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
* @api
16+
*/
17+
class Redirect extends Template
18+
{
19+
/**
20+
* Route path key to make redirect url.
21+
*/
22+
private const ROUTE_PATH = 'route_path';
23+
24+
/**
25+
* @var UrlInterface
26+
*/
27+
private $url;
28+
29+
/**
30+
* @param Context $context
31+
* @param UrlInterface $url
32+
* @param array $data
33+
*/
34+
public function __construct(
35+
Context $context,
36+
UrlInterface $url,
37+
array $data = []
38+
) {
39+
$this->url = $url;
40+
parent::__construct($context, $data);
41+
}
42+
43+
/**
44+
* Returns url for redirect.
45+
*
46+
* @return string
47+
*/
48+
public function getRedirectUrl(): string
49+
{
50+
return $this->url->getUrl($this->getData(self::ROUTE_PATH));
51+
}
52+
53+
/**
54+
* Returns params to be redirected.
55+
*
56+
* @return array
57+
*/
58+
public function getPostParams(): array
59+
{
60+
return (array)$this->_request->getPostValue();
61+
}
62+
}
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: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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\Action;
9+
use Magento\Framework\App\Action\Context;
10+
use Magento\Framework\App\Action\HttpPostActionInterface;
11+
use Magento\Framework\App\CsrfAwareActionInterface;
12+
use Magento\Framework\App\Request\InvalidRequestException;
13+
use Magento\Framework\App\RequestInterface;
14+
use Magento\Framework\Controller\ResultInterface;
15+
use Magento\Framework\Exception\LocalizedException;
16+
use Magento\Framework\View\Result\LayoutFactory;
17+
use Magento\Payment\Model\Method\Logger;
18+
use Magento\Paypal\Model\Payflow\Transparent;
19+
20+
/**
21+
* Class for redirecting the Paypal response result to Magento controller.
22+
*/
23+
class Redirect extends Action implements CsrfAwareActionInterface, HttpPostActionInterface
24+
{
25+
/**
26+
* @var LayoutFactory
27+
*/
28+
private $resultLayoutFactory;
29+
30+
/**
31+
* @var Transparent
32+
*/
33+
private $transparent;
34+
35+
/**
36+
* @var Logger
37+
*/
38+
private $logger;
39+
40+
/**
41+
* @param Context $context
42+
* @param LayoutFactory $resultLayoutFactory
43+
* @param Transparent $transparent
44+
* @param Logger $logger
45+
*/
46+
public function __construct(
47+
Context $context,
48+
LayoutFactory $resultLayoutFactory,
49+
Transparent $transparent,
50+
Logger $logger
51+
) {
52+
$this->resultLayoutFactory = $resultLayoutFactory;
53+
$this->transparent = $transparent;
54+
$this->logger = $logger;
55+
56+
parent::__construct($context);
57+
}
58+
59+
/**
60+
* @inheritdoc
61+
*/
62+
public function createCsrfValidationException(
63+
RequestInterface $request
64+
): ?InvalidRequestException {
65+
return null;
66+
}
67+
68+
/**
69+
* @inheritdoc
70+
*/
71+
public function validateForCsrf(RequestInterface $request): ?bool
72+
{
73+
return true;
74+
}
75+
76+
/**
77+
* Saves the payment in quote
78+
*
79+
* @return ResultInterface
80+
* @throws LocalizedException
81+
*/
82+
public function execute()
83+
{
84+
$gatewayResponse = (array)$this->getRequest()->getPostValue();
85+
$this->logger->debug(
86+
['PayPal PayflowPro redirect:' => $gatewayResponse],
87+
$this->transparent->getDebugReplacePrivateDataKeys(),
88+
$this->transparent->getDebugFlag()
89+
);
90+
91+
$resultLayout = $this->resultLayoutFactory->create();
92+
$resultLayout->addDefaultHandle();
93+
$resultLayout->getLayout()->getUpdate()->load(['transparent_payment_redirect']);
94+
95+
return $resultLayout;
96+
}
97+
}

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)