What is the best way to integrate coupons into the purchasing process and is there any example code available?
Well, this has to do with your payment processor. Depending on what payment processor you use this process will be different.
We would also like to be able to store the coupon code used in a custom licence field for future reference.
Sure, you can set the custom license fields at the time you create the product key.