Renews an SSL certificate if it is ACTIVE and Expires <= 30 days. Returns
    the following information:

    - The certificate ID
    - The order ID
    - The transaction ID
    - The amount charged for the order

    years : 1
        Number of years to register

    certificate_id
        Unique ID of the SSL certificate you wish to renew

    certificate_type
        Type of SSL Certificate. Possible values include:

        - EV Multi Domain SSL
        - EV SSL
        - EV SSL SGC
        - EssentialSSL
        - EssentialSSL Wildcard
        - InstantSSL
        - InstantSSL Pro
        - Multi Domain SSL
        - PositiveSSL
        - PositiveSSL Multi Domain
        - PositiveSSL Wildcard
        - PremiumSSL
        - PremiumSSL Wildcard
        - QuickSSL Premium
        - RapidSSL
        - RapidSSL Wildcard
        - SGC Supercert
        - SSL Web Server
        - SSL Webserver EV
        - SSL123
        - Secure Site
        - Secure Site Pro
        - Secure Site Pro with EV
        - Secure Site with EV
        - True BusinessID
        - True BusinessID Multi Domain
        - True BusinessID Wildcard
        - True BusinessID with EV
        - True BusinessID with EV Multi Domain
        - Unified Communications

    promotional_code
        An optional promo code to use when renewing the certificate

    CLI Example:

    .. code-block:: bash

        salt 'my-minion' namecheap_ssl.renew 1 my-cert-id RapidSSL

def renew(years, certificate_id, certificate_type, promotion_code=None):
    '''
    Renews an SSL certificate if it is ACTIVE and Expires <= 30 days. Returns
    the following information:

    - The certificate ID
    - The order ID
    - The transaction ID
    - The amount charged for the order

    years : 1
        Number of years to register

    certificate_id
        Unique ID of the SSL certificate you wish to renew

    certificate_type
        Type of SSL Certificate. Possible values include:

        - EV Multi Domain SSL
        - EV SSL
        - EV SSL SGC
        - EssentialSSL
        - EssentialSSL Wildcard
        - InstantSSL
        - InstantSSL Pro
        - Multi Domain SSL
        - PositiveSSL
        - PositiveSSL Multi Domain
        - PositiveSSL Wildcard
        - PremiumSSL
        - PremiumSSL Wildcard
        - QuickSSL Premium
        - RapidSSL
        - RapidSSL Wildcard
        - SGC Supercert
        - SSL Web Server
        - SSL Webserver EV
        - SSL123
        - Secure Site
        - Secure Site Pro
        - Secure Site Pro with EV
        - Secure Site with EV
        - True BusinessID
        - True BusinessID Multi Domain
        - True BusinessID Wildcard
        - True BusinessID with EV
        - True BusinessID with EV Multi Domain
        - Unified Communications

    promotional_code
        An optional promo code to use when renewing the certificate

    CLI Example:

    .. code-block:: bash

        salt 'my-minion' namecheap_ssl.renew 1 my-cert-id RapidSSL
    '''

    valid_certs = ('QuickSSL Premium',
                   'RapidSSL',
                   'RapidSSL Wildcard',
                   'PremiumSSL',
                   'InstantSSL',
                   'PositiveSSL',
                   'PositiveSSL Wildcard',
                   'True BusinessID with EV',
                   'True BusinessID',
                   'True BusinessID Wildcard',
                   'True BusinessID Multi Domain',
                   'True BusinessID with EV Multi Domain',
                   'Secure Site',
                   'Secure Site Pro',
                   'Secure Site with EV',
                   'Secure Site Pro with EV',
                   'EssentialSSL',
                   'EssentialSSL Wildcard',
                   'InstantSSL Pro',
                   'PremiumSSL Wildcard',
                   'EV SSL',
                   'EV SSL SGC',
                   'SSL123',
                   'SSL Web Server',
                   'SGC Supercert',
                   'SSL Webserver EV',
                   'EV Multi Domain SSL',
                   'Multi Domain SSL',
                   'PositiveSSL Multi Domain',
                   'Unified Communications',
                   )

    if certificate_type not in valid_certs:
        log.error('Invalid option for certificate_type=%s', certificate_type)
        raise Exception('Invalid option for certificate_type=' + certificate_type)

    if years < 1 or years > 5:
        log.error('Invalid option for years=%s', years)
        raise Exception('Invalid option for years=' + six.text_type(years))

    opts = salt.utils.namecheap.get_opts('namecheap.ssl.renew')
    opts['Years'] = six.text_type(years)
    opts['CertificateID'] = six.text_type(certificate_id)
    opts['SSLType'] = certificate_type
    if promotion_code is not None:
        opts['PromotionCode'] = promotion_code

    response_xml = salt.utils.namecheap.post_request(opts)
    if response_xml is None:
        return {}

    sslrenewresult = response_xml.getElementsByTagName('SSLRenewResult')[0]
    return salt.utils.namecheap.atts_to_dict(sslrenewresult)