State management during callbacks

This is more of an implementation detail. I have a function which sends a request to the gateway and also have an endpoint which responds to the callback by the gateway and this endpoint is handled by a function. But how do I know that the second function should respond to the initial user who triggered the first function. That is, is there a way to identify the state of the user?

Each call to the Gateway APIs require a unique transaction id . In the callback response Gateway responds with same transaction Id. When many sessions are running simultaneosly , The call back api responses can be stored against transaction id in a global array or tables.After subscribing the same by application you can remove it from the array and proceed with further actions.