Yes, this can definitely be done. You could setup a merchant account & gateway with someone and then have your gateway "pass back" the order details along with a sessionID of some kind after a successful transaction.
Then your script on your site could auto-generate or release the registration code to the customer. You'll of course want to employ some standard security methods to ensure that people don't try to spoof a "real" order in an attempt to get free software

but beyond that... it is not too hard to setup the above.