Learning by ear is a simple task. You listen to something and write down or memorize what you hear. Simple, but sometimes difficult. Sometimes frustrating. Sometimes impossible.
Go one note at a time. Listen to the first note. Listen to it as many times as you need to to figure out what it is. Listen to the note, play a note, listen to the note, play a note. Repeat until you find the correct note. There are a limited number of options, so eventually you will find the correct note. Then move on to the next note.
At first this may be a painfully difficult process. It may take you what you perceive to be an unreasonably long period of time to figure out just one note. It’s not. It’s exactly the amount of time it takes. And it’s going to take less time next time.
You can’t skip any part of this process. Your ear will gradually develop whether you like it or not. If you focus and work hard it will develop a little faster, but you’re not going to skip to the front of the line.