client = $client; $this->option_key = 'surecart_' . md5( $this->client->slug ) . '_license_activation_id'; } /** * Create an activation for the license. * * @param string $license_id The license id. * * @return object|\WP_Error */ public function create( $license_id ) { if ( empty( $license_id ) ) { return new \WP_Error( 'missing_key', __( 'Please enter a license key', 'quickwebp' ) ); } // send the activation request. $activation = $this->client->send_request( 'POST', trailingslashit( $this->endpoint ), array( 'activation' => array( 'fingerprint' => esc_url_raw( get_site_url() ), 'name' => get_bloginfo(), 'license' => $license_id, ), ) ); // error. if ( is_wp_error( $activation ) ) { return $activation; } // no id. if ( empty( $activation->id ) ) { return new \WP_Error( 'could_not_activate', __( 'Could not activate the license.', 'quickwebp' ) ); } // return the activation. return $activation; } /** * Retrieves details of a specific activation. * * @param string $id The id of the activation. * * @return object|\WP_Error */ public function get( $id = '' ) { return $this->client->send_request( 'GET', trailingslashit( $this->endpoint ) . $id ); } /** * Update an activation for the license. * * @param string $id The id of the activation. * * @return object|\WP_Error */ public function update( $id = '' ) { $license_key = $this->client->license()->get_id(); if ( empty( $license_key ) ) { return new \WP_Error( 'missing_key', __( 'Please enter a license key', 'quickwebp' ) ); } return $this->client->send_request( 'PATCH', trailingslashit( $this->endpoint ) . $id, array( 'fingerprint' => esc_url_raw( get_site_url() ), 'name' => get_bloginfo(), 'license' => $license_key, ) ); } /** * Deletes a specific activation. * * @param string $id The id of the activation. * * @return object|\WP_Error */ public function delete( $id = '' ) { return $this->client->send_request( 'DELETE', trailingslashit( $this->endpoint ) . $id ); } }