Module: ZATCA

Extended by:
ZATCA
Included in:
ZATCA
Defined in:
lib/zatca.rb,
lib/zatca/tag.rb,
lib/zatca/tags.rb,
lib/zatca/types.rb,
lib/zatca/version.rb,
lib/zatca/tags_schema.rb,
lib/zatca/qr_code_generator.rb

Defined Under Namespace

Modules: Hacks, Types, UBL Classes: Client, Error, Hashing, QRCodeExtractor, QRCodeGenerator, Tag, Tags

Constant Summary collapse

VERSION =
"1.1.0"
TagsSchema =
Dry::Schema.Params do
  required(:seller_name).filled(:string)
  required(:vat_registration_number).filled(:string)

  required(:timestamp).filled([:date_time, :string])

  # Using strings to avoid any floating point approximations, we're not doing
  # any calculations with these values, it's for display purposes only. A
  # string is a good fit.
  required(:invoice_total).filled(:string)
  required(:vat_total).filled(:string)

  # Data types required for Phase 2 by 1 January 2023
  optional(:xml_invoice_hash).filled(:string)
  optional(:ecdsa_signature).filled(:string)
  optional(:ecdsa_public_key).filled(:string)
  optional(:ecdsa_stamp_signature).filled(:string)
end

Class Method Summary collapse

Class Method Details

.extract_qr_base64_from_base64_invoice(base64_invoice) ⇒ Object



32
33
34
# File 'lib/zatca.rb', line 32

def self.extract_qr_base64_from_base64_invoice(base64_invoice)
  QRCodeExtractor.new(invoice_base64: base64_invoice).extract
end

.render_qr_code(tags: nil, base64: nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/zatca.rb', line 36

def self.render_qr_code(tags: nil, base64: nil)
  if tags.present?
    tags = ZATCA::Tags.new(tags) if tags.is_a?(Hash)
    QRCodeGenerator.new(tags: tags).render
  elsif base64.present?
    QRCodeGenerator.new(base64: base64).render
  else
    raise ArgumentError, "Either tags or base64 must be provided"
  end
end