/**
 * Returns whether or not the given download is a renewal
 *
 * @return bool
 */
function cart_has_renewal_discount()
{
    if (!edd_sl_renewals_allowed()) {
        return false;
    }
    if (!EDD()->session->get('edd_is_renewal')) {
        return false;
    }
    $renewal_discount = cart_get_renewal_discount();
    return !empty($renewal_discount);
}
 /**
  * Returns the status label
  * @since 2.7
  * @return string
  */
 function license_status($license_id)
 {
     $status = self::get_license_status($license_id);
     switch ($status) {
         case 'active':
             $status = __('Active', 'edd_sl');
             break;
         case 'inactive':
             $status = __('Inactive', 'edd_sl');
             break;
         case 'expired':
             $status = __('Expired', 'edd_sl');
             if (edd_sl_renewals_allowed()) {
                 $renewal_link = edd_get_checkout_uri(array('edd_license_key' => self::get_license_key($license_id), 'download_id' => self::get_download_id($license_id)));
                 $status .= ', <a href="' . esc_url($renewal_link) . '" title="' . __('Renew this license', 'edd_sl') . '">' . __('renew now', 'edd_sl') . '</a>';
             }
             break;
     }
     return $status;
 }
Example #3
0
/**
 * Software licensing
 * @return [type] [description]
 */
function pp_edd_sl_renewal_form()
{
    if (!edd_sl_renewals_allowed()) {
        return;
    }
    $renewal = EDD()->session->get('edd_is_renewal');
    $renewal_key = EDD()->session->get('edd_renewal_key');
    $preset_key = !empty($_GET['key']) ? urldecode($_GET['key']) : '';
    $error = !empty($_GET['edd-sl-error']) ? absint($_GET['edd-sl-error']) : '';
    ob_start();
    ?>
	

	<form method="post" id="edd_sl_renewal_form">
		<fieldset id="edd_sl_renewal_fields">

			<?php 
    if (empty($renewal) || empty($renewal_key)) {
        ?>

			<p id="edd_sl_show_renewal_form_wrap">
				<a href="#" id="edd_sl_show_renewal_form">
					<svg width="32" height="32">
					   <use xlink:href="<?php 
        echo get_stylesheet_directory_uri() . '/images/svg-defs.svg#icon-renew';
        ?>
"></use>
					</svg>
					<?php 
        _e('Renewing a License Key?', 'edd_sl');
        ?>
				</a>
			</p>

			<p id="edd-license-key-container-wrap" style="display:none;">
				<span class="edd-description"><?php 
        _e('Enter the license key you wish to renew. Leave blank to purchase a new one.', 'edd_sl');
        ?>
</span>
					

			<span class="input-wrap">
				<input class="edd-input required" type="text" name="edd_license_key" placeholder="<?php 
        _e('Enter your license key', 'edd_sl');
        ?>
" id="edd-license-key" value="<?php 
        echo $preset_key;
        ?>
"/>
				<input type="submit" class="edd-submit button edd-renew-license" value="<?php 
        _e('Renew', 'edd_sl');
        ?>
" />
			</span>

			<input type="hidden" name="edd_action" value="apply_license_renewal"/>

			</p>

			<?php 
    } else {
        ?>
			<div id="edd-license-key-container-wrap">
				<p id="edd-license-key-wrap">
					<label class="edd-label" for="edd-license-key"><?php 
        _e('License Key Being Renewed', 'edd_sl');
        ?>
</label>
					<span class="edd-renewing-key"><?php 
        echo $renewal_key;
        ?>
</span>
				</p>
				<p id="edd-license-key-submit">
					<input type="hidden" name="edd_action" value="cancel_license_renewal"/>
					<input type="submit" class="edd-submit button" value="<?php 
        _e('Cancel License Renewal', 'edd_sl');
        ?>
"/>
				</p>
			</div>
			<?php 
    }
    ?>

		</fieldset>
	</form>
	<?php 
    echo ob_get_clean();
}
Example #4
0
function edd_downloads_renew_to_cart($download_id, $options)
{
    if (!edd_sl_renewals_allowed()) {
        return;
    }
    $post_data = urldecode($_REQUEST['post_data']);
    $post_data_formated = array();
    if (strstr($post_data, "expired")) {
        $post_data_split = explode("&", $post_data);
        foreach ($post_data_split as $data_split) {
            $data_array = explode("=", $data_split);
            $post_data_formated[$data_array[0]] = $data_array[1];
        }
    }
    if (isset($post_data_formated['expired']) && $post_data_formated['expired'] == 1 && isset($post_data_formated['license_id']) && isset($post_data_formated['product_id'])) {
        global $edd_options;
        $license_key = edd_software_licensing()->get_license_key($post_data_formated['license_id']);
        $data = array('edd_license_key' => $license_key, 'edd_action' => 'apply_license_renewal');
        $license = !empty($data['edd_license_key']) ? sanitize_text_field($data['edd_license_key']) : false;
        $valid = true;
        if (!$license) {
            $valid = false;
        }
        $license_id = edd_software_licensing()->get_license_by_key($license);
        if (empty($license_id)) {
            $valid = false;
        }
        $download_id = get_post_meta($license_id, '_edd_sl_download_id', true);
        if (empty($download_id) || !edd_item_in_cart($download_id)) {
            $valid = false;
        }
        $options = array();
        // if product has variable prices, find previous used price id and add it to cart
        if (edd_has_variable_prices($download_id)) {
            $price_id = get_post_meta($license_id, '_edd_sl_download_price_id', true);
            if ('' === $price_id) {
                // If no $price_id is available, try and find it from the payment ID. See https://github.com/pippinsplugins/EDD-Software-Licensing/issues/110
                $payment_id = get_post_meta($license_id, '_edd_sl_payment_id', true);
                $payment_items = edd_get_payment_meta_downloads($payment_id);
                foreach ($payment_items as $payment_item) {
                    if ((int) $payment_item['id'] !== (int) $download_id) {
                        continue;
                    }
                    if (isset($payment_item['options']['price_id'])) {
                        $options['price_id'] = $payment_item['options']['price_id'];
                        break;
                    }
                }
            } else {
                $options['price_id'] = $price_id;
            }
            $cart_key = edd_get_item_position_in_cart($download_id, $options);
            edd_remove_from_cart($cart_key);
            edd_add_to_cart($download_id, $options);
            $valid = true;
        }
        if ($valid) {
            $keys = (array) EDD()->session->get('edd_renewal_keys');
            $keys[$download_id] = $license;
            EDD()->session->set('edd_is_renewal', '1');
            EDD()->session->set('edd_renewal_keys', $keys);
            //$redirect = edd_get_checkout_uri();
        }
        //do_action('edd_apply_license_renewal', array('edd_license_key' => $license_key ,'edd_action' => 'apply_license_renewal'));
    }
    return true;
}
Example #5
0
            _e('View Upgrades', 'edd_sl');
            ?>
