The timing and circumstances of the act of repentance determines the quality and credibility of my repentance.
Maimonides writes in Hilkhot Teshuba 2: 1.“What is considered a perfect and complete repentance? When one is confronted with the same opportunity to repeat the original transgression, but now he does not do it because he has repented … however, when one does not repeat the original transgression, [ and refrains from sinning] because now he fears that other people would find out … his repentance is accepted, but this is not considered a perfect repentance. “
To explain the ideal scenario of Teshuba, Maimonides brings the example of a man who was involved in an adulterous relationship which now he regrets. What would demonstrate that his repentance is credible? If he is faced with a similar opportunity to repeat his mistake and now refrains from it because he has reached a new moral conscience and understanding, i.e., he now realizes that being carried away by his impulses will hurt him spiritually and will destroy his family, etc.
However, if the sinner abstains from making the same transgression, not because of a renewed understanding but because now he fears being seen his Teshuba / repentance is accepted, but this kind of repentance is far from ideal. Why? Because this individual did not reach a renewed understanding of what is right and what is wrong: he has repented because he fears being caught.
Another example. An employee was caught in an act of corruption, like stealing money, etc. Many times, after being caught, the disgraced employee might express his remorse and regret for he has done. This is certainly a brave gesture of repentance. However, this act of repentance is questionable in terms of its credibility. Why? Because the process of repentance and apology did not happen before being caught but as a result of being caught. It is very likely that what is pushing this person to repent is NOT a new moral conscience, but the interest of a reduced conviction, a better sentence, to save the honor of his family, etc.
In this scenario, what would be considered an act of a “perfect” repentance? If this employee, while still doing his job and without any risk of being caught, realizes his mistake by the call of his own conscience; understands that what he was doing was immoral, and now he repents, ask forgiveness and gives the money back, etc. That would be a case of a perfect and credible Teshuba.