Skip to content

Commit 3109931

Browse files
committed
Merge remote-tracking branch 'borg/MAGETWO-94269' into 2.3-regression-pr-HB
2 parents d901ca3 + 172e3b2 commit 3109931

File tree

5 files changed

+53
-12
lines changed

5 files changed

+53
-12
lines changed

app/code/Magento/Paypal/Controller/Payflow/ReturnUrl.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function execute()
6868
if ($order->getIncrementId()) {
6969
if ($this->checkOrderState($order)) {
7070
$redirectBlock->setData('goto_success_page', true);
71+
$this->_eventManager->dispatch('paypal_checkout_success', ['order' => $order]);
7172
} else {
7273
if ($this->checkPaymentMethod($order)) {
7374
$gotoSection = $this->_cancelPayment((string)$this->getRequest()->getParam('RESPMSG'));

app/code/Magento/Paypal/Test/Unit/Controller/Payflow/ReturnUrlTest.php

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Paypal\Test\Unit\Controller\Payflow;
77

8+
use Magento\Framework\Event\ManagerInterface;
89
use Magento\Sales\Api\PaymentFailuresInterface;
910
use Magento\Checkout\Block\Onepage\Success;
1011
use Magento\Checkout\Model\Session;
@@ -96,6 +97,11 @@ class ReturnUrlTest extends \PHPUnit\Framework\TestCase
9697
*/
9798
private $paymentFailures;
9899

100+
/**
101+
* @var ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
102+
*/
103+
private $eventManagerMock;
104+
99105
/**
100106
* @inheritdoc
101107
*/
@@ -148,25 +154,31 @@ protected function setUp()
148154
->disableOriginalConstructor()
149155
->getMock();
150156

151-
$this->context->expects($this->any())->method('getView')->willReturn($this->view);
152-
$this->context->expects($this->any())->method('getRequest')->willReturn($this->request);
153-
154157
$this->paymentFailures = $this->getMockBuilder(PaymentFailuresInterface::class)
155158
->disableOriginalConstructor()
156159
->getMock();
157160

161+
$this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class)
162+
->disableOriginalConstructor()
163+
->getMock();
164+
158165
$this->context->method('getView')
159166
->willReturn($this->view);
160167
$this->context->method('getRequest')
161168
->willReturn($this->request);
162-
163-
$this->returnUrl = $this->objectManager->getObject(ReturnUrl::class, [
164-
'context' => $this->context,
165-
'checkoutSession' => $this->checkoutSession,
166-
'orderFactory' => $this->orderFactory,
167-
'checkoutHelper' => $this->checkoutHelper,
168-
'paymentFailures' => $this->paymentFailures,
169-
]);
169+
$this->context->method('getEventManager')
170+
->willReturn($this->eventManagerMock);
171+
172+
$this->returnUrl = $this->objectManager->getObject(
173+
ReturnUrl::class,
174+
[
175+
'context' => $this->context,
176+
'checkoutSession' => $this->checkoutSession,
177+
'orderFactory' => $this->orderFactory,
178+
'checkoutHelper' => $this->checkoutHelper,
179+
'paymentFailures' => $this->paymentFailures,
180+
]
181+
);
170182
}
171183

172184
/**
@@ -187,6 +199,10 @@ public function testExecuteAllowedOrderState($state)
187199
->with('goto_success_page', true)
188200
->willReturnSelf();
189201

202+
$this->eventManagerMock->expects($this->once())
203+
->method('dispatch')
204+
->with('paypal_checkout_success', $this->arrayHasKey('order'));
205+
190206
$result = $this->returnUrl->execute();
191207
$this->assertNull($result);
192208
}

app/code/Magento/Signifyd/Observer/PlaceOrder.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\Event\ObserverInterface;
1111
use Magento\Framework\Exception\AlreadyExistsException;
1212
use Magento\Sales\Api\Data\OrderInterface;
13+
use Magento\Sales\Model\Order;
1314
use Magento\Signifyd\Api\CaseCreationServiceInterface;
1415
use Magento\Signifyd\Model\Config;
1516
use Psr\Log\LoggerInterface;
@@ -80,7 +81,9 @@ public function execute(Observer $observer)
8081
private function createCaseForOrder($order)
8182
{
8283
$orderId = $order->getEntityId();
83-
if (null === $orderId || $order->getPayment()->getMethodInstance()->isOffline()) {
84+
if (null === $orderId
85+
|| $order->getPayment()->getMethodInstance()->isOffline()
86+
|| $order->getState() === Order::STATE_PENDING_PAYMENT) {
8487
return;
8588
}
8689

app/code/Magento/Signifyd/Test/Unit/Observer/PlaceOrderTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\Exception\AlreadyExistsException;
1111
use Magento\Payment\Model\MethodInterface;
1212
use Magento\Sales\Api\Data\OrderInterface;
13+
use Magento\Sales\Model\Order;
1314
use Magento\Sales\Model\Order\Payment;
1415
use Magento\Signifyd\Api\CaseCreationServiceInterface;
1516
use Magento\Signifyd\Model\Config;
@@ -193,6 +194,23 @@ public function testExecute()
193194
$this->placeOrder->execute($this->observer);
194195
}
195196

197+
public function testExecuteWithOrderPendingPayment()
198+
{
199+
$orderId = 1;
200+
$storeId = 2;
201+
202+
$this->withActiveSignifydIntegration(true, $storeId);
203+
$this->withOrderEntity($orderId, $storeId);
204+
$this->orderEntity->method('getState')
205+
->willReturn(Order::STATE_PENDING_PAYMENT);
206+
$this->withAvailablePaymentMethod(true);
207+
208+
$this->creationService->expects(self::never())
209+
->method('createForOrder');
210+
211+
$this->placeOrder->execute($this->observer);
212+
}
213+
196214
/**
197215
* Specifies order entity mock execution.
198216
*

app/code/Magento/Signifyd/etc/events.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@
1212
<event name="paypal_express_place_order_success">
1313
<observer name="signifyd_place_order_paypal_express_observer" instance="Magento\Signifyd\Observer\PlaceOrder"/>
1414
</event>
15+
<event name="paypal_checkout_success">
16+
<observer name="signifyd_place_order_checkout_success_observer" instance="Magento\Signifyd\Observer\PlaceOrder" />
17+
</event>
1518
</config>

0 commit comments

Comments
 (0)