I have an iPhone 7 Plus in good condition.
Today it was connected to my Mac (I'm an app developer, I was debugging an app) and noticed that my iPhone wasn't charging. My app was debugging properly (so data connection to my Mac was fine) but I've realized that it wasn't charging when it ran out of battery while connected to my Mac over USB.
I've plugged it out and back in. It had trouble turning on for about 15 minutes after plugging in. Then it turned on and I didn't really pay attention as it turned on.
After a long time connected to my Mac, I've plugged it out and in a few minutes it turned off again due to low battery. It was weird. I've thought there is a problem with my Mac or that particular lightning cable so I've plugged it to the original Apple AC adapter with another lightning cable. Same results.
No matter where it's plugged in, my iPhone is refusing to charge or is charging extremely slowly.
How can I fix the problem?