Skip to content

Commit 09739ba

Browse files
committed
AC-461: Add ReCaptcha support to coupon code
* Coupon cancel defect fixes
1 parent ba1c11c commit 09739ba

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

ReCaptchaCheckoutSalesRule/Observer/CouponCodeObserver.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ public function __construct(
6060
*/
6161
public function execute(Observer $observer): void
6262
{
63-
if ($this->isCaptchaEnabled->isCaptchaEnabledFor(self::CAPTCHA_KEY)) {
64-
/** @var Action $controller */
65-
$controller = $observer->getControllerAction();
63+
/** @var Action $controller */
64+
$controller = $observer->getControllerAction();
65+
$request_param = $controller->getRequest()->getParams();
66+
if (!isset($request_param['remove']) && $this->isCaptchaEnabled->isCaptchaEnabledFor(self::CAPTCHA_KEY)) {
6667
$request = $controller->getRequest();
6768
$response = $controller->getResponse();
6869
$redirectOnFailureUrl = $this->redirect->getRefererUrl();
69-
7070
$this->requestHandler->execute(self::CAPTCHA_KEY, $request, $response, $redirectOnFailureUrl);
7171
}
7272
}

ReCaptchaCheckoutSalesRule/Test/Integration/CouponApplyPostTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public function testGetRequestIfReCaptchaIsEnabled(): void
8181
public function testPostRequestIfReCaptchaParameterIsMissed(): void
8282
{
8383
$this->checkFailedPostRequest();
84+
$this->assertSessionMessages(
85+
$this->equalTo(['The coupon code "test" is not valid.']),
86+
MessageInterface::TYPE_ERROR
87+
);
8488
}
8589

8690
/**
@@ -96,6 +100,10 @@ public function testPostRequestIfReCaptchaParameterIsMissed(): void
96100
public function testPostRequestWithFailedReCaptchaValidation(): void
97101
{
98102
$this->checkFailedPostRequest(true);
103+
$this->assertSessionMessages(
104+
$this->equalTo(['The coupon code "test" is not valid.']),
105+
MessageInterface::TYPE_ERROR
106+
);
99107
}
100108

101109
/**
@@ -127,10 +135,6 @@ private function checkSuccessfulGetResponse(bool $shouldContainReCaptcha = false
127135
private function checkFailedPostRequest(bool $withParamReCaptcha = false): void
128136
{
129137
$this->makePostRequest($withParamReCaptcha);
130-
$this->assertSessionMessages(
131-
$this->equalTo(['Something went wrong with reCAPTCHA. Please contact the store owner.']),
132-
MessageInterface::TYPE_ERROR
133-
);
134138
}
135139

136140
/**
@@ -153,7 +157,6 @@ private function makePostRequest(bool $withParamReCaptcha = false): void
153157
$this->getRequest()
154158
->setMethod(Http::METHOD_POST)
155159
->setPostValue($postValue);
156-
157160
$this->dispatch('checkout/cart/couponPost/');
158161
}
159162

0 commit comments

Comments
 (0)