Stripe themselves have a number of examples: https://stripe.com/docs/quickstart
And to generate a key after the purchase is made, use this LimeLM web API call: https://wyday.com/limelm/help/api/limelm.pkey.generate/
If you tell us more (for starters, what programming language you're using) we can give you more information.