Skip to content

Commit d50c10c

Browse files
author
Oleksandr Dubovyk
committed
Merge remote-tracking branch 'local/MC-39861' into PRodubovyk20201222
2 parents 6f55864 + b955411 commit d50c10c

File tree

3 files changed

+69
-7
lines changed

3 files changed

+69
-7
lines changed

app/code/Magento/Paypal/Controller/Hostedpro/ReturnAction.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ class ReturnAction extends Action implements CsrfAwareActionInterface, HttpPostA
2626
*/
2727
public function execute()
2828
{
29-
$session = $this->_objectManager->get(\Magento\Checkout\Model\Session::class);
30-
//TODO: some actions with order
31-
if ($session->getLastRealOrderId()) {
32-
$this->_redirect('checkout/onepage/success');
33-
}
29+
$this->_redirect('checkout/onepage/success');
3430
}
3531

3632
/**

app/code/Magento/Paypal/Plugin/TransparentSessionChecker.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
*/
1616
class TransparentSessionChecker
1717
{
18-
private const TRANSPARENT_REDIRECT_PATH = 'paypal/transparent/redirect';
18+
/**
19+
* @var string[]
20+
*/
21+
private $disableSessionUrls = [
22+
'paypal/transparent/redirect',
23+
'paypal/hostedpro/return',
24+
];
1925

2026
/**
2127
* @var Http
@@ -45,6 +51,12 @@ public function afterCheck(SessionStartChecker $subject, bool $result): bool
4551
return false;
4652
}
4753

48-
return strpos((string)$this->request->getPathInfo(), self::TRANSPARENT_REDIRECT_PATH) === false;
54+
foreach ($this->disableSessionUrls as $url) {
55+
if (strpos((string)$this->request->getPathInfo(), $url) !== false) {
56+
return false;
57+
}
58+
}
59+
60+
return true;
4961
}
5062
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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\Controller\Hostedpro;
9+
10+
use Magento\TestFramework\TestCase\AbstractController;
11+
use Laminas\Stdlib\Parameters;
12+
13+
/**
14+
* Tests PayPal HostedPro return controller.
15+
*/
16+
class ReturnActionTest extends AbstractController
17+
{
18+
/**
19+
* Tests customer redirect on success page after return from PayPal HostedPro payment.
20+
*
21+
* @SuppressWarnings(PHPMD.Superglobals)
22+
*/
23+
public function testReturnRedirect()
24+
{
25+
$redirectUri = 'paypal/hostedpro/return';
26+
$this->setRequestUri($redirectUri);
27+
$this->getRequest()->setMethod('POST');
28+
29+
$this->dispatch($redirectUri);
30+
$this->assertRedirect($this->stringContains('checkout/onepage/success'));
31+
32+
$this->assertEmpty(
33+
$_SESSION,
34+
'Session start has to be skipped for current controller'
35+
);
36+
}
37+
38+
/**
39+
* Sets REQUEST_URI into request object.
40+
*
41+
* @param string $requestUri
42+
* @return void
43+
*/
44+
private function setRequestUri(string $requestUri)
45+
{
46+
$request = $this->getRequest();
47+
$reflection = new \ReflectionClass($request);
48+
$property = $reflection->getProperty('requestUri');
49+
$property->setAccessible(true);
50+
$property->setValue($request, null);
51+
52+
$request->setServer(new Parameters(['REQUEST_URI' => $requestUri]));
53+
}
54+
}

0 commit comments

Comments
 (0)