How to generate a random transaction id which is unused

I will give first example

Note : - i am talking about firebase as the server and caution my english is R.I.P.
because even i don’t what i am talking about acctually.

You have seen in many payment apps like paypal or paytm (only India) that every single transaction have its own unique id and which is used to access the order details or payment details.

I also want to implement one as like them.

I tried is
that user gets a unsed id registered in the firebase like sr.no. when app requests a id it will return the sr no. like if the transaction is first transaction then sr no . will be 0 and will get changed to 1 after payment is done and when second payment takes place it automattically gets changed to 2 and then 3…
But this is causing error when multiple transactions take place at one time.

I have decided to keep a long automatic generated string and then our app will verify its available or not and if its available then it will directly registered to fail and then the payment will success then it will add the details of payment to that tag on firebase.

But wondering if this feature have any drawbacks please help me.

u can use 1+1 method and each and every tag save transaction info (money,time,date, to person )

You can do

If (getValue = generatedID) { // Generate a new ID randomNumber(); } else if (getValue ≠ generatedID) { // Do nothing }