diff --git a/client/components/webhook-description/__tests__/index.test.js b/client/components/webhook-description/__tests__/index.test.js
index 33f545f8a..c38d41322 100644
--- a/client/components/webhook-description/__tests__/index.test.js
+++ b/client/components/webhook-description/__tests__/index.test.js
@@ -25,7 +25,7 @@ describe( 'WebhookDescription', () => {
};
} );
- render( );
+ render( );
expect(
screen.queryByTestId( 'webhook-information' )
@@ -44,7 +44,7 @@ describe( 'WebhookDescription', () => {
};
} );
- render( );
+ render( );
expect(
screen.queryByTestId( 'webhook-information' )
@@ -64,7 +64,7 @@ describe( 'WebhookDescription', () => {
};
} );
- render( );
+ render( );
expect(
screen.queryByTestId( 'webhook-information' )
diff --git a/client/components/webhook-description/index.js b/client/components/webhook-description/index.js
index 79c5b4846..03557653c 100644
--- a/client/components/webhook-description/index.js
+++ b/client/components/webhook-description/index.js
@@ -31,7 +31,7 @@ const WebhookDescriptionInner = styled.div`
}
`;
-export const WebhookDescription = ( { isWebhookSecretEntered } ) => {
+export const WebhookDescription = ( { isWebhookEnabled } ) => {
const {
code,
message,
@@ -40,10 +40,9 @@ export const WebhookDescription = ( { isWebhookSecretEntered } ) => {
} = useWebhookStateMessage();
const isWarningMessage = code === 3 || code === 4;
const isSuccessMessage = code === 1;
- const isSuccessMessageWithSecret =
- isSuccessMessage && isWebhookSecretEntered;
+ const isSuccessMessageWithSecret = isSuccessMessage && isWebhookEnabled;
const webhookDescriptionClassesAr = [];
- if ( isWebhookSecretEntered ) {
+ if ( isWebhookEnabled ) {
webhookDescriptionClassesAr.push( 'expanded' );
}
if ( isWarningMessage ) {
@@ -52,7 +51,7 @@ export const WebhookDescription = ( { isWebhookSecretEntered } ) => {
return (
- { ! isWebhookSecretEntered && }
+ { ! isWebhookEnabled && }
diff --git a/client/settings/account-details/index.js b/client/settings/account-details/index.js
index 29feb11df..d77cc684e 100644
--- a/client/settings/account-details/index.js
+++ b/client/settings/account-details/index.js
@@ -7,10 +7,6 @@ import styled from '@emotion/styled';
import SectionStatus from '../section-status';
import Tooltip from 'wcstripe/components/tooltip';
import { useAccount } from 'wcstripe/data/account';
-import {
- useAccountKeysTestWebhookSecret,
- useAccountKeysWebhookSecret,
-} from 'wcstripe/data/account-keys';
import { WebhookDescription } from 'wcstripe/components/webhook-description';
const AccountDetailsContainer = styled.div`
@@ -108,28 +104,20 @@ const PayoutsSection = () => {
};
const WebhooksSection = () => {
- const [ testWebhookSecret ] = useAccountKeysTestWebhookSecret();
- const [ webhookSecret ] = useAccountKeysWebhookSecret();
const { data } = useAccount();
- const isTestModeEnabled = Boolean( data.testmode );
-
- const isWebhookSecretEntered = Boolean(
- isTestModeEnabled ? testWebhookSecret : webhookSecret
- );
+ const isWebhookEnabled = Boolean( data.is_webhook_enabled );
return (
<>
-
- { isWebhookSecretEntered
+
+ { isWebhookEnabled
? __( 'Enabled', 'woocommerce-gateway-stripe' )
: __( 'Disabled', 'woocommerce-gateway-stripe' ) }
-
+
>
);
};
diff --git a/includes/admin/class-wc-rest-stripe-account-controller.php b/includes/admin/class-wc-rest-stripe-account-controller.php
index 65a9c8e03..6d3a4f54a 100644
--- a/includes/admin/class-wc-rest-stripe-account-controller.php
+++ b/includes/admin/class-wc-rest-stripe-account-controller.php
@@ -96,6 +96,7 @@ public function get_account() {
'webhook_status_message' => WC_Stripe_Webhook_State::get_webhook_status_message(),
'webhook_url' => WC_Stripe_Helper::get_webhook_url(),
'configured_webhook_urls' => WC_Stripe_Webhook_State::get_configured_webhook_urls(),
+ 'is_webhook_enabled' => WC_Stripe_Webhook_State::is_webhook_enabled(),
'oauth_connections' => [
'test' => $this->get_account_oauth_connection_data( 'test' ),
'live' => $this->get_account_oauth_connection_data( 'live' ),
diff --git a/includes/class-wc-stripe-webhook-state.php b/includes/class-wc-stripe-webhook-state.php
index bb147ccc9..196f57a6d 100644
--- a/includes/class-wc-stripe-webhook-state.php
+++ b/includes/class-wc-stripe-webhook-state.php
@@ -306,4 +306,30 @@ public static function get_configured_webhook_urls() {
'test' => empty( $test_webhook['url'] ) ? null : rawurlencode( $test_webhook['url'] ),
];
}
+
+
+ /**
+ * Determine if the webhook is enabled by checking with Stripe.
+ *
+ * @return bool
+ */
+ public static function is_webhook_enabled() {
+ error_log( 'is_webhook_enabled' );
+ $stripe_settings = WC_Stripe_Helper::get_stripe_settings();
+
+ $key = self::get_testmode() ? 'test_webhook_data' : 'webhook_data';
+ if ( ! isset( $stripe_settings[ $key ] ) ) {
+ return false;
+ }
+
+ $webhook_id = $stripe_settings[ $key ]['id'];
+ $webhook_secret = $stripe_settings[ $key ]['secret'];
+ if ( empty( $webhook_id ) || empty( $webhook_secret ) ) {
+ return false;
+ }
+
+ WC_Stripe_API::set_secret_key( $webhook_secret );
+ $webhook = WC_Stripe_API::request( [], 'webhook_endpoints/' . $webhook_id, 'GET' );
+ return ! empty( $webhook->status ) && 'enabled' === $webhook->status;
+ }
};