Skip to content

Commit 830bea6

Browse files
authored
New filter to allow captcha validation when adding setup intents (#4733)
* New filter to allow captcha validation when adding setup intents * Adding filter doc
1 parent 46d6a8b commit 830bea6

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Changelog ***
22

33
= 10.1.0 - xxxx-xx-xx =
4+
* Add - Add a new filter allowing third-party plugins to hook captcha solutions when creating and confirming setup intents
45
* Dev - Add track events when clicking the "Reconnect to Stripe" button (both in the settings page and the admin notice)
56
* Update - Removes unnecessary legacy checkout gateway instantiations and UPE disablement code
67
* Dev - Renames previous Order Helper class methods to use the `_id` suffix

includes/class-wc-stripe-intent-controller.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,14 +1198,24 @@ public function create_and_confirm_setup_intent_ajax() {
11981198
}
11991199

12001200
$is_nonce_valid = check_ajax_referer( 'wc_stripe_create_and_confirm_setup_intent_nonce', false, false );
1201-
12021201
if ( ! $is_nonce_valid ) {
12031202
throw new WC_Stripe_Exception( 'Invalid nonce.', __( 'Unable to verify your request. Please refresh the page and try again.', 'woocommerce-gateway-stripe' ) );
12041203
}
12051204

1205+
/**
1206+
* Filter to validate captcha for create and confirm setup intent requests.
1207+
* Can be used by third-party plugins to add captcha validation.
1208+
*
1209+
* @since 10.1.0
1210+
* @param bool $is_captcha_valid True if the captcha is valid, false otherwise. Default is true.
1211+
*/
1212+
$is_captcha_valid = apply_filters( 'wc_stripe_is_valid_create_and_confirm_setup_intent_captcha', true );
1213+
if ( ! $is_captcha_valid ) {
1214+
throw new WC_Stripe_Exception( 'captcha_invalid', __( 'Captcha verification failed. Please try again.', 'woocommerce-gateway-stripe' ) );
1215+
}
1216+
12061217
$payment_method = sanitize_text_field( wp_unslash( $_POST['wc-stripe-payment-method'] ?? '' ) );
12071218
$payment_type = sanitize_text_field( wp_unslash( $_POST['wc-stripe-payment-type'] ?? WC_Stripe_Payment_Methods::CARD ) );
1208-
12091219
if ( ! $payment_method ) {
12101220
throw new WC_Stripe_Exception( 'Payment method missing from request.', __( "We're not able to add this payment method. Please refresh the page and try again.", 'woocommerce-gateway-stripe' ) );
12111221
}

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
111111
== Changelog ==
112112

113113
= 10.1.0 - xxxx-xx-xx =
114+
* Add - Add a new filter allowing third-party plugins to hook captcha solutions when creating and confirming setup intents
114115
* Dev - Add track events when clicking the "Reconnect to Stripe" button (both in the settings page and the admin notice)
115116
* Update - Removes unnecessary legacy checkout gateway instantiations and UPE disablement code
116117
* Dev - Renames previous Order Helper class methods to use the `_id` suffix

0 commit comments

Comments
 (0)