BSF_License_Manager::process_license_deactivation( int $product_id )

Process license deactivation.


Description


Parameters

$product_id

(int) (Required) Product ID.


Return

(array)


Source

File: admin/bsf-core/class-bsf-license-manager.php

		public function process_license_deactivation( $product_id ) {

			$license_key = $this->bsf_get_product_info( $product_id, 'purchase_key' );

			// Check if the key is from EDD.
			$is_edd = $this->is_edd( $license_key );

			$path = bsf_get_api_url() . '?referer=deactivate-' . $product_id;

			// Using Brainstorm API v2.
			$data = array(
				'action'       => 'bsf_deactivate_license',
				'purchase_key' => $license_key,
				'product_id'   => $product_id,
				'site_url'     => get_site_url(),
				'is_edd'       => $is_edd,
				'referer'      => 'customer',
			);

			$data     = apply_filters( 'bsf_deactivate_license_args', $data );
			$response = wp_remote_post(
				$path,
				array(
					'body'    => $data,
					'timeout' => '15',
				)
			);

			if ( ! is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) === 200 ) {
				$result = json_decode( wp_remote_retrieve_body( $response ), true );

				if ( isset( $result['success'] ) && ( true === $result['success'] || 'true' === $result['success'] ) ) {
					// update license saus to the product.
					$_POST['bsf_license_deactivation']['success'] = $result['success'];
					$_POST['bsf_license_deactivation']['message'] = $result['message'];

					$this->bsf_update_product_info( $product_id, $result );

					do_action( 'bsf_deactivate_license_' . $product_id . '_after_success', $result, $response, $_POST );

				} else {
					$_POST['bsf_license_deactivation']['success'] = $result['success'];
					$_POST['bsf_license_deactivation']['message'] = $result['message'];
				}
			} else {
				// If there is an error, the status will not be changed. hence it's true.
				$_POST['bsf_license_activation']['success'] = true;
				$_POST['bsf_license_activation']['message'] = 'There was an error when connecting to our license API - <pre class="bsf-pre">' . $response->get_error_message() . '</pre>';

				$result['success'] = false;
				$result['message'] = $response->get_error_message();
			}

			// Delete license key status transient.
			delete_transient( $product_id . '_license_status' );

			return $result;
		}


User Contributed Notes

You must log in before being able to contribute a note or feedback.