You can use findReference
from @solana/pay
which will make this a bit easier: https://docs.solanapay.com/api/core/function/findReference
But fundamentally you're doing the right thing, you need to look for transactions that include your reference key.
In terms of why it's not working, are you using Phantom wallet by any chance to scan the code and send the transaction? There's currently a bug in their transfer request handling where the reference
isn't being included as part of the transaction so this logic isn't working. Try using another wallet and see if that fixes it for you.
You can verify if the transaction includes the reference key you expect too, if you look it up in explorer, for example by searching the address of your wallet that's making the payment. That's the signer of the transaction so it'll definitely be there. If your reference is not included then that's a bug in the wallet.