Run a custom function when a user has paid for signup, based on custom field

Hi there

When my users sign up for the first time, they will be paying for virtual tickets in a lottery.

They can purchase between 1-5 tickets. I want to make the signup process as easy as possible so that it's taken care of in one step, they order their tickets, they are subscribed to a given level in Membership, and they choose their password, all in one step.

My extra bit of logic is that I need to run my own custom function that issues the tickets, once the user has subscribed and paid.

How can I customise the signup process and also the callback scripts?

Thanks