stage11-shopping-review.py
TEXT FILE740 B · Public source code for developers, search crawlers and AI agents
1def review(quote, merchant, now, ceiling):
2 if quote.get('merchant') != merchant:
3 raise ValueError('merchant mismatch')
4 amount = quote.get('amount_sat')
5 expiry = quote.get('expires_at')
6 if type(amount) is not int or not 0 < amount <= ceiling:
7 raise ValueError('amount rejected')
8 if type(expiry) is not int or expiry <= now:
9 raise ValueError('expired quote')
10 return {'status':'review_required','amount_sat':amount}
11
12if __name__ == '__main__':
13 q = {'merchant':'demo','amount_sat':1200,'expires_at':200}
14 assert review(q,'demo',100,2000)['status'] == 'review_required'
15 try: review(q,'demo',200,2000)
16 except ValueError: pass
17 else: raise AssertionError('expired quote accepted')Read-only source · Select a line number to link directly · Raw download above
