Set and read session data via jquery ejs file

I am currently developing a Braintree payment integration which requires to call an UI using jQuery. This works so far. I implemented this step in the code section. However on button submit inside the UI it generates an paymentId and I would like to store that paymentId in the session storage manager. I can’t find any documentation on how to do this in the code section for a .ejs file. Is there any tutorial for this. I need the ID so I can call an endpoint in the server connect.

Can you explain a little more detailed what data and how do you need to use? How do you receive it and what needs to be done with it?

Braintree has a dropin-ui plugin for jquery. It listens for a button on click and the payment info is processed and returns a payment method ID which I need to use to make transfers for example. The main problem is that this id is only in the code accessible (.ejs file). What would be the best way to handle this so I can use it in my server actions side? Because I need that id to use in other pages + call end points which requires this payment id

Maybe @patrick can help here.