Sorry to hear that! It does happen and sometimes you cannot do anything about it. Sometimes fish get a internal bacterial infection you can do little about because it attacks their organs.
My first betta (Robin) died in a simular way, he stopped swimming and faded then died shortly after. It was my 3yr old daughters very first pet, and daddy could do nothing to save him, even though he posted and did everything he knew.
My 2nd fish (Finchy) got a REAL bad case of Fungus a few days after we had him, but this time we where able to save him and he is doing fine.
Give your tank a real good clean. I have acrylic tanks so I use water/vinegar to sanitize the tank and decorations, and boiling hot water (kettle) for the gavel (put the gravel in a bowl) for a few minutes and let it dry completely. If you have a glass tank, you can use a water/bleach combination, just make sure to rinse it really well and let the tank dry in the sun to neutralize any residual bleach.
I would encourage you to try again. It gets better, I promise!