How to use NTVWC Client – Dev

This page is about how to use “NTVWC Client” which is client library of plugin “Token Vendor for WooCommerce”.

Client libraries for other than WordPress Themes and Plugins are not prepared yet.

Just include it initialize, then you can validate the token easily with it.

 

Features of “NTVWC Client”

At first, introduction of what the NTVWC Client helps for.

In current version, It has 2 parts of feature, please regard.

 

Create Admin Page as a subpage under “Dashboard”

By initializing the client library, it create admin page automatically located in “Dashboard” -> “Token Validator: Name of Theme or Plugin”, which can save the token to be vlaidated. So please indicate customers to save the purchased token in this page.

Verify if the token is valid and the hashed value is the same as the one which the token has

It varifies if hashed value which you can copy in product settings is the same as the one which the saved token has.

By this, it will be easy to set the condition in the program.

 

Case for WordPress Themes and Plugins

You can download it in admin page “WooCommerce” -> “NTVWC” -> “Tools” or in this site.

Extract the zip located in directory you want to set in package, then you will see the folder “ntvwc-client”.

In your themes and plugins, write some codes by following steps below.

  1. Include the main class file “class-ntvwc-client.php”
  2. Call the static method “get_instance” of the class “NTVWC_Client”

Example:

/**
 * Token Vendor for WooCommerce Client
 * 
 * @param string $file
 * @param string $textdomain
 * @param string $plugin_dir_name
 * @param string $api_url_base
 */
if ( ! class_exists( 'NTVWC_Client' ) ) {
  require_once( 'path/to/ntvwc-client/class-ntvwc-client.php' );
}
$ntvwc_client = NTVWC_Client::get_instance(
  MAIN_FILE, // like "path/to/functions.php" of the theme or "path/to/plugin-file.php" of the plugin
  TEXTDOMAIN, // Textdomain of your theme or of your plugin
  PACKAGE_DIR_NAME, // Folder name of the package
  WC_SITE_URL // URL of WooCommerce site which is installed Token Vendor for WooCommerce
);

 

About Params for the method “get_instance”,

  1. Absolute path of “funcitons.php” for theme, or main plugin file for plugin
  2. Textdomain
  3. Folder name of the theme or plugin
  4. URL of WooCommerce Site which sell the token

you just put these 4.

 

Then, just call the method “validate_token( $hashed )” using the initialized object of the class “NTVWC_Client”. This is an example.

  1. if ( $ntvwc_client->validate_token( PREMIUM_HASHED_VALUE ) ) {
  2. echo ‘Premium User!’;
  3. } elseif ( $ntvwc_client->validate_token( NORMAL_HASHED_VALUE ) ) {
  4. echo ‘Registered User!’;
  5. } else {
  6. echo ‘Huh?’;
  7. }

Use it as you want. This method returns boolean. Hashed values should be copied in product setting page where the Token is sold.