American Express interview question

How to make this code secure based on a use case?