class PedicelPay::Helper

Assistance/collection functions.

Public Class Methods

bytestring_to_hex(string) click to toggle source
# File lib/pedicel-pay/helper.rb, line 19
def self.bytestring_to_hex(string)
  string.unpack('H*').first
end
ec_key_to_pkey_public_key(ec_key) click to toggle source
# File lib/pedicel-pay/helper.rb, line 11
def self.ec_key_to_pkey_public_key(ec_key)
  # EC#public_key is not a PKey public key, but an EC point.
  pub = OpenSSL::PKey::EC.new(ec_key.group)
  pub.public_key = ec_key.is_a?(OpenSSL::PKey::PKey) ? ec_key.public_key : ec_key

  pub
end
encrypt(data:, key:) click to toggle source
# File lib/pedicel-pay/helper.rb, line 46
def self.encrypt(data:, key:)
  cipher = OpenSSL::Cipher.new('aes-256-gcm')
  cipher.encrypt
  cipher.key = key
  cipher.iv_len = 16
  cipher.iv = 0.chr * cipher.iv_len
  cipher.auth_data = ''
  cipher.update(data) + cipher.final + cipher.auth_tag
end
merchant_id(x) click to toggle source
# File lib/pedicel-pay/helper.rb, line 23
def self.merchant_id(x)
  case x
  when Client
    Pedicel::EC.merchant_id(certificate: x.certificate)
  when OpenSSL::X509::Certificate
    Pedicel::EC.merchant_id(certificate: x)
  when /\A[0-9a-fA-F]{64}\z/
    [x].pack('H*')
  when /\A.{32}\z/
    x
  else
    raise ArgumentError, "cannot extract 'merchant_id' from #{x}"
  end
end
new(config: PedicelPay.config, pedicel_instance: nil) click to toggle source
# File lib/pedicel-pay/helper.rb, line 6
def initialize(config: PedicelPay.config, pedicel_instance: nil)
  @config = config
  @pedicel = pedicel_instance
end
recipient_certificate(recipient:) click to toggle source
# File lib/pedicel-pay/helper.rb, line 38
def self.recipient_certificate(recipient:)
  case recipient
  when Client                     then recipient.certificate
  when OpenSSL::X509::Certificate then recipient
  else raise ArgumentError, 'invalid recipient'
  end
end