Class: PedicelPay::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/pedicel-pay/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key: nil, certificate: nil, ca_certificate_pem: nil) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
# File 'lib/pedicel-pay/client.rb', line 9

def initialize(key: nil, certificate: nil, ca_certificate_pem: nil)
  @key = key
  @certificate = certificate
  @ca_certificate_pem = ca_certificate_pem
end

Instance Attribute Details

#ca_certificate_pemObject

Returns the value of attribute ca_certificate_pem.



7
8
9
# File 'lib/pedicel-pay/client.rb', line 7

def ca_certificate_pem
  @ca_certificate_pem
end

#certificateObject

Returns the value of attribute certificate.



7
8
9
# File 'lib/pedicel-pay/client.rb', line 7

def certificate
  @certificate
end

#keyObject

Returns the value of attribute key.



7
8
9
# File 'lib/pedicel-pay/client.rb', line 7

def key
  @key
end

Instance Method Details

#decrypt(token, ca_certificate_pem: @ca_certificate_pem, now: Time.now) ⇒ Object



36
37
38
39
40
# File 'lib/pedicel-pay/client.rb', line 36

def decrypt(token, ca_certificate_pem: @ca_certificate_pem, now: Time.now)
  Pedicel::EC.
    new(token).
    decrypt(private_key: key, certificate: certificate, ca_certificate_pem: ca_certificate_pem, now: now)
end

#generate_csr(subject: PedicelPay.config[:subject][:csr]) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/pedicel-pay/client.rb', line 22

def generate_csr(subject: PedicelPay.config[:subject][:csr])
  req = OpenSSL::X509::Request.new
  req.version = 0
  req.subject = subject
  req.public_key = PedicelPay::Helper.ec_key_to_pkey_public_key(key)
  req.sign(key, OpenSSL::Digest::SHA256.new)

  req
end

#generate_keyObject



15
16
17
18
19
20
# File 'lib/pedicel-pay/client.rb', line 15

def generate_key
  @key = OpenSSL::PKey::EC.new(PedicelPay::EC_CURVE)
  @key.generate_key

  @key
end

#merchant_idObject



32
33
34
# File 'lib/pedicel-pay/client.rb', line 32

def merchant_id
  Pedicel::EC.merchant_id(certificate: certificate)
end