Hi, Aljaz.
>I can set the value of custom attribute in consent gathering script (user.setAttribute()), but the value of the attribute is gone by the time dynscope script is run.
That's strange. Perhaps you don't finalize the process, so it's never written to LDAP db. You could check how it's handled in custom scripts which enrol/update user entries, like [this one](https://github.com/GluuFederation/oxAuth/blob/master/Server/integrations/saml/SamlExternalAuthenticator.py#L285)
>Please correct me if I'm wrong, but the way I understand your suggestion, this would require that value (payment id) of this custom attribute is updated in LDAP every time a new request is made. I don't think this is right way, as the value of payment id is specific to request, not user. How could then a user have two outstanding requests (two consents, two payments) at the same time? Sure, I could store two attributes. But how can I know which attribute belongs to which request?
You could invent some kind of protocol, store data structures, like JSON in those attributes, with a metadata of some sort, which will help to distinguish them. I'm not saying it's the best and most efficient approach, it's just a relatively easy (and crude) solution which comes to mind right away. We can't offer you a better one without dragging in our developers, and this is not allowed within Community Support, with a few exceptions.
This discussion already starts to involve quite in-depth subjects we can't afford to assist you with at Community support, unfortunately. All Gluu's codebase is available for study, so you should find some way to achieve what you need. If you would like to have support from our developers on this, please consider purchasing a support plan. I'm closing the ticket for now.