Пример #1
0
/**
 * @param foolic_licensekey $license_key
 *
 * @returns int
 */
function foolic_renewal_percentage($license_key)
{
    $discount = 0;
    //we only want to give a discount if the license expires
    if ($license_key->does_expire()) {
        if (!$license_key->has_expired()) {
            //the license key has not expired yet - good boy!
            $discount = foolic_renewal_discount_early();
        } else {
            $expiration_date = strtotime($license_key->expires);
            $grace_period_expiry_date = strtotime('+' . foolic_renewal_grace_period() . ' days', $expiration_date);
            //days ahead of expiry
            if ($grace_period_expiry_date >= time()) {
                //within grace period - lucky boy!
                $discount = foolic_renewal_discount_grace();
            } else {
                //late - boo!
                $discount = foolic_renewal_discount_late();
            }
        }
    }
    return $discount;
}