Class: DPay::Internal::ChecksumCalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/dpay/internal/checksum_calculator.rb,
sig/dpay/internal/checksum_calculator.rbs

Instance Method Summary collapse

Constructor Details

#initialize(secret_hash) ⇒ ChecksumCalculator

Returns a new instance of ChecksumCalculator.

Parameters:

  • secret_hash (String)


8
9
10
11
# File 'lib/dpay/internal/checksum_calculator.rb', line 8

def initialize(secret_hash)
  @secret_hash = secret_hash
  freeze
end

Instance Method Details

#ordered_body(values) ⇒ String

Parameters:

  • values (Array[untyped])

Returns:

  • (String)


19
20
21
22
23
# File 'lib/dpay/internal/checksum_calculator.rb', line 19

def ordered_body(values)
  joined = values.map { |value| PHP.strval(value) }.join("|")

  Digest::SHA256.hexdigest("#{joined}|#{@secret_hash}")
end

#secret_second(service, fields) ⇒ String

Parameters:

  • service (String)
  • fields (Array[untyped])

Returns:

  • (String)


13
14
15
16
17
# File 'lib/dpay/internal/checksum_calculator.rb', line 13

def secret_second(service, fields)
  parts = [service, @secret_hash] + fields.map { |field| PHP.strval(field) }

  Digest::SHA256.hexdigest(parts.join("|"))
end