88use Adyen \Payment \Model \Notification ;
99use Adyen \Webhook \PaymentStates ;
1010use Magento \Framework \Exception \LocalizedException ;
11+ use Magento \Quote \Api \CartRepositoryInterface ;
12+ use Magento \Quote \Model \Quote ;
1113use Magento \Sales \Model \Order ;
1214use PHPUnit \Framework \MockObject \MockObject ;
1315use Adyen \Payment \Helper \Order as OrderHelper ;
@@ -27,6 +29,7 @@ class AuthorisationWebhookHandlerTest extends AbstractAdyenTestCase
2729 private AdyenAmountCurrency |MockObject $ orderAmountCurrency ;
2830 private Notification |MockObject $ notificationMock ;
2931 private Order |MockObject $ orderMock ;
32+ private Quote |MockObject $ quoteMock ;
3033
3134 protected function setUp (): void
3235 {
@@ -54,6 +57,7 @@ protected function setUp(): void
5457 'getPaymentMethod ' => $ paymentMethod ,
5558 'isSuccessful ' => true
5659 ]);
60+ $ this ->quoteMock = $ this ->createMock (Quote::class);
5761 }
5862
5963 /**
@@ -89,6 +93,9 @@ public function testHandleWebhook(): void
8993
9094 $ transitionState = PaymentStates::STATE_PAID ;
9195
96+ $ cartRepositoryMock = $ this ->createMock (CartRepositoryInterface::class);
97+ $ cartRepositoryMock ->expects ($ this ->once ())->method ('get ' )->willReturn ($ this ->quoteMock );
98+
9299 $ handler = $ this ->createAuthorisationWebhookHandler (
93100 null ,
94101 $ this ->orderHelperMock ,
@@ -98,7 +105,8 @@ public function testHandleWebhook(): void
98105 $ mockChargedCurrency ,
99106 null ,
100107 null ,
101- $ paymentMethodsHelperMock
108+ $ paymentMethodsHelperMock ,
109+ $ cartRepositoryMock
102110 );
103111
104112 // Call the function to be tested
@@ -160,6 +168,9 @@ public function testHandleSuccessfulAuthorisation($isAutoCapture): void
160168 ]
161169 );
162170
171+ $ cartRepositoryMock = $ this ->createMock (CartRepositoryInterface::class);
172+ $ cartRepositoryMock ->expects ($ this ->once ())->method ('get ' )->willReturn ($ this ->quoteMock );
173+
163174 $ authorisationWebhookHandler = $ this ->createAuthorisationWebhookHandler (
164175 $ this ->adyenOrderPaymentMock ,
165176 $ this ->orderHelperMock ,
@@ -169,7 +180,8 @@ public function testHandleSuccessfulAuthorisation($isAutoCapture): void
169180 $ mockChargedCurrency ,
170181 null ,
171182 null ,
172- $ paymentMethodsMock
183+ $ paymentMethodsMock ,
184+ $ cartRepositoryMock
173185 );
174186
175187 // Invoke the private method
@@ -257,6 +269,36 @@ public function testHandleAutoCapture(): void
257269 $ this ->assertInstanceOf (Order::class, $ result );
258270 }
259271
272+ public function testDisableQuote ()
273+ {
274+ $ this ->orderMock ->expects ($ this ->any ())->method ('getPayment ' )->willReturn ($ this ->orderMock );
275+ $ this ->orderMock ->expects ($ this ->any ())->method ('getConfig ' )->willReturnSelf ();
276+
277+ $ this ->quoteMock ->expects ($ this ->any ())->method ('getIsActive ' )->willReturn (true );
278+ $ this ->quoteMock ->expects ($ this ->any ())->method ('setIsActive ' )->with (false );
279+
280+ $ cartRepositoryMock = $ this ->createMock (CartRepositoryInterface::class);
281+ $ cartRepositoryMock ->expects ($ this ->once ())->method ('get ' )->willReturn ($ this ->quoteMock );
282+ $ cartRepositoryMock ->expects ($ this ->once ())->method ('save ' )->with ($ this ->quoteMock );
283+
284+ // Create an instance of AuthorisationWebhookHandler
285+ $ webhookHandler = $ this ->createAuthorisationWebhookHandler (
286+ null ,
287+ null ,
288+ null ,
289+ null ,
290+ null ,
291+ null ,
292+ null ,
293+ null ,
294+ null ,
295+ $ cartRepositoryMock
296+ );
297+
298+ $ result = $ webhookHandler ->handleWebhook ($ this ->orderMock , $ this ->notificationMock , 'paid ' );
299+ $ this ->assertInstanceOf (Order::class, $ result );
300+ }
301+
260302 /**
261303 * @throws ReflectionExceptionAlias
262304 */
@@ -358,9 +400,9 @@ protected function createAuthorisationWebhookHandler(
358400 $ mockChargedCurrency = null ,
359401 $ mockConfigHelper = null ,
360402 $ mockInvoiceHelper = null ,
361- $ mockPaymentMethodsHelper = null
362- ): AuthorisationWebhookHandler
363- {
403+ $ mockPaymentMethodsHelper = null ,
404+ $ mockCartRepositoryMock = null
405+ ): AuthorisationWebhookHandler {
364406 if (is_null ($ mockAdyenOrderPayment )) {
365407 $ mockAdyenOrderPayment = $ this ->createMock (AdyenOrderPayment::class);
366408 }
@@ -397,6 +439,10 @@ protected function createAuthorisationWebhookHandler(
397439 $ mockPaymentMethodsHelper = $ this ->createMock (PaymentMethods::class);
398440 }
399441
442+ if (is_null ($ mockCartRepositoryMock )) {
443+ $ mockCartRepositoryMock = $ this ->createMock (CartRepositoryInterface::class);
444+ }
445+
400446 return new AuthorisationWebhookHandler (
401447 $ mockAdyenOrderPayment ,
402448 $ mockOrderHelper ,
@@ -406,7 +452,8 @@ protected function createAuthorisationWebhookHandler(
406452 $ mockChargedCurrency ,
407453 $ mockConfigHelper ,
408454 $ mockInvoiceHelper ,
409- $ mockPaymentMethodsHelper
455+ $ mockPaymentMethodsHelper ,
456+ $ mockCartRepositoryMock
410457 );
411458 }
412459}
0 commit comments