Tried that when my kid was 5. After a few months of this she told me to stop it, because when she messed up she realized she also wouldn’t get her reward, which led to a ridiculously prolonged tantrum. She said she would rather rarely get a toy than have to go through that, and she has been as good as her word ever since. She must be one of the few kids in the universe that can calmly play and then exit a packed toy store after being told she can look, but we cannot get a thing. Honestly, I’m just glad she was able to verbalize the problem, because there was so much else going on, we couldn’t be sure if the rewards were helping or hurting.
May work for a middle schooler, if you find something that a) would really motivate him, and b) he is actually capable of achieving what you want him to. My kid was simply unable to do all what was required of her at that time.