Class: Wechatpay::Api::V3::Cert

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/wechatpay/api/v3/cert.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#certObject

Returns the value of attribute cert.



11
12
13
# File 'lib/wechatpay/api/v3/cert.rb', line 11

def cert
  @cert
end

#certificateObject

Returns the value of attribute certificate.



11
12
13
# File 'lib/wechatpay/api/v3/cert.rb', line 11

def certificate
  @certificate
end

#expires_atObject

Returns the value of attribute expires_at.



11
12
13
# File 'lib/wechatpay/api/v3/cert.rb', line 11

def expires_at
  @expires_at
end

#serial_noObject

Returns the value of attribute serial_no.



11
12
13
# File 'lib/wechatpay/api/v3/cert.rb', line 11

def serial_no
  @serial_no
end

Instance Method Details

#loadObject



25
26
27
28
29
# File 'lib/wechatpay/api/v3/cert.rb', line 25

def load
  return false if cert.nil? || expires_at < DateTime.now

  self
end

#update(json) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/wechatpay/api/v3/cert.rb', line 13

def update(json)
  Wechatpay::Api.client.logger.debug { "Cert JSON: #{json}" }
  expire_time = DateTime.parse(json[:expire_time])
  return unless expires_at.nil? || expire_time > expires_at

  @serial_no = json[:serial_no]
  @expires_at = expire_time
  ec = json[:encrypt_certificate]
  @cert = yield(ec[:ciphertext], ec[:nonce], ec[:associated_data])
  @certificate = OpenSSL::X509::Certificate.new @cert
end