Also, I am not looking for options like BitPay or CoinGate. I want to learn how to develop it from scratch.
BitPay is good for marcents point of view but it sucks in customers point of view. As a customer to purchase anything from a site which ask pay to bitpay is annoying to me.
Give me few minutes to find you something from Google as I know there is something which allows you to integrate bitcoin payments in your site like without giving any fees and stuffs. One can do it using the bitcoin core they have.
Edit: Check step 3 in this article:
https://blog.blockonomics.co/accepting-bitcoin-do-you-need-a-payment-gateway-832487d3b84cIf I am not massively wrong then this is the solution you are looking at.