echo "<span class='red' >Refresh token is already used to retrieved new access token.</span> <br>";
        } else {
            echo "<span class='yellow' >Updating access token by refresh token...</span><br>";
            // Update access token, refresh token, expired_at and updated_at
            $status = $service_bgl360->updateAccessToken(array('access_token' => $response['access_token'], 'refresh_token' => $response['refresh_token'], 'expired_at' => $time->getAccessTokenExpireDateTime(), 'updated_at' => $time->getCurrentDateTime()));
            if ($status == TRUE) {
                echo "<span class='green' >Token successfully updated...</span><br>";
            } else {
                echo "<span class='red' >Token failed to update...</span><br>";
            }
        }
    } else {
        // Do nothing
        $accessToken = $service_bgl360->getCurrentAccessTokenByUser($current_user->ID);
        echo "<span class='green' >Access Token is active! </span> <br>";
        echo "<span class='green' >Remaining days: " . $time->getTotalRemainingDays($time->getCurrentDate(), $time->toDate($accessToken[0]['expired_at'])) . " </span> <br><br><br><br>";
        echo "<span class='green'><b>[This should redirect to homepage when launch]</b></span>";
        //        header("location:bgl360-import");
    }
} else {
    $accessToken = $authentication_bgl360->getAccessToken();
    // echo "<pre>";
    //print_r($accessToken );
    //    exit;
    /**
     * If retrieving access token got an error then should redirect the bgl360 application
     * I think this can be explore more later
     */
    if ($accessToken['error'] == 'invalid_grant') {
        echo "<span class='red'> Authenticating to bgl360 application... </span> <br>";
        /**
/**
 * Instantiate classes
 */
$service_bgl360 = new ServiceBgl360($wpdb, $current_user->ID);
$authentication_bgl360 = new AuthenticationBgl360();
$resource_request_bgl360 = new ResourceRequestBgl360();
$time = new Time();
/**
 * Get all access token saved to database
 */
$accessData = $service_bgl360->getAccessTokens();
foreach ($accessData as $accessToken) {
    echo "id = " . $accessToken['id'] . "<br>";
    echo " current date " . $time->getCurrentDate() . '<br>';
    echo " expired at date " . $time->toDate($accessToken['expired_at']) . '<br>';
    echo " Total remaining days " . $time->getTotalRemainingDays($time->getCurrentDate(), $time->toDate($accessToken['expired_at'])) . '<br>';
    /**
     * Get total days remaining
     */
    if ($time->getTotalRemainingDays($time->getCurrentDate(), $time->toDate($accessToken['expired_at'])) == 0) {
        /**
         * Update access token because total days passed days is 6
         */
        echo "<hr>";
        $accessToken = new AccessToken($wpdb, $accessToken['user_id']);
        $accessToken->refreshAndUpdateAccessToken();
    } else {
        echo " <span style='color:green'>Nothing to update, all are doing great!</span><br>";
        /**
         * Don't update access token because total days is not yet 6th
         */