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}"
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
3) Error when running rb file ruby csr.rb
4) gem list (this shows Zatca)