Unique code for user to register

Are you sending the invitations by hand?

If so, you could instead have your sales backend send an API call to Discourse that generates the invite and sends it to the user.

If you don’t want to have this happen on every purchase, you could also put a page on your site that verifies the transaction ID and calls the invite API.

This might be a more straightforward approach than a plugin.