class GlobeSSL::OrderSSLCertificate

Constants

EXPIRY_PERIODS

Public Instance Methods

dcv_method=(value) click to toggle source
# File lib/globessl/order_ssl_certificate.rb, line 41
def dcv_method=(value)
  @dcv_method = value.downcase
end
purchase!() click to toggle source
# File lib/globessl/order_ssl_certificate.rb, line 45
def purchase!
  @errors.clear
  return false unless valid?
  
  # If the dcv_method is 'http' or 'https', prepare the validation text file.
  # Use MD5 for .txt file name.
  # Write SHA1 to first line and comodoca.com to 2nd line.
  # Save to web app root (@txt_file_path).
  unless @dcv_method == "email"
    DomainControlValidation.write_file(@csr.fingerprint_sha1, @csr.fingerprint_md5, @dcv_file_path)
  end
  
  params = { 
    "admin_firstname" => @admin_firstname,
    "admin_lastname"  => @admin_lastname,
    "admin_email"     => @admin_email,
    "admin_phone"     => @admin_phone,
    "csr"             => @csr.csr_code,
    "dcv_method"      => @dcv_method,
    "period"          => @period,
    "product_id"      => @product.id,
    "webserver_type"  => @webserver_type
  }
  
  admin_params = {
    "admin_org"       => @admin_org,
    "admin_jobtitle"  => @admin_jobtitle,
    "admin_address"   => @admin_address,
    "admin_city"      => @admin_city,
    "admin_country"   => @admin_country
  }
  
  email_params = {
    "approver_email"  => @approver_email
  }

  multiple_emails_params = {
    "approver_emails" => @approver_emails
  }
  
  org_params = {
    "org_name"        => @org_name,
    "org_division"    => @org_division,
    "org_address"     => @org_address,
    "org_city"        => @org_city,
    "org_state"       => @org_state,
    "org_country"     => @org_country,
    "org_postalcode"  => @org_postalcode,
    "org_phone"       => @org_phone
  }

  multi_domain_params = {
    "dns_names" => @dns_names
  }

  if @product.validation == "dv"
    if @dcv_method == "email"
      params.merge!(email_params)
    end
  
    if @product.multi_domain
      params.merge!(multi_domain_params)
    end
    
    if @dcv_method == "email" && @product.multi_domain
      params.merge!(multiple_emails_params)
    end
    
    if @optional_admin_params
      params.merge!(admin_params)
    end
    
    if @optional_org_params
      params.merge!(org_params)
    end
  else
    params.merge!(admin_params)
    params.merge!(org_params)
  end
  
  response = Client.post('/order/ssl', params)
  
  case response.code
  when '200'  
    json = response.body
    hash = JSON.parse(json)

    @order_id       = hash["order_id"]
    @certificate_id = hash["certificate_id"]
    @amount         = hash["amount"]
    @currency       = hash["currency"]
    
    return true
  when '400', '401', '403'
    set_errors(response)
    return false
  else
    return false
  end
end
set_errors(response) click to toggle source
# File lib/globessl/order_ssl_certificate.rb, line 146
def set_errors(response)
  json = response.body
  hash = JSON.parse(json)
  @errors << hash["message"]
end
valid?() click to toggle source
# File lib/globessl/order_ssl_certificate.rb, line 152
def valid?
  validate
end
validate() click to toggle source
# File lib/globessl/order_ssl_certificate.rb, line 156
def validate
  unless @dcv_method
    @errors << "dcv_method is required"
  else
    unless DomainControlValidation::METHODS.include?(@dcv_method)
      @errors << "dcv_method must be one of 'email', 'http' or 'https'"
    end

    unless @dcv_method == "email"
      unless @dcv_file_path
        @errors << "dcv_file_path is required"
      end
    end
  end
  
  if @product.multi_domain
    unless @dns_names.size > (@product.min_domains - 1)
      @errors << "dns_names are required"
    end
  end
  
  if @dcv_method == "email"
    unless @approver_email
      @errors << "approver_email is required"
    end
    
    if @product.multi_domain
      unless @approver_emails.size == @dns_names.size
        @errors << "approver_emails are required"
      end
    end
  end
  
  unless @product.validation == "dv"  # if not domain validation
    unless @admin_org
      @errors << "admin_org is required"
    end
    
    unless @admin_address
      @errors << "admin_address is required"
    end
    
    unless @admin_city
      @errors << "admin_city is required"
    end

    unless @admin_country
      @errors << "admin_country is required"
    else
      unless COUNTRY_CODES.has_key?(@admin_country)
        @errors << "admin_country must be one in COUNTRY_CODES"
      end
    end

    unless @org_name
      @errors << "org_name is required"
    end
    
    unless @org_division
      @errors << "org_division is required"
    end

    unless @org_address
      @errors << "org_address is required"
    end

    unless @org_city
      @errors << "org_city is required"
    end

    unless @org_state
      @errors << "org_state is required"
    end
    
    unless @org_country
      @errors << "org_country is required"
    else
      unless COUNTRY_CODES.has_key?(@org_country)
        @errors << "org_country must be one in COUNTRY_CODES"
      end
    end
    
    unless @org_postalcode
      @errors << "org_postalcode is required"
    end
    
    unless @org_phone
      @errors << "org_phone is required"
    end
  end
  
  unless @admin_firstname
    @errors << "admin_firstname is required"
  end

  unless @admin_lastname
    @errors << "admin_lastname is required"
  end

  unless @admin_email
    @errors << "admin_email is required"
  end
  
  unless @admin_jobtitle
    @errors << "admin_jobtitle is required"
  end

  unless @admin_phone
    @errors << "admin_phone is required"
  end

  unless @admin_phone
    @errors << "admin_phone is required"
  end
  
  unless @csr
    @errors << "certificate signing request (csr) is required"
  end
  
  unless @period
    @errors << "period is required"
  else
    unless EXPIRY_PERIODS.include?(@period)
      @errors << "period must be 1, 2 or 3 years or 0 if product is free"
    end
  end
  
  unless @webserver_type
    @errors << "webserver_type is required"
  end
  
  unless @product
    @errors << "product is required"
  end

  if @errors.any?
    return false
  else
    return true
  end
end