<?php
//ini_set('display_errors', '1');
//ini_set('display_startup_errors', '1');
//error_reporting(E_ALL);
//use Http\Adapter\Guzzle6\Client;
require dirname(__FILE__) . "/vendor/autoload.php";
global $client_id,$client_secret,$redirect_url;


    $refresh_token="1000.bd471fdcb7e6539fabd25cfbee1af11c.ad38670adcd9fb508a3c9f4da373bab4";


    $client_id="1000.RMGV7OI3L1SBGBDAWVYU2QBWE0JWBB";
    $client_secret="97fa78c603995fe2db49fc3eec34156dfa76d3f597";
    $redirect_url='https://signup.modernwebstudios.com/subscriptions/products.php';
    
    $adminUrl='https://accounts.zoho.com/oauth/v2/token';

    $para = [
        'refresh_token' => $refresh_token,
        "client_secret" => $client_secret, 
        "grant_type"    => "refresh_token",
        'client_id'     => $client_id
           
    ];                        
    
    

    $ch = curl_init();
        
    curl_setopt($ch, CURLOPT_URL, $adminUrl);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $para);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);

    $token = curl_exec($ch);

 //   echo '<pre>';
 //       echo "<br />curl post fields";
 //       print_r($para);
 //   echo '</pre>';
    
    
 //   echo "<br>  token = ";
    $token = json_decode($token);
   // print_r($token);
 //   echo $token->access_token;

    curl_close($ch);
    
    // Wordpress
    
    if($_GET['id'] == 'WP1'){
        $plan_id = "wp-1";
    }
    if($_GET['id'] == 'WP2'){
        $plan_id = "wp-2";
    }
    if($_GET['id'] == 'WP3'){
        $plan_id = "wp-3";
    }
    if($_GET['id'] == 'WP4'){
        $plan_id = "wp-4";
    }
    if($_GET['id'] == 'WP5'){
        $plan_id = "wp-5";
    }
    if($_GET['id'] == 'WP6'){
        $plan_id = "wp-6";
    }
    if($_GET['id'] == 'WP7'){
        $plan_id = "wp-7";
    }    
    if($_GET['id'] == 'WP8'){
        $plan_id = "wp-8";
    }
    if($_GET['id'] == 'WP9'){
        $plan_id = "wp-9";
    }    
    if($_GET['id'] == 'WP10'){
        $plan_id = "wp-10";
    }    
    if($_GET['id'] == 'WP11'){
        $plan_id = "wp-11";
    }    
    if($_GET['id'] == 'WP12'){
        $plan_id = "wp-12";
    }
    
    
    // Woocommerce
    if($_GET['id'] == 'Woo1'){
        $plan_id = "woo-1";
    }
    if($_GET['id'] == 'Woo2'){
        $plan_id = "woo-2";
    }
    if($_GET['id'] == 'Woo3'){
        $plan_id = "woo-3";
    }
    if($_GET['id'] == 'Woo4'){
        $plan_id = "woo-4";
    }
    if($_GET['id'] == 'Woo5'){
        $plan_id = "woo5";// I did mistake when I was creating the Plan in Zoho so no dash
    }
    if($_GET['id'] == 'Woo6'){
        $plan_id = "woo-6";
    }
    if($_GET['id'] == 'Woo7'){
        $plan_id = "woo-7";
    }    
    if($_GET['id'] == 'Woo8'){
        $plan_id = "woo-8";
    }
    if($_GET['id'] == 'Woo9'){
        $plan_id = "woo-9";
    }    
    if($_GET['id'] == 'Woo10'){
        $plan_id = "woo-10";
    }    
    if($_GET['id'] == 'Woo11'){
        $plan_id = "woo-11";
    }    
    if($_GET['id'] == 'Woo12'){
        $plan_id = "woo-12";
    }

use SudiptoChoudhury\Zoho\Subscriptions\Api;
if (isset($token->access_token)){
if($plan_id){   
include('products/product.php');
} else{
include('products/invalid-product.php');    
}


}