diff --git a/inc/integrations/class-form-utils.php b/inc/integrations/class-form-utils.php index 86a1f6094..611308b9c 100644 --- a/inc/integrations/class-form-utils.php +++ b/inc/integrations/class-form-utils.php @@ -40,9 +40,14 @@ public static function generate_test_email() { 'eight', 'nine', 'ten', + 'eleven', + 'twelve', + 'thirteen', + 'fourteen', + 'fifteen', ); - $name_1 = $words[ wp_rand( 0, count( $words ) ) ]; + $name_1 = $words[ wp_rand( 0, count( $words ) - 1 ) ]; $name_2 = $words[ wp_rand( 2, count( $words ) ) - 1 ]; return "Otter-Form-successfully-connected.delete-on-confirmation.$name_1.$name_2@otter-blocks.com"; diff --git a/inc/integrations/interfaces/interface-form-subscribe-service.php b/inc/integrations/interfaces/interface-form-subscribe-service.php index 8f3b482e9..d14785f0c 100644 --- a/inc/integrations/interfaces/interface-form-subscribe-service.php +++ b/inc/integrations/interfaces/interface-form-subscribe-service.php @@ -51,10 +51,10 @@ public function extract_data_from_integration( $wp_options_form ); public static function validate_api_key( $api_key ); /** - * Test if the service is set up by registering a random email address on the contact list. + * Make a request that add the email to the contact list. * - * @return mixed - * @since 2.0.3 + * @param string $email The email address. + * @return array|\WP_Error The response from Mailchimp. */ - public function test_subscription(); + public function make_subscribe_request( $email ); } diff --git a/inc/integrations/providers/class-mailchimp.php b/inc/integrations/providers/class-mailchimp.php index 80ffea446..88bab3def 100644 --- a/inc/integrations/providers/class-mailchimp.php +++ b/inc/integrations/providers/class-mailchimp.php @@ -111,7 +111,7 @@ function( $item ) { * @param string $email The email address. * @return array|\WP_Error The response from Mailchimp. */ - private function make_subscribe_request( $email ) { + public function make_subscribe_request( $email ) { $user_status = $this->get_new_user_status_mailchimp( $this->list_id ); $url = 'https://' . $this->server_name . '.api.mailchimp.com/3.0/lists/' . $this->list_id . '/members/' . md5( strtolower( $email ) ); @@ -161,23 +161,6 @@ public function subscribe( $form_data ) { return $form_data; } - /** - * Test the subscription by registering a random generated email. - * - * @return Form_Data_Request - * @since 2.0.3 - */ - public function test_subscription() { - $req = new Form_Data_Request(); - $response = $this->make_subscribe_request( Form_Utils::generate_test_email() ); - - if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { - $req->set_error( Form_Data_Response::get_error_code_message( Form_Data_Response::ERROR_PROVIDER_SUBSCRIBE_ERROR ) ); - } - - return $req; - } - /** * Set the API Key. * diff --git a/inc/integrations/providers/class-sendinblue.php b/inc/integrations/providers/class-sendinblue.php index 63f8a4cd3..267d4f0f1 100644 --- a/inc/integrations/providers/class-sendinblue.php +++ b/inc/integrations/providers/class-sendinblue.php @@ -154,22 +154,6 @@ public function subscribe( $form_data ) { return $form_data; } - /** - * Test the subscription by registering a random generated email. - * - * @return Form_Data_Request - */ - public function test_subscription() { - $req = new Form_Data_Request(); - $response = $this->make_subscribe_request( Form_Utils::generate_test_email() ); - - if ( is_wp_error( $response ) || 400 === wp_remote_retrieve_response_code( $response ) ) { - $req->set_error( Form_Data_Response::get_error_code_message( Form_Data_Response::ERROR_PROVIDER_SUBSCRIBE_ERROR ) ); - } - - return $req; - } - /** * Set the API Key * diff --git a/inc/server/class-form-server.php b/inc/server/class-form-server.php index de3adf207..b2c940a5e 100644 --- a/inc/server/class-form-server.php +++ b/inc/server/class-form-server.php @@ -655,7 +655,13 @@ public function test_subscription_service( $form_data ) { if ( $valid_api_key['valid'] ) { if ( $form_options->has_list_id() ) { $service->set_api_key( $form_options->get_api_key() )->set_list_id( $form_options->get_list_id() ); - $res = $service->test_subscription(); + $response = $service->make_subscribe_request( Form_Utils::generate_test_email() ); + + if ( is_wp_error( $response ) ) { + $res->set_error( Form_Data_Response::ERROR_RUNTIME_ERROR, $response->get_error_message() ); + } else { + $res->mark_as_success(); + } } else { $res->set_error( __( 'Contact list ID is missing!', 'otter-blocks' ) ); }