diff --git a/classes/gateways/class.pmprogateway_stripe.php b/classes/gateways/class.pmprogateway_stripe.php index cb242fd57..06a15e103 100644 --- a/classes/gateways/class.pmprogateway_stripe.php +++ b/classes/gateways/class.pmprogateway_stripe.php @@ -123,10 +123,6 @@ public static function init() { 'pmpro_payment_option_fields' ), 10, 2 ); - // Show webhook setup banner on payment settings page. - add_action( 'update_option_pmpro_stripe_payment_flow', array( 'PMProGateway_stripe', 'update_option_pmpro_stripe_payment_flow' ), 10, 1 ); - add_action( 'pmpro_payment_option_fields', array( 'PMProGateway_stripe', 'show_set_up_webhooks_popup' ) ); - //old global RE showing billing address or not global $pmpro_stripe_lite; $pmpro_stripe_lite = apply_filters( "pmpro_stripe_lite", ! get_option( "pmpro_stripe_billingaddress" ) ); //default is opposite of the stripe_billingaddress setting @@ -303,16 +299,12 @@ public static function pmpro_payment_option_fields( $values, $gateway ) { $stripe->show_connect_payment_option_fields( true, $values, $gateway ); // Show live connect fields. $stripe->show_connect_payment_option_fields( false, $values, $gateway ); // Show sandbox connect fields. - if ( self::using_legacy_keys() ) { - // Check if webhook is enabled or not. - $webhook = $stripe->does_webhook_exist(); - - // Check to see if events are missing. - if ( is_array( $webhook ) && isset( $webhook['enabled_events'] ) ) { - $events = $stripe->check_missing_webhook_events( $webhook['enabled_events'] ); - if ( $events ) { - $stripe->update_webhook_events(); - } + // If we have a webhook, make sure it has all the necessary events. + $webhook = $stripe->does_webhook_exist(); + if ( is_array( $webhook ) && isset( $webhook['enabled_events'] ) ) { + $events = $stripe->check_missing_webhook_events( $webhook['enabled_events'] ); + if ( $events ) { + $stripe->update_webhook_events(); } } @@ -369,12 +361,26 @@ public static function pmpro_payment_option_fields( $values, $gateway ) { - show_legacy_keys_settings() ) { ?>style="display: none;"> + style="display: none;"> + +
+

+ + + style="display: none;"> + + + + +

get_site_webhook_url() ); ?>

+ + + style="display: none;"> - + - show_legacy_keys_settings()) { ?> + show_legacy_keys_settings() ) { ?> + } else { ?>

@@ -406,25 +412,18 @@ public static function pmpro_payment_option_fields( $values, $gateway ) { -

: - get_site_webhook_url() ); ?>

- - - style="display: none;"> - -
-

style="display: none;"> - + + + + get_secretkey() ) ) { $required_webhook_events = self::webhook_events(); sort( $required_webhook_events ); - $webhook_event_data = array(); - $failed_webhooks = array(); $missing_webhooks = array(); $working_webhooks = array(); @@ -526,8 +525,6 @@ public static function pmpro_payment_option_fields( $values, $gateway ) { -

: - get_site_webhook_url() ); ?>

style="display: none;"> @@ -695,11 +692,7 @@ public static function pmpro_payment_option_fields( $values, $gateway ) { * AJAX callback to create webhooks. */ public static function wp_ajax_pmpro_stripe_create_webhook( $silent = false ) { - $secretkey = sanitize_text_field( $_REQUEST['secretkey'] ); - $stripe = new PMProGateway_stripe(); - Stripe\Stripe::setApiKey( $secretkey ); - $update_webhook_response = $stripe->update_webhook_events(); if ( empty( $update_webhook_response ) || is_wp_error( $update_webhook_response ) ) { @@ -731,11 +724,7 @@ public static function wp_ajax_pmpro_stripe_create_webhook( $silent = false ) { * AJAX callback to disable webhooks. */ public static function wp_ajax_pmpro_stripe_delete_webhook( $silent = false ) { - $secretkey = sanitize_text_field( $_REQUEST['secretkey'] ); - $stripe = new PMProGateway_stripe(); - Stripe\Stripe::setApiKey( $secretkey ); - $webhook = $stripe->does_webhook_exist(); $r = array( @@ -1196,8 +1185,9 @@ public static function stripe_connect_save_options() { unset( $_GET['pmpro_stripe_access_token'] ); unset( $_GET['pmpro_stripe_publishable_key'] ); - // Set a transient to show a banner to set up webhooks on the next page load. - set_transient( 'pmpro_stripe_connect_show_webhook_set_up_banner', true, 60 ); + // Set up a webhook if needed. + $stripe = new PMProGateway_stripe(); + $stripe->update_webhook_events(); wp_redirect( admin_url( sprintf( 'admin.php?%s', http_build_query( $_GET ) ) ) ); exit; @@ -1280,10 +1270,12 @@ public static function stripe_connect_deauthorize() { * If the checkout flow has changed to Stripe Checkout, remember to show a banner to set up webhooks. * * @since 2.12 + * @deprecated TBD * * @param string $old_value The old value of the option. */ public static function update_option_pmpro_stripe_payment_flow( $old_value ) { + _deprecated_function( __FUNCTION__, 'TBD' ); global $pmpro_stripe_old_payment_flow; $pmpro_stripe_old_payment_flow = empty( $old_value ) ? 'onsite' : $old_value; } @@ -1292,8 +1284,11 @@ public static function update_option_pmpro_stripe_payment_flow( $old_value ) { * Show a modal to the user after connecting to Stripe or switching to Stripe Checkout. * * @since 2.12 + * @deprecated TBD */ public static function show_set_up_webhooks_popup() { + _deprecated_function( __FUNCTION__, 'TBD' ); + global $pmpro_stripe_old_payment_flow; // Figure out if we need to show a popup.