0% found this document useful (0 votes)
5 views2 pages

Generate Aadhar OTP Method in Ruby

Uploaded by

shalinijainnov1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Generate Aadhar OTP Method in Ruby

Uploaded by

shalinijainnov1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Appendix

Improved File/method with about 30 mins colaboration with genAI.

def generate_aadhar_otp

begin

encrypted_aadhar = RsaEncryption.oaep_mgf1_padding(params["aadhar"])

auth_token = AbhaWebService.authenticate_abha

otp_response = AbhaWebService.generate_aadhar_otp(encrypted_aadhar,
auth_token)

case otp_response[:resp_status]

when "200"

# @otp_txn_id = [Link](otp_response[:resp_body])["txnId"]

@response = { status: "success", txn_id: @otp_txn_id }

when "400"

[Link]("Bad Request: #{otp_response[:resp_body]}")

@response = { status: "error", message: "Invalid request parameters", error:


otp_response[:resp_body] }#, status: :bad_request

when "401"

[Link]("Unauthorized: #{otp_response[:resp_body]}")

@response = { status: "error", message: "Authentication failed", error:


otp_response[:resp_body] }#, status: :unauthorized

when "404"

[Link]("Not Found: #{otp_response[:resp_body]}")

@response = { status: "error", message: "Resource not found", error:


otp_response[:resp_body] }#, status: :not_found

when "429"

[Link]("Rate Limited: #{otp_response[:resp_body]}")

@response = { status: "error", message: "Too many requests, please try again later",
error: otp_response[:resp_body] }#, status: :too_many_requests
when "500"

[Link]("ABHA Service Error: #{otp_response[:resp_body]}")

@response = { status: "error", message: "ABHA service is currently unavailable",


error: otp_response[:resp_body] }#, status: :service_unavailable

else

[Link]("Unexpected Response: #{otp_response[:resp_body]}")

@response = { status: "error", message: "Unexpected response from ABHA


service", error: otp_response[:resp_body] }#, status: :unprocessable_entity

end

rescue JSON::ParserError => e

[Link]("JSON parsing error: #{[Link]}")

@response = { status: "error", message: "Invalid response format" }#,


status: :internal_server_error

rescue StandardError => e

[Link]("Error generating Aadhar OTP: #{[Link]}")

[Link]([Link]("\n"))

@response = { status: "error", message: "Something went wrong" }#,


status: :internal_server_error

end

end

You might also like