Skip to content

Commit ccf944e

Browse files
authored
Use wp_ajax prefix for Add Payment Method page action (#4500)
* Use wp_ajax prefix for Add Payment Method page action * Add readme and changelog entries * Remove unnecessary whitespace change to unrelated file
1 parent dc52c7c commit ccf944e

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* Update - Add the number of pending webhooks to the Account status section
2727
* Fix - Prevent "Undefined array key charges_enabled" PHP warning when determining live‑mode status
2828
* Update - Deprecate `wc_gateway_stripe_process_payment`, `wc_gateway_stripe_process_redirect_payment` and `wc_gateway_stripe_process_webhook_payment` actions in favour of `wc_gateway_stripe_process_payment_charge`
29+
* Tweak - Use wp_ajax prefix for its built-in security for Add Payment Method action
2930

3031
= 9.6.0 - 2025-07-07 =
3132
* Fix - Register Express Checkout script before use to restore buttons on “order-pay” pages

client/api/index.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,13 @@ export default class WCStripeAPI {
178178
* @return {Promise} Promise containing the setup intent.
179179
*/
180180
setupIntent( paymentMethod, additionalData = {} ) {
181-
return this.request(
182-
this.getAjaxUrl( 'create_and_confirm_setup_intent' ),
183-
{
184-
...additionalData,
185-
action: 'create_and_confirm_setup_intent',
186-
'wc-stripe-payment-method': paymentMethod.id,
187-
'wc-stripe-payment-type': paymentMethod.type,
188-
_ajax_nonce: this.options?.createAndConfirmSetupIntentNonce,
189-
}
190-
).then( ( response ) => {
181+
return this.request( this.options?.wp_ajax_url, {
182+
...additionalData,
183+
action: 'wc_stripe_create_and_confirm_setup_intent',
184+
'wc-stripe-payment-method': paymentMethod.id,
185+
'wc-stripe-payment-type': paymentMethod.type,
186+
_ajax_nonce: this.options?.createAndConfirmSetupIntentNonce,
187+
} ).then( ( response ) => {
191188
if ( ! response.success ) {
192189
throw response.data.error;
193190
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public function init_hooks() {
2929
add_action( 'wc_ajax_wc_stripe_verify_intent', [ $this, 'verify_intent' ] );
3030
add_action( 'wc_ajax_wc_stripe_create_setup_intent', [ $this, 'create_setup_intent' ] );
3131

32-
add_action( 'wc_ajax_wc_stripe_create_and_confirm_setup_intent', [ $this, 'create_and_confirm_setup_intent_ajax' ] );
32+
// Use wp_ajax instead of wc_ajax to ensure only logged in users can fire this action.
33+
add_action( 'wp_ajax_wc_stripe_create_and_confirm_setup_intent', [ $this, 'create_and_confirm_setup_intent_ajax' ] );
3334

3435
add_action( 'wc_ajax_wc_stripe_create_payment_intent', [ $this, 'create_payment_intent_ajax' ] );
3536
add_action( 'wc_ajax_wc_stripe_update_payment_intent', [ $this, 'update_payment_intent_ajax' ] );

includes/payment-methods/class-wc-stripe-upe-payment-gateway.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ public function javascript_params() {
505505
$stripe_params['isCheckout'] = ( is_checkout() || has_block( 'woocommerce/checkout' ) ) && empty( $_GET['pay_for_order'] ); // wpcs: csrf ok.
506506
$stripe_params['return_url'] = $this->get_stripe_return_url();
507507
$stripe_params['ajax_url'] = WC_AJAX::get_endpoint( '%%endpoint%%' );
508+
$stripe_params['wp_ajax_url'] = admin_url( 'admin-ajax.php' );
508509
$stripe_params['theme_name'] = get_option( 'stylesheet' );
509510
$stripe_params['testMode'] = $this->testmode;
510511
$stripe_params['createPaymentIntentNonce'] = wp_create_nonce( 'wc_stripe_create_payment_intent_nonce' );

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
136136
* Update - Add the number of pending webhooks to the Account status section
137137
* Fix - Prevent "Undefined array key charges_enabled" PHP warning when determining live‑mode status
138138
* Update - Deprecate `wc_gateway_stripe_process_payment`, `wc_gateway_stripe_process_redirect_payment` and `wc_gateway_stripe_process_webhook_payment` actions in favour of `wc_gateway_stripe_process_payment_charge`
139+
* Tweak - Use wp_ajax prefix for its built-in security for Add Payment Method action
139140

140141
[See changelog for full details across versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

0 commit comments

Comments
 (0)