Class: Ticketbai::TbaiQr

Inherits:
Object
  • Object
show all
Defined in:
lib/ticketbai/tbai_qr.rb

Constant Summary collapse

BASE_URL =
'https://batuz.eus/QRTBAI/?'.freeze
ID_TBAI_NAME =

param names

'id'.freeze
SERIAL_NAME =
's'.freeze
NUMBER_NAME =
'nf'.freeze
TOTAL_NAME =
'i'.freeze
CRC_NAME =
'cr'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ TbaiQr

Returns a new instance of TbaiQr.

Parameters:

  • id_tbai (String)

    The Tbai Identifier

  • number (String)

    Invoice number

  • total (String)

    Invoice total amount (Max 2 decimals) Ex: 14.20

  • serial (String)

    The invoice serial number



20
21
22
23
24
25
# File 'lib/ticketbai/tbai_qr.rb', line 20

def initialize(**args)
  self.id_tbai = args[:id_tbai]
  self.serial = args[:serial]
  self.number = args[:number]
  self.total = args[:total]
end

Instance Attribute Details

#id_tbaiObject

Returns the value of attribute id_tbai.



12
13
14
# File 'lib/ticketbai/tbai_qr.rb', line 12

def id_tbai
  @id_tbai
end

#numberObject

Returns the value of attribute number.



12
13
14
# File 'lib/ticketbai/tbai_qr.rb', line 12

def number
  @number
end

#serialObject

Returns the value of attribute serial.



12
13
14
# File 'lib/ticketbai/tbai_qr.rb', line 12

def serial
  @serial
end

#totalObject

Returns the value of attribute total.



12
13
14
# File 'lib/ticketbai/tbai_qr.rb', line 12

def total
  @total
end

Instance Method Details

#createString

Returns:

  • (String)

    Ticketbai QR URL



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ticketbai/tbai_qr.rb', line 31

def create
  encoded_params = [
    format_param(ID_TBAI_NAME, @id_tbai),
    format_param(SERIAL_NAME, @serial),
    format_param(NUMBER_NAME, @number),
    format_param(TOTAL_NAME, @total)
  ].join('&')

  crc = ChecksumCalculator.new(BASE_URL + encoded_params).calculate

  BASE_URL + [encoded_params, format_param(CRC_NAME, crc)].join('&')
end