File tree Expand file tree Collapse file tree 3 files changed +18
-14
lines changed
ReCaptchaCheckout/view/frontend/web/js Expand file tree Collapse file tree 3 files changed +18
-14
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ define(
1818 } ,
1919
2020 /**
21- * Render reCAPTCHA
21+ * Render reCAPTCHA for payment method
2222 *
2323 * @param {Object } method
2424 */
@@ -32,7 +32,7 @@ define(
3232 } ,
3333
3434 /**
35- * Get reCAPTCHA ID
35+ * Get reCAPTCHA ID for payment method
3636 *
3737 * @param {Object } method
3838 * @returns {String }
@@ -55,12 +55,14 @@ define(
5555 * @inheritdoc
5656 */
5757 initCaptcha : function ( ) {
58- var $wrapper , $recaptchaResponseInput ;
58+ var $wrapper ,
59+ $recaptchaResponseInput ;
5960
6061 this . _super ( ) ;
61- // Since there will be multiple recaptcha in the payment form,
62- // they may override each other if the form is submitted.
63- // The recaptcha response will be collected in the callback: reCaptchaCallback()
62+ // Since there will be multiple reCaptcha in the payment form,
63+ // they may override each other if the form data is serialized and submitted.
64+ // Instead, the reCaptcha response will be collected in the callback: reCaptchaCallback()
65+ // and sent in the request header X-ReCaptcha
6466 $wrapper = $ ( '#' + this . getReCaptchaId ( ) + '-wrapper' ) ;
6567 $recaptchaResponseInput = $wrapper . find ( '[name=g-recaptcha-response]' ) ;
6668 if ( $recaptchaResponseInput . length ) {
Original file line number Diff line number Diff line change 1818class ReCaptchaSession
1919{
2020 private const PAYPAL_PAYFLOWPRO_RECAPTCHA = 'paypal_payflowpro_recaptcha ' ;
21- private const REPLAY_TIMEOUT = 120 ;
21+ private const TIMEOUT = 120 ;
2222
2323 /**
2424 * @var TimezoneInterface
@@ -51,7 +51,7 @@ public function __construct(
5151 }
5252
5353 /**
54- * Saves quote_id and datetime the reCaptcha was verified
54+ * Saves quote_id and datetime the reCaptcha was verified in session
5555 *
5656 * @return bool
5757 */
@@ -72,7 +72,7 @@ public function save(): bool
7272 }
7373
7474 /**
75- * Checks whether the reCaptcha extended time has not expired
75+ * Checks whether the time since reCaptcha was verified is not more than the timeout
7676 *
7777 * @param int $quoteId
7878 * @return bool
@@ -83,7 +83,7 @@ public function isValid(int $quoteId): bool
8383 $ data = $ this ->transparentSession ->getData (self ::PAYPAL_PAYFLOWPRO_RECAPTCHA ) ?? [];
8484 if (isset ($ data ['quote_id ' ])
8585 && (int ) $ data ['quote_id ' ] === $ quoteId
86- && ($ data ['verified_at ' ] + self ::REPLAY_TIMEOUT ) >= $ this ->timezone ->date ()->getTimestamp ()
86+ && ($ data ['verified_at ' ] + self ::TIMEOUT ) >= $ this ->timezone ->date ()->getTimestamp ()
8787 ) {
8888 $ this ->transparentSession ->unsetData (self ::PAYPAL_PAYFLOWPRO_RECAPTCHA );
8989 $ result = true ;
Original file line number Diff line number Diff line change @@ -68,10 +68,12 @@ public function afterGetConfigFor(
6868 $ bodyParams = $ this ->request ->getBodyParams ();
6969 $ paymentMethod = $ bodyParams ['paymentMethod ' ] ?? $ bodyParams ['payment_method ' ] ?? [];
7070 $ cartId = $ bodyParams ['cartId ' ] ?? $ bodyParams ['cart_id ' ] ?? null ;
71- if (isset ($ paymentMethod ['method ' ]) && $ paymentMethod ['method ' ] === Config::METHOD_PAYFLOWPRO ) {
72- if ($ cartId && $ this ->reCaptchaSession ->isValid ((int ) $ cartId )) {
73- return null ;
74- }
71+ if (isset ($ paymentMethod ['method ' ])
72+ && $ paymentMethod ['method ' ] === Config::METHOD_PAYFLOWPRO
73+ && $ cartId
74+ && $ this ->reCaptchaSession ->isValid ((int ) $ cartId )
75+ ) {
76+ return null ;
7577 }
7678 }
7779
You can’t perform that action at this time.
0 commit comments