eck if webhook already exists. * * @since 1.9.5 * * @return array */ private function webhook_exists(): array { try { $response = $this->client->getWebhookSubscriptionsApi()->listWebhookSubscriptions(); if ( ! $response->isSuccess() || empty( $response->getResult()->getSubscriptions() ) ) { return []; } foreach ( $response->getResult()->getSubscriptions() as $subscription ) { if ( $subscription->getNotificationUrl() !== Helpers::get_webhook_url() ) { continue; } $signature = $this->client->getWebhookSubscriptionsApi()->retrieveWebhookSubscription( $subscription->getId() ); return $signature->isSuccess() ? [ 'id' => $signature->getResult()->getSubscription()->getId(), 'signature_key' => $signature->getResult()->getSubscription()->getSignatureKey(), ] : []; } } catch ( Exception $e ) { return []; } return []; } /** * Save webhook settings. * * @since 1.9.5 * * @param array $webhook Webhook endpoint. */ private function save_settings( array $webhook ) { $mode = Helpers::get_mode(); $settings = (array) get_option( 'wpforms_settings', [] ); // Save webhooks endpoint ID and secret. $settings[ 'square-webhooks-id-' . $mode ] = sanitize_text_field( $webhook['id'] ); $settings[ 'square-webhooks-secret-' . $mode ] = sanitize_text_field( $webhook['signature_key'] ); WebhooksHealthCheck::save_status( WebhooksHealthCheck::ENDPOINT_OPTION, WebhooksHealthCheck::STATUS_OK ); // Enable webhooks setting shouldn't be rewritten. if ( empty( $settings['square-webhooks-enabled'] ) ) { $settings['square-webhooks-enabled'] = true; } update_option( 'wpforms_settings', $settings ); } }