I think this may be too early. I worry what happens if the invoice creation fails after this. Would it be better to set the key separately: on successful invoice creation, AND if `existing` is already present?