public static function get_instance()
 {
     // If the single instance hasn't been set, set it now.
     if (null == self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
 public function init()
 {
     Stripe_Subscriptions_Admin::get_instance();
     Stripe_Subscriptions_Scripts::get_instance();
     Stripe_Subscriptions_Functions::get_instance();
     Stripe_Subscriptions_Shortcodes::get_instance();
 }
 public function main_shortcode($attr, $content = null)
 {
     // Our unique identifier in case multiple forms exist
     static $uid = 1;
     extract(shortcode_atts(array('label' => '', 'type' => 'radio', 'default' => '', 'show_details' => 'true', 'id' => '', 'interval' => 'month', 'interval_count' => 1, 'statement_description' => '', 'use_amount' => 'false', 'setup_fee' => 0), $attr, 'stripe_subscription'));
     Shortcode_Tracker::add_new_shortcode('stripe_subscription_' . $uid, 'stripe_subscription', $attr, false);
     $sub_amount = 0;
     $sub_interval = 0;
     $sub_interval_count = 0;
     $error_count = 0;
     $error_html = '';
     $html = !empty($label) ? '<p class="sc-radio-group-label">' . $label . '</p>' : '';
     // If the type is set to single then we just want to make sure the button points to the right plan
     // and that the button will be assigned the correct price for the subscripti
     // We use sanitize_text_field here to account for empty values that may exist
     $content_check = sanitize_text_field($content);
     // Limit to 15
     $statement_description = substr($statement_description, 0, 22);
     if ($type != 'radio') {
         Shortcode_Tracker::update_error_count();
         if (current_user_can('manage_options')) {
             Shortcode_Tracker::add_error_message('<h6>' . __('You have entered an invalid type.', 'sc_sub') . '</h6>');
         }
         return;
     }
     if (empty($content_check)) {
         if (empty($id)) {
             return;
         }
         $sub = Stripe_Subscriptions_Functions::get_subscription_by_id($id);
         if (!is_object($sub)) {
             if (current_user_can('manage_options')) {
                 //$error_html .= _x( 'Invalid subscription ID entered - ', 'Shown when the admin has entered an invalid subscription ID', 'sc_sub' ) . $id . '<br>';
                 $error_html .= $sub;
                 $error_count++;
             }
         } else {
             $default = $sub->id;
             $sub_amount = $sub->amount;
             $sub_interval = $sub->interval;
             $sub_interval_count = $sub->interval_count;
             $sub_currency = $sub->currency;
         }
         $uid++;
     } else {
         $content = trim(substr($this->parse_shortcode_content($content), 0, -1));
         $ids = explode(';', $content);
         static $id_num = 1;
         $html .= '<div class="sc-radio-group">';
         foreach ($ids as $id) {
             $data = explode('|', $id);
             $data[0] = trim($data[0]);
             // Get the Subscription
             if (empty($data[0])) {
                 Shortcode_Tracker::update_error_count();
                 if (current_user_can('manage_options')) {
                     $error_html .= _x('You have not entered any subscription plan IDs', 'Shown when the admin has not entered any subscription IDs', 'sc_sub') . $data[0] . '<br>';
                 }
                 $error_count++;
                 continue;
             }
             $sub = Stripe_Subscriptions_Functions::get_subscription_by_id($data[0]);
             if (!is_object($sub)) {
                 if (current_user_can('manage_options')) {
                     //$error_html .= _x( 'Invalid subscription ID entered - ', 'Shown when the admin has entered an invalid subscription ID', 'sc_sub' ) . $id . '<br>';
                     $error_html .= $sub;
                 }
                 $error_count++;
                 continue;
             }
             if (empty($default)) {
                 $default = $sub->id;
                 $sub_interval = $sub->interval;
                 $sub_interval_count = $sub->interval_count;
             }
             if ($default == $sub->id) {
                 $sub_amount = $sub->amount;
             }
             $currency = $sub->currency;
             $formatted_amount = Stripe_Checkout_Misc::to_formatted_amount($sub->amount, $sub->currency);
             $details_html = ' - ';
             $details_html .= ($currency == 'usd' ? '$' : '') . $formatted_amount . ($currency == 'usd' ? '' : ' ' . strtoupper($currency));
             // For interval count of 1, use $1.00/month format.
             // For a count > 1, use $1.00 every 3 months format.
             if ($sub->interval_count == 1) {
                 $details_html .= '/' . $sub->interval;
             } else {
                 $details_html .= ' ' . __('every', 'sc_sub') . ' ' . $sub->interval_count . ' ' . $sub->interval . 's';
             }
             $details_html = ($data[1] != 'null' ? $data[1] : $sub->name) . ($show_details == 'true' ? ' ' . $details_html : '');
             $details_html = apply_filters('sc_subscription_details', $details_html, $sub);
             if ($type == 'radio') {
                 $html .= '<label title="' . esc_attr($sub->name) . '">';
                 $html .= '<input type="radio" value="' . esc_attr($sub->name) . '" name="sc_radio_' . $uid . '" id="sc_radio_' . $id_num . '" data-sub-amount="' . $sub->amount . '" ' . 'data-sub-id="' . $sub->id . '" ' . (!empty($default) && $sub->id == $default ? 'checked' : '') . ' data-parsley-errors-container=".sc-radio-group" ' . ' data-sub-interval="' . $sub->interval . '" data-sub-interval-count="' . $sub->interval_count . '" data-sub-currency="' . $currency . '" ' . 'data-sub-setup-fee="' . (!empty($data[2]) ? $data[2] : 0) . '">';
                 $html .= '<span>' . $details_html . '</span>';
                 $html .= '</label>';
             }
             if (!empty($default) && $sub->id == $default) {
                 $sub_interval = $sub->interval;
             }
             $id_num++;
         }
         $html .= '</div>';
     }
     if ($setup_fee > 0) {
         global $sc_script_options;
         $sc_script_options['script']['setupFee'] = $setup_fee;
         //add_filter( 'sc_stripe_total', array( 'Stripe_Subscriptions_Functions', 'setup_fee_stripe_total' ), 10, 2 );
     }
     if ($error_count < 1) {
         $html .= '<input type="hidden" name="sc_sub_id" class="sc_sub_id" value="' . $default . '" />';
         $html .= '<input type="hidden" name="sc_sub_amount" class="sc_sub_amount" value="' . $sub_amount . '" />';
         $html .= '<input type="hidden" name="sc_sub_interval" class="sc_sub_interval" value="' . $sub_interval . '" />';
         $html .= '<input type="hidden" name="sc_sub_interval_count" class="sc_sub_interval_count" value="' . $sub_interval_count . '" />';
         $html .= '<input type="hidden" name="sc_sub_setup_fee" class="sc_sub_setup_fee" value="' . esc_attr($setup_fee) . '" />';
         if (isset($sub_currency)) {
             $html .= '<input type="hidden" name="sc_sub_currency" class="sc_sub_currency" value="' . $sub_currency . '" />';
         }
         return '<div class="sc_sub_wrapper sc-form-group" id="sc_sub_wrapper_' . $uid . '">' . $html . '</div>';
     } else {
         Shortcode_Tracker::update_error_count();
         if (current_user_can('manage_options')) {
             Shortcode_Tracker::add_error_message('<h6>An error has occurred. Please check your shortcode syntax.</h6>');
         }
         return '<h6>' . __('An error has occurred. If the problem persists, please contact the site administrator.', 'sc_sub') . '</h6>';
     }
 }