Guest User

Untitled

a guest
May 26th, 2021
48
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 Name\Module\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. const TRANSPARENT_REDIRECT_PATH = 'test/checkout/redirectBack'; //The path to the controller that handles your return
  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. return strpos((string)$this->request->getPathInfo(), self::TRANSPARENT_REDIRECT_PATH) === false;
  48. }
  49. }
  50.  
RAW Paste Data