Here are a few steps you can try:
1. Check the Charging Port: Sometimes dust or debris can accumulate in the charging port, preventing proper contact. Carefully clean the port with a dry, non-metallic object like a toothpick or a small brush.
2. Check for Software Updates: Go to Settings > Software Update and check for any available updates. Installing the latest software can sometimes fix charging issues.
3. Battery Health: If the phone is still under warranty, it might be worth visiting a Samsung service center for a professional diagnosis. There could be an issue with the battery itself.