Class: GlobeSSL::OrderSSLCertificate
- Defined in:
- lib/globessl/order_ssl_certificate.rb
Constant Summary collapse
- EXPIRY_PERIODS =
[0, 1, 2, 3].freeze
Instance Method Summary collapse
- #dcv_method=(value) ⇒ Object
- #purchase! ⇒ Object
- #set_errors(response) ⇒ Object
- #valid? ⇒ Boolean
- #validate ⇒ Object
Methods inherited from Base
Instance Method Details
#dcv_method=(value) ⇒ Object
41 42 43 |
# File 'lib/globessl/order_ssl_certificate.rb', line 41 def dcv_method=(value) @dcv_method = value.downcase end |
#purchase! ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# 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) ⇒ Object
146 147 148 149 150 |
# 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? ⇒ Boolean
152 153 154 |
# File 'lib/globessl/order_ssl_certificate.rb', line 152 def valid? validate end |
#validate ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# 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 |