Simple Contract that buys another token

Hi, I'm learning solidity and I was working on a personal project that does the following:

user sends BNB + gas to a contract, this contract applies some fees to it and buy another specific token then sends it back to the buying user. A second option is to have a calling function that does that. In case of fail, user would be able to reclaim that via contract function.

Does anyone have an idea on how I could implement this (logic or any contract that already goes similar)?

You're probably looking at some kind of smart contract integration with a dex e.g. quickswap. Take a look at this https://docs.uniswap.org/protocol/V2/guides/smart-contract-integration/quick-start (it says uniswap but it's fine cause quickswap is a fork of uniswap anyway).

You'll probably need to add an additional reclaimFunds() function for when transactions fail and some mapping to keep track of this.

That's great, thanks! I will take a look on that and do some tests on testnet