Automator_Review::get_credits()

Callback for getting api credits.


Parameters Parameters

$request

(Required)


Top ↑

Return Return

(object)


Source Source

File: src/core/admin/class-automator-review.php

	public function get_credits() {

		// The rest response object
		$response = (object) [];

		// Default return message
		$response->message = __( 'Information is missing.', 'automator-plugin' );
		$response->success = true;

		$have_valid_licence = false;
		$licence_key        = '';
		$item_name          = '';
		$count              = 0;

		/*if ( defined( 'AUTOMATOR_PRO_FILE' ) && 'valid' !== get_option( 'uap_automator_pro_license_status' ) ) {
			$response->credits_left = 0;
			$response->total_credits = 0;
			$response = new \WP_REST_Response( $response, 200 );

			return $response;
		}*/

		if ( defined( 'AUTOMATOR_PRO_FILE' ) && 'valid' === get_option( 'uap_automator_pro_license_status' ) ) {
			$licence_key = get_option( 'uap_automator_pro_license_key' );
			$item_name   = AUTOMATOR_AUTOMATOR_PRO_ITEM_NAME;
		} elseif ( 'valid' === get_option( 'uap_automator_free_license_status' ) ) {
			$licence_key = get_option( 'uap_automator_free_license_key' );
			$item_name   = AUTOMATOR_FREE_ITEM_NAME;
		}

		if ( empty( $licence_key ) ) {
			$response->credits_left  = 0;
			$response->total_credits = 0;
			$response                = new \WP_REST_Response( $response, 200 );

			return $response;
		}

		$website = preg_replace( '(^https?://)', '', get_home_url() );

		// data to send in our API request
		$api_params = [
			'action'      => 'get_credits',
			'license_key' => $licence_key,
			'site_name'   => $website,
			'item_name'   => $item_name,
			'api_ver'     => '2.0',
			'plugins'     => defined( 'AUTOMATOR_PRO_FILE' ) ? \Uncanny_Automator_Pro\InitializePlugin::PLUGIN_VERSION : AUTOMATOR_PLUGIN_VERSION,
		];

		// Call the custom API.
		$api_response = wp_remote_post( AUTOMATOR_API_URL . 'v2/credits', array(
			'timeout'   => 15,
			'sslverify' => false,
			'body'      => $api_params,
		) );

		$credit_data = json_decode( wp_remote_retrieve_body( $api_response ) );
		if ( $credit_data->statusCode == 200 ) {
			$response->credits_left  = $credit_data->data->usage_limit - $credit_data->data->paid_usage_count;
			$response->total_credits = $credit_data->data->usage_limit;

		}

		$response = new \WP_REST_Response( $response, 200 );

		return $response;
	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.1 Introduced.