/**
     *  Implements the form() function as required by WordPress
     *  This is responsible for how the form in the WordPress admin looks
     */
    function form($instance)
    {
        $defaults = array('title' => '', 'button_text' => 'Checkout with Instamojo', 'instamojo_offer' => '', 'button_style' => 'none');
        $instance = wp_parse_args((array) $instance, $defaults);
        $instamojo_credentials = get_option('instamojo_credentials');
        if (!$instamojo_credentials['auth_token']) {
            ?>
      <p>Please authenticate your account first.</p>
      <?php 
        } else {
            // Create Instamojo instance for interacting with API
            $instamojo = new Instamojo(APPLICATION_ID);
            $instamojo->setAuthToken($instamojo_credentials['auth_token']);
            $offerObject = $instamojo->listAllOffers();
            $offers = $offerObject['offers'];
            ?>
      <p>
        <label for="<?php 
            echo $this->get_field_id('title');
            ?>
">Widget Title:</label>
        <input class="widefat" id="<?php 
            echo $this->get_field_id('title');
            ?>
"
          name="<?php 
            echo $this->get_field_name('title');
            ?>
"
          value="<?php 
            echo $instance['title'];
            ?>
" />
      </p>
      <p>
        <label for="<?php 
            echo $this->get_field_id('button_text');
            ?>
">Button Text:</label>
        <input class="widefat" id="<?php 
            echo $this->get_field_id('button_text');
            ?>
"
          name="<?php 
            echo $this->get_field_name('button_text');
            ?>
"
          value="<?php 
            echo $instance['button_text'];
            ?>
" />
      </p>
      <p>
        <label for="<?php 
            echo $this->get_field_id('instamojo_offer');
            ?>
">Instamojo Offer:</label>
        <select id="<?php 
            echo $this->get_field_id('instamojo_offer');
            ?>
" name="<?php 
            echo $this->get_field_name('instamojo_offer');
            ?>
">
          <option value="none" <?php 
            if ($instance['instamojo_offer'] == '') {
                echo 'selected="selected"';
            }
            ?>
>None</option>
        <?php 
            foreach ($offers as $offer) {
                ?>
          <option value="<?php 
                echo $offer['slug'];
                ?>
" <?php 
                if ($instance['instamojo_offer'] == $offer['slug']) {
                    echo 'selected="selected"';
                }
                ?>
><?php 
                echo $offer['title'];
                ?>
</option>
        <?php 
            }
            ?>
        </select>
      </p>
      <p>
        <label for="<?php 
            echo $this->get_field_id('button_style');
            ?>
">Button Style</label>
        <select id="<?php 
            echo $this->get_field_id('button_style');
            ?>
" name="<?php 
            echo $this->get_field_name('button_style');
            ?>
">
          <option value="light" <?php 
            if ($instance['button_style'] == 'light') {
                echo 'selected="selected"';
            }
            ?>
>Light</option>
          <option value="dark" <?php 
            if ($instance['button_style'] == 'dark') {
                echo 'selected="selected"';
            }
            ?>
>Dark</option>
          <option value="flat" <?php 
            if ($instance['button_style'] == 'flat') {
                echo 'selected="selected"';
            }
            ?>
>Flat Light</option>
          <option value="flat-dark" <?php 
            if ($instance['button_style'] == 'flat-dark') {
                echo 'selected="selected"';
            }
            ?>
>Flat Dark</option>
          <option value="none" <?php 
            if ($instance['button_style'] == 'none') {
                echo 'selected="selected"';
            }
            ?>
>None</option>
        </select>
      </p>
    <?php 
        }
    }
 /**
  * Revoke Token
  * @param string $auth_token Auth Token stored in options
  */
 private function revoke_token($auth_token)
 {
     $instance = new Instamojo(APPLICATION_ID);
     $instance->setAuthToken($auth_token);
     $instance->deleteAuthToken();
     delete_option('instamojo_credentials');
     unset($instance);
 }