Zoom_Helpers::zoom_oauth_save()

Action when settings added, it will redirect user to 3rd party for OAuth connect.


Source

File: src/integrations/zoom/helpers/zoom-helpers.php

	public function zoom_oauth_save() {
		if ( isset( $_POST['uap_automator_zoom_api_nonce'] ) && wp_verify_nonce( $_POST['uap_automator_zoom_api_nonce'], 'uap_automator_zoom_api_nonce' ) ) {
			if ( isset( $_POST['uap_automator_zoom_api_consumer_key'] ) && ! empty( $_POST['uap_automator_zoom_api_consumer_key'] ) && isset( $_POST['uap_automator_zoom_api_consumer_secret'] ) && ! empty( $_POST['uap_automator_zoom_api_consumer_secret'] ) ) {
				update_option( 'uap_automator_zoom_api_consumer_key', $_POST['uap_automator_zoom_api_consumer_key'] );
				update_option( 'uap_automator_zoom_api_consumer_secret', $_POST['uap_automator_zoom_api_consumer_secret'] );
				delete_transient( 'uap_automator_zoom_api_user_info' );
				$client = $this->refresh_token();
				// Check if token is working fine or not.
				$response = wp_remote_post(
					$this->automator_api,
					array(
						'body' =>
							array(
								'action'       => 'get_meetings',
								'access_token' => $client['access_token'],
								'page_number'  => 1,
								'page_size'    => 300,
								'type'         => 'upcoming',
							),
					)
				);
				$status_code = wp_remote_retrieve_response_code( $response );
				// Check for a meeting API call if not 200 then its wrong pair.
				if ( $status_code !== 200 ) {
					$body = json_decode( wp_remote_retrieve_body( $response ), true );
					delete_option( '_uncannyowl_zoom_settings' );
					$error_status = $body['data']['message'] ? $body['data']['message'] : '2';
					wp_safe_redirect( admin_url( 'edit.php?post_type=uo-recipe&page=uncanny-automator-settings&tab=' . $this->setting_tab . '&connect=' . $error_status ) );
				} else {
					wp_safe_redirect( admin_url( 'edit.php?post_type=uo-recipe&page=uncanny-automator-settings&tab=' . $this->setting_tab . '&connect=1' ) );
				}
				die;
			}
		}
	}