Gotowebinar_Helpers::gtw_register_user( string $user_id, string $webinar_key,  $action_data = null )

For registering user to webinar action method.


Parameters Parameters

$user_id

(Required)

$webinar_key

(Required)


Top ↑

Return Return

(array)


Source Source

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

	public function gtw_register_user( $user_id, $webinar_key, $action_data = null ) {

		$user = get_userdata( $user_id );

		if ( is_wp_error( $user ) ) {
			throw new \Exception( __( 'GoTo Webinar user not found.', 'uncanny-automator' ) );
		}

		$customer_first_name = $user->first_name;
		$customer_last_name = $user->last_name;
		$customer_email = $user->user_email;

		if ( ! empty( $customer_email ) ) {
			$customer_email_parts = explode( '@', $customer_email );
			$customer_first_name = empty( $customer_first_name ) ? $customer_email_parts[0] : $customer_first_name;
			$customer_last_name = empty( $customer_last_name ) ? $customer_email_parts[0] : $customer_last_name;
		}

		list( $access_token, $organizer_key ) = $this->get_webinar_token();

		$params = array(
			'method'      => 'POST',
			'url' 		  => "https://api.getgo.com/G2W/rest/v2/organizers/{$organizer_key}/webinars/{$webinar_key}/registrants?resendConfirmation=true",
			'timeout'     => 45,
			'redirection' => 5,
			'httpversion' => '1.0',
			'blocking'    => true,
			'headers'     => array(
				'Authorization' => $access_token,
				'Content-type'  => 'application/json',
			),
			'body'        => wp_json_encode(
				array(
					'firstName' => $customer_first_name,
					'lastName'   => $customer_last_name,
					'email'     => $customer_email,
				)
			),
		);

		$response = $this->remote_request( $params, $action_data );

		$code = wp_remote_retrieve_response_code( $response );

		$jsondata = json_decode( $response['body'], true, 512, JSON_BIGINT_AS_STRING );

		if ( 201 !== $code ) {
			throw new \Exception( $jsondata['description'], $code );
		}

		if ( ! isset( $jsondata['joinUrl'] ) ) {
			throw new \Exception( __( 'Error adding user to GoTo Webinar', 'uncanny-automator' ) );
		}

		update_user_meta( $user_id, '_uncannyowl_gtw_webinar_' . $webinar_key . '_registrantKey', $jsondata['registrantKey'] );
		update_user_meta( $user_id, '_uncannyowl_gtw_webinar_' . $webinar_key . '_joinUrl', $jsondata['joinUrl'] );
	}