mrsool / zatca

An unofficial Ruby library for generating ZATCA e-invoices, QR Codes, and submitting e-invoices to ZATCA's servers.
MIT License
40 stars 16 forks source link

out of char range when generating tags for qrcode #30

Closed Anas-Nabulsi closed 7 months ago

Anas-Nabulsi commented 7 months ago

I'm facing this error here at tag 8 and 9 respectively... any guidance is appreciated

C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/zatca-1.1.0/lib/zatca/tag.rb:40:in chr': 550 out of char range (RangeError) from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/zatca-1.1.0/lib/zatca/tag.rb:40:into_tlv' from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/zatca-1.1.0/lib/zatca/tags.rb:47:in map' from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/zatca-1.1.0/lib/zatca/tags.rb:47:into_tlv' from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/zatca-1.1.0/lib/zatca/tags.rb:33:in `to_base64'

C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/zatca-1.1.0/lib/zatca/tag.rb:40:in chr': 512 out of char range (RangeError) from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/zatca-1.1.0/lib/zatca/tag.rb:40:into_tlv' from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/zatca-1.1.0/lib/zatca/tags.rb:47:in map' from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/zatca-1.1.0/lib/zatca/tags.rb:47:into_tlv' from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/zatca-1.1.0/lib/zatca/tags.rb:33:in `to_base64'


tags = ZATCA::Tags.new({
  seller_name: "Acme Widgets LTD",
  vat_registration_number: "311111111101113",
  timestamp: invoice_timestamp,
  vat_total: "30.15",
  invoice_total: "231.15",
  xml_invoice_hash: invoice_hash,

  # These 3 properties on the invoice assume you have signed it before.
  # They are nil unless signed.
  ecdsa_signature: invoice.signed_hash,
  ecdsa_public_key: invoice.public_key_bytes,
  ecdsa_stamp_signature: invoice.certificate_signature
})

# Turn the tags to TLV and then encode that TLV to base64
invoice.qr_code = tags.to_base64
obahareth commented 7 months ago

@Anas-Nabulsi Would you be able to privately share a similar version of your certificate/key with some obfuscated information? (but generally the same kind of characters)

Please make sure these are never used on production on your end.

Anas-Nabulsi commented 7 months ago

@obahareth , you actually pointed me to the right direction. It was an incorrect certificate and key. After I ensured they are correct, it worked perfectly. Thanks a lot.