Class: Bakong::Khqr::MerchantCode::TimeStamp
- Inherits:
-
TagLengthString
- Object
- TagLengthString
- Bakong::Khqr::MerchantCode::TimeStamp
- Defined in:
- lib/bakong/khqr/merchant_code/time_stamp.rb
Overview
Tag “99”. Accepts a snake_case hash: { creation_timestamp:, expiration_timestamp: } where both are millisecond-precision Unix timestamps (13 digits).
Instance Attribute Summary
Attributes inherited from TagLengthString
Instance Method Summary collapse
-
#initialize(tag, timestamp, poi = nil) ⇒ TimeStamp
constructor
A new instance of TimeStamp.
Methods inherited from TagLengthString
Constructor Details
#initialize(tag, timestamp, poi = nil) ⇒ TimeStamp
Returns a new instance of TimeStamp.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bakong/khqr/merchant_code/time_stamp.rb', line 15 def initialize(tag, , poi = nil) ||= {} = ([:creation_timestamp] || 0).to_i = ([:expiration_timestamp] || 0).to_i if poi == EMV[:DYNAMIC_QR] if .empty? || .zero? raise Error.from(ERROR_CODES[:EXPIRATION_TIMESTAMP_REQUIRED]) end if .to_s.length != EMV[:INVALID_LENGTH][:TIMESTAMP] raise Error.from(ERROR_CODES[:EXPIRATION_TIMESTAMP_LENGTH_INVALID]) end begin Time.at( / 1000.0) rescue StandardError raise Error.from(ERROR_CODES[:INVALID_DYNAMIC_KHQR]) end raise Error.from(ERROR_CODES[:EXPIRATION_TIMESTAMP_IN_THE_PAST]) if < now_ms = (Time.now.to_f * 1000).to_i raise Error.from(ERROR_CODES[:KHQR_EXPIRED]) if < now_ms end string = +"" created = TagLengthString.new(EMV[:CREATION_TIMESTAMP], ) string << created.to_s expired = TagLengthString.new(EMV[:EXPIRATION_TIMESTAMP], ) string << expired.to_s super(tag, string) end |