</a>
					<?php 
        } elseif (edd_sl_license_has_upgrades($license->ID) && 'expired' == edd_software_licensing()->get_license_status($license->ID)) {
            ?>
						<span class="edd_sl_limit_sep">&nbsp;&ndash;&nbsp;</span>
						<span class="edd_sl_no_upgrades"><?php 
            _e('Renew to upgrade', 'edd_sl');
            ?>
</span>
					<?php 
        }
        ?>
					<?php 
        if (edd_sl_renewals_allowed()) {
            ?>
						<?php 
            if ('expired' === edd_software_licensing()->get_license_status($license->ID)) {
                ?>
							<span class="edd_sl_key_sep">&nbsp;&ndash;&nbsp;</span>
							<a href="<?php 
                echo edd_software_licensing()->get_renewal_url($license->ID);
                ?>
" title="<?php 
                esc_attr_e('Renew license', 'edd_sl');
                ?>
"><?php 
                _e('Renew license', 'edd_sl');
                ?>
</a>
Example #6
0
/**
 * Displays Yes/No if a payment was a renewal
 *
 * @since 3.0.2
 * @return void
 */
function edd_sl_payment_details_inner($payment_id = 0)
{
    if (!edd_sl_renewals_allowed()) {
        return;
    }
    $was_renewal = get_post_meta($payment_id, '_edd_sl_is_renewal', true);
    ?>
	<div class="edd-admin-box-inside">
		<p>
			<strong><?php 
    _e('Was renewal:', 'edd_sl');
    ?>
</strong>&nbsp;
			<span><?php 
    echo $was_renewal ? __('Yes', 'edd_sl') : __('No', 'edd_sl');
    ?>
</span>
		</p>
	</div>
<?php 
}