mrsool / zatca

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

Trouble with Phase 2 - Generating a CSR #18

Closed davidfrothin closed 10 months ago

davidfrothin commented 10 months ago

I followed https://github.com/mrsool/zatca/wiki/Generating-a-CSR

1) Installed gem gem install zatca

2) Created a file called csr.rb as below

vat_id = "XXXXXXXX"

# Four digits, each digit acting as a bool. The order is as follows: Standard Invoice, Simplified, future use, future use
invoice_type = "1100"

options = {
  common_name: "XXXXXX",
  organization_identifier: vat_id,
  organization_name: "XXXXXX",
  organization_unit: "IT",
  country: "SA",
  invoice_type: invoice_type, 
  address: "Riyadh, Al Olaya D, Al Olaya, 12211",
  business_category: "IT",

  # The solution provider name
  egs_solution_name: "XXXXXXXXX",

  # The model of the unit the stamp is being generated for
  egs_model: "1000",

  # If you have multiple devices each should have a unique serial number
  egs_serial_number: "10000021"
}

# ENSURE THAT YOU USE YOUR OWN PRIVATE KEY by passing private_key_path and private_key_password.
# Otherwise the SDK will generate a passwordless one and delete it (this is only for testing purposes)
# Modes:
# :production (Via Fatoora Portal)
# :sandbox (Via Developer Portal)
# :simulation (Via Fatoora Portal - Simulation)
# For the sandbox set production_mode to false, otherwise set it to true. It is true by default.
#generator = ZATCA::Signing::CSR.new(csr_options: options, mode: :production)
generator = ZATCA::Signing::CSR.new(csr_options: options, mode: :sandbox)

# This is the CSR as PEM
csr = generator.generate

# ZATCA's API expects us to encode the PEM to Base64
csr_base64 = Base64.strict_encode64(csr)

# Construct an unauthenticated API client, this is the only endpoint that is unauthenticated
client = ZATCA::Client.new(username: "", password: "")

# Get this OTP from Fatoora portal
otp = "111111" 
response = client.issue_csid(csr: csr_base64, otp: otp)

# Output the response
puts "Response: #{response}"

3) Error when running rb file ruby csr.rb

csr.rb:34:in `<main>': uninitialized constant ZATCA (NameError)

generator = ZATCA::Signing::CSR.new(csr_options: options, mode: :sandbox)
                          ^^^^^

4) gem list (this shows Zatca)

*** LOCAL GEMS ***

abbrev (default: 0.1.1)
actioncable (7.0.4)
actionmailbox (7.0.4)
actionmailer (7.0.4)
actionpack (7.0.4)
actiontext (7.0.4)
actionview (7.0.4)
activejob (7.0.4)
activemodel (7.0.4)
activerecord (7.0.4)
activestorage (7.0.4)
activesupport (7.0.4)
base64 (default: 0.1.1)
benchmark (default: 0.2.1)
bigdecimal (default: 3.1.3)
builder (3.2.4)
bundler (2.4.22, default: 2.4.10)
cgi (default: 0.3.6)
chunky_png (1.4.0)
concurrent-ruby (1.2.2)
crass (1.0.6)
csv (default: 3.2.6)
date (default: 3.3.3)
debug (1.7.1)
delegate (default: 0.3.0)
did_you_mean (default: 1.6.3)
digest (default: 3.1.1)
drb (default: 2.1.1)
dry-configurable (1.1.0)
dry-core (1.0.1)
dry-inflector (1.0.0)
dry-initializer (3.1.1)
dry-logic (1.5.0)
dry-schema (1.13.3)
dry-types (1.7.1)
english (default: 0.7.2)
erb (default: 4.0.2)
error_highlight (default: 0.5.1)
erubi (1.12.0)
etc (default: 1.4.2)
fcntl (default: 1.0.2)
fiddle (default: 1.1.1)
fileutils (default: 1.7.0)
find (default: 0.1.1)
forwardable (default: 1.3.3)
getoptlong (default: 0.2.0)
globalid (1.2.1)
http-2-next (1.0.1)
httpx (0.21.1)
i18n (1.14.1)
io-console (default: 0.6.0)
io-nonblock (default: 0.2.0)
io-wait (default: 0.3.0)
ipaddr (default: 1.2.5)
irb (default: 1.6.2)
json (default: 2.6.3)
logger (default: 1.5.3)
loofah (2.22.0)
mail (2.8.1)
marcel (1.0.2)
matrix (0.4.2)
method_source (1.0.0)
mini_mime (1.1.5)
minitest (5.20.0, 5.16.3)
mutex_m (default: 0.1.2)
net-ftp (0.2.0)
net-http (default: 0.3.2)
net-imap (0.3.4)
net-pop (0.1.2)
net-protocol (default: 0.2.1)
net-smtp (0.3.3)
nio4r (2.7.0)
nkf (default: 0.1.2)
nokogiri (1.15.5 x86_64-linux)
observer (default: 0.1.1)
open-uri (default: 0.3.0)
open3 (default: 0.1.2)
openssl (default: 3.1.0)
optparse (default: 0.3.1)
ostruct (default: 0.5.5)
pathname (default: 0.2.1)
power_assert (2.0.3)
pp (default: 0.4.0)
prettyprint (default: 0.1.1)
prime (0.1.2)
pstore (default: 0.1.2)
psych (default: 5.0.1)
racc (default: 1.6.2)
rack (2.2.8)
rack-test (2.1.0)
rails (7.0.4)
rails-dom-testing (2.2.0)
rails-html-sanitizer (1.6.0)
railties (7.0.4)
rake (13.0.6)
rbs (2.8.2)
rdoc (default: 6.5.0)
readline (default: 0.0.3)
readline-ext (default: 0.1.5)
reline (default: 0.3.2)
resolv (default: 0.2.2)
resolv-replace (default: 0.1.1)
rexml (3.2.5)
rinda (default: 0.1.1)
rqrcode (2.1.2)
rqrcode_core (1.2.0)
rss (0.2.9)
ruby2_keywords (default: 0.0.5)
securerandom (default: 0.2.2)
set (default: 1.0.3)
shellwords (default: 0.1.0)
singleton (default: 0.1.1)
starkbank-ecdsa (2.0.0)
stringio (default: 3.0.4)
strscan (default: 3.0.5)
syntax_suggest (default: 1.0.2)
syslog (default: 0.1.1)
tempfile (default: 0.1.3)
test-unit (3.5.7)
thor (1.3.0)
time (default: 0.2.2)
timeout (default: 0.3.1)
tmpdir (default: 0.1.3)
tsort (default: 0.1.1)
typeprof (0.21.3)
tzinfo (2.0.6)
un (default: 0.2.1)
uri (default: 0.12.1)
weakref (default: 0.1.2)
websocket-driver (0.7.6)
websocket-extensions (0.1.5)
yaml (default: 0.2.1)
zatca (1.0.1)
zeitwerk (2.6.12)
zlib (default: 3.0.0)
davidfrothin commented 10 months ago

Solved the issue

i missed the steps bundle init

then add line to the file require "zatca"