Create subscription automatically on buying a product

Can anyone help me,
i have created a ecommerce website , on purchasing a product i want a subscription to be created automatically, can anyone tell me how to do this which flag to be enabled or do i have to write code for this