diff --git a/assets/wizards/readerRevenue/views/stripe-setup/index.js b/assets/wizards/readerRevenue/views/stripe-setup/index.js index 7282984ac9..31a5d9556e 100644 --- a/assets/wizards/readerRevenue/views/stripe-setup/index.js +++ b/assets/wizards/readerRevenue/views/stripe-setup/index.js @@ -115,6 +115,11 @@ const StripeSetup = () => { country_state_fields = [], } = Wizard.useWizardData( 'reader-revenue' ); + const hasWebhook = + data.webhook_url && + Array.isArray( data.webhooks ) && + data.webhooks.filter( webhook => webhook.url === data.webhook_url ).length > 0; + const [ isLoading, setIsLoading ] = useState( false ); const createWebhooks = () => { setIsLoading( true ); @@ -257,8 +262,16 @@ const StripeSetup = () => { ) } - - { __( 'Create Webhooks', 'newspack' ) } + { hasWebhook && ( + { __( 'Webhooks have already been created.', 'newspack' ) } + ) } + + { __( 'Create Webhook', 'newspack' ) } > diff --git a/includes/reader-revenue/class-stripe-connection.php b/includes/reader-revenue/class-stripe-connection.php index 04c114a55a..475260034c 100644 --- a/includes/reader-revenue/class-stripe-connection.php +++ b/includes/reader-revenue/class-stripe-connection.php @@ -420,6 +420,13 @@ public static function receive_webhook( $request ) { } } + /** + * Get URL of the webhook for this site. + */ + public static function get_webhook_url() { + return get_rest_url( null, NEWSPACK_API_NAMESPACE . '/stripe/webhook' ); + } + /** * Create Stripe webhooks. */ @@ -428,7 +435,7 @@ public static function create_webhooks() { try { $webhook = $stripe->webhookEndpoints->create( [ - 'url' => get_rest_url( null, NEWSPACK_API_NAMESPACE . '/stripe/webhook' ), + 'url' => self::get_webhook_url(), 'enabled_events' => [ 'charge.failed', 'charge.succeeded', diff --git a/includes/wizards/class-reader-revenue-wizard.php b/includes/wizards/class-reader-revenue-wizard.php index 927acc7e59..3f0bd44587 100644 --- a/includes/wizards/class-reader-revenue-wizard.php +++ b/includes/wizards/class-reader-revenue-wizard.php @@ -473,6 +473,7 @@ public function fetch_all_data() { $args['platform_data'] = wp_parse_args( $nrh_config, $args['platform_data'] ); } elseif ( Donations::is_platform_stripe() ) { $args['stripe_data']['webhooks'] = Stripe_Connection::list_webhooks(); + $args['stripe_data']['webhook_url'] = Stripe_Connection::get_webhook_url(); $args['stripe_data']['connection_error'] = Stripe_Connection::get_connection_error(); } return $args;
{ __( 'Webhooks have already been created.', 'newspack' ) }