Skip to content

Commit cb74b27

Browse files
author
Joan He
committed
MAGETWO-94865: Case is not showing up in Signfyd for Guest Checkout using PayPal Payments Pro Hosted Solution
1 parent b55989d commit cb74b27

File tree

2 files changed

+91
-16
lines changed

2 files changed

+91
-16
lines changed

app/code/Magento/Paypal/Controller/Ipn/Index.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
namespace Magento\Paypal\Controller\Ipn;
99

1010
use Magento\Framework\App\CsrfAwareActionInterface;
11+
use Magento\Framework\App\ObjectManager;
1112
use Magento\Framework\App\Request\InvalidRequestException;
1213
use Magento\Framework\App\RequestInterface;
1314
use Magento\Framework\Exception\RemoteServiceUnavailableException;
15+
Use Magento\Sales\Model\OrderFactory;
1416

1517
/**
1618
* Unified IPN controller for all supported PayPal methods
@@ -27,18 +29,26 @@ class Index extends \Magento\Framework\App\Action\Action implements CsrfAwareAct
2729
*/
2830
protected $_ipnFactory;
2931

32+
/**
33+
* @var OrderFactory
34+
*/
35+
private $orderFactory;
36+
3037
/**
3138
* @param \Magento\Framework\App\Action\Context $context
3239
* @param \Magento\Paypal\Model\IpnFactory $ipnFactory
3340
* @param \Psr\Log\LoggerInterface $logger
41+
* @param OrderFactory $orderFactory
3442
*/
3543
public function __construct(
3644
\Magento\Framework\App\Action\Context $context,
3745
\Magento\Paypal\Model\IpnFactory $ipnFactory,
38-
\Psr\Log\LoggerInterface $logger
46+
\Psr\Log\LoggerInterface $logger,
47+
OrderFactory $orderFactory = null
3948
) {
4049
$this->_logger = $logger;
4150
$this->_ipnFactory = $ipnFactory;
51+
$this->orderFactory = $orderFactory ?: ObjectManager::getInstance()->get(OrderFactory::class);
4252
parent::__construct($context);
4353
}
4454

@@ -74,6 +84,13 @@ public function execute()
7484
try {
7585
$data = $this->getRequest()->getPostValue();
7686
$this->_ipnFactory->create(['data' => $data])->processIpnRequest();
87+
$incrementId = $this->getRequest()->getPostValue()['invoice'];
88+
$this->_eventManager->dispatch(
89+
'paypal_checkout_success',
90+
[
91+
'order' => $this->orderFactory->create()->loadByIncrementId($incrementId)
92+
]
93+
);
7794
} catch (RemoteServiceUnavailableException $e) {
7895
$this->_logger->critical($e);
7996
$this->getResponse()->setStatusHeader(503, '1.1', 'Service Unavailable')->sendResponse();

app/code/Magento/Paypal/Test/Unit/Controller/Ipn/IndexTest.php

Lines changed: 73 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,102 @@
66

77
namespace Magento\Paypal\Test\Unit\Controller\Ipn;
88

9+
use Magento\Framework\Event\ManagerInterface;
10+
use Magento\Paypal\Controller\Ipn\Index;
11+
use Magento\Paypal\Model\IpnFactory;
12+
use Magento\Paypal\Model\IpnInterface;
13+
use Magento\Sales\Model\Order;
14+
use Magento\Sales\Model\OrderFactory;
15+
916
class IndexTest extends \PHPUnit\Framework\TestCase
1017
{
1118
/** @var Index */
12-
protected $model;
19+
private $model;
1320

1421
/** @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject */
15-
protected $logger;
22+
private $loggerMock;
1623

1724
/** @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject */
18-
protected $request;
25+
private $requestMock;
1926

2027
/** @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject */
21-
protected $response;
28+
private $responseMock;
29+
30+
/**
31+
* @var IpnFactory|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
private $ipnFactoryMock;
34+
35+
/**
36+
* @var OrderFactory|\PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
private $orderFactoryMock;
39+
40+
/**
41+
* @var ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
42+
*/
43+
private $eventManagerMock;
2244

2345
protected function setUp()
2446
{
25-
$this->logger = $this->createMock(\Psr\Log\LoggerInterface::class);
26-
$this->request = $this->createMock(\Magento\Framework\App\Request\Http::class);
27-
$this->response = $this->createMock(\Magento\Framework\App\Response\Http::class);
47+
$this->loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
48+
$this->requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class);
49+
$this->responseMock = $this->createMock(\Magento\Framework\App\Response\Http::class);
50+
$this->ipnFactoryMock = $this->createMock(IpnFactory::class);
51+
$this->orderFactoryMock = $this->createMock(OrderFactory::class);
52+
$this->eventManagerMock = $this->createMock(ManagerInterface::class);
2853

2954
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
3055
$this->model = $objectManagerHelper->getObject(
31-
\Magento\Paypal\Controller\Ipn\Index::class,
56+
Index::class,
3257
[
33-
'logger' => $this->logger,
34-
'request' => $this->request,
35-
'response' => $this->response,
58+
'logger' => $this->loggerMock,
59+
'request' => $this->requestMock,
60+
'response' => $this->responseMock,
61+
'ipnFactory' => $this->ipnFactoryMock,
62+
'orderFactory' => $this->orderFactoryMock,
63+
'eventManager' => $this->eventManagerMock
3664
]
3765
);
3866
}
3967

4068
public function testIndexActionException()
4169
{
42-
$this->request->expects($this->once())->method('isPost')->will($this->returnValue(true));
70+
$this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue(true));
4371
$exception = new \Exception();
44-
$this->request->expects($this->once())->method('getPostValue')->will($this->throwException($exception));
45-
$this->logger->expects($this->once())->method('critical')->with($this->identicalTo($exception));
46-
$this->response->expects($this->once())->method('setHttpResponseCode')->with(500);
72+
$this->requestMock->expects($this->once())->method('getPostValue')->will($this->throwException($exception));
73+
$this->loggerMock->expects($this->once())->method('critical')->with($this->identicalTo($exception));
74+
$this->responseMock->expects($this->once())->method('setHttpResponseCode')->with(500);
75+
$this->model->execute();
76+
}
77+
78+
public function testIndexAction()
79+
{
80+
$this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue(true));
81+
$incrementId = 'incrementId';
82+
$data = [
83+
'invoice' => $incrementId,
84+
'other' => 'other data'
85+
];
86+
$this->requestMock->expects($this->exactly(2))->method('getPostValue')->willReturn($data);
87+
$ipnMock = $this->createMock(IpnInterface::class);
88+
$this->ipnFactoryMock->expects($this->once())
89+
->method('create')
90+
->with(['data' => $data])
91+
->willReturn($ipnMock);
92+
$ipnMock->expects($this->once())
93+
->method('processIpnRequest');
94+
$orderMock = $this->createMock(Order::class);
95+
$this->orderFactoryMock->expects($this->once())
96+
->method('create')
97+
->willReturn($orderMock);
98+
$orderMock->expects($this->once())
99+
->method('loadByIncrementId')
100+
->with($incrementId)
101+
->willReturn($orderMock);
102+
$this->eventManagerMock->expects($this->once())
103+
->method('dispatch')
104+
->with('paypal_checkout_success', ['order' => $orderMock]);
47105
$this->model->execute();
48106
}
49107
}

0 commit comments

Comments
 (0)