Custom Plugin integration with API calls

Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInPrint this page

Each of the products on your WP E-commerce which use the WordPress E-Commerce Software License Management software will need to contain a code to make connection with the server. Certain variables or constants need to be set as they appear within the product server admin:


Per this example the code which will be inserted within the plugin should appear like the following:

define('APTO_APP_API_URL',      ''); 

define('APTO_PRODUCT_ID',           'APTO');
define('APTO_SECRET_KEY',           '*#[email protected]*&#1');
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
define('APTO_INSTANCE',             str_replace($protocol, "", get_bloginfo('wpurl')));

You should observer the concordance between the data on the plugin code and the product on the server

The code above need to be inserted before any API calls.
A simple activation calls will looks like this:

$args = array(
                    'sl_action'         => 'activate',
                    'licence_key'       => $license_key,
                    'product_id'        => APTO_PRODUCT_ID,
                    'secret_key'        => APTO_SECRET_KEY,
                    'sl_instance'          => APTO_INSTANCE
$request_uri    = APTO_APP_API_URL . '?' . http_build_query( $args );
$data           = wp_remote_get( $request_uri );

if(is_wp_error( $data ) || $data['response']['code'] != 200)
        //there was a problem establishing a connection to the API server

$data_body = json_decode($data['body']);
        if($data_body->status == 'success' && $data_body->status_code == 's200')
                //the license is active and the software is active
                //doing further actions like saving the license and allow the plugin to run

                //there was a problem activating the license
        //there was a problem establishing a connection to the API server
API Index

Notify of
Inline Feedbacks
View all comments