Fix the status codes for a payment webhook

Review the AI's codeEasy10 minStripe style

Your task

An AI wrote a Flask webhook for payment events that wrapped everything in except Exception: pass and always returned 200. The provider took every 200 as "handled", so when fulfilment failed, nobody retried and paid orders were never shipped. The status code is the only signal the provider gets: 200 means done, 400 means never send it again, and 500 means send it again later.

An assistant wrote webhook_response_status(outcomes). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • outcomes: what happened to each incoming event, in order, as a short code such as ok or db_error.
  • Return the HTTP status to send for each event, in the same order, as integers.

Rules the tests check:

  • Trim whitespace from both ends of each outcome first. Codes then match exactly, case included.
  • 200 for ok and duplicate (a replay of an event already handled).
  • 400 for bad_payload and bad_signature. A retry would fail the same way.
  • 500 for unknown_order, db_error and fulfill_error. These can succeed on a later retry: an unknown_order event often arrives before the order it refers to is saved.
  • 500 for any other code, including an empty one, so an unexpected failure is retried rather than marked done.

Examples

webhook_response_status(outcomes: list[str]) -> list[int]
Example 1
Inputwebhook_response_status(["ok", "db_error", "fulfill_error"])
Output[200, 500, 500]
Example 2
Inputwebhook_response_status(["bad_payload", "duplicate"])
Output[400, 200]
Example 3
Inputwebhook_response_status([])
Output[]