Most ecommerces offer to their customers 2 basic options in cases when they wanna return one or more items to the store, for some reason such as wrong size or color, whatever. Those options are: choosing if they prefer either get a coupon in the purchase value or a refund using the same way the customer used to pay an order. In Magento is already possible to make a refund, online or manually, doesn't matter.
So now, I would like to know if would be possible generating a coupon automatically with a credit memo, maybe using a custom status like "voucher issued" and assigned to the "closed" state. I know that already there is some extensions to do that, but I'm not looking for extensions at this first time.
In summary, is it possible to do that programatically? Alternative ways could be help me a lot too.