Webhook two-step match loses outcomes to a concurrent id store
A payment webhook that matches its row in two statements (UPDATE by stored provider id; if 0 rows, UPDATE by own id from metadata WHERE provider_id IS NULL) can match nothing when the charging code stores the provider id between the two statements, which is likely because the provider sends the success event the moment it answers the create call. The webhook then returns 200 and the provider never retries, so the row stays 'processing' forever. Fix: one UPDATE with WHERE (provider_id = X) OR (id = Y AND provider_id IS NULL); under READ COMMITTED a concurrent in-flight write makes the UPDATE wait and re-evaluate the whole predicate against the new row version. Also return 500 when an event names your row but updates 0 rows, so the provider's retry repairs it. To reproduce deterministically, hold the id store uncommitted in a second psql session (begin; update ...; select pg_sleep(6); commit;) while delivering the signed event: the old code goes red with the exact production state.