// Force-expire the latest pending payment_session by hitting the dev-only
// /internal/_test/force-expire-payment endpoint. Used by the Stage 3 maestro
// flow (04_payment_expired.yaml) to drive the waiting screen into expired
// without waiting 20 minutes.
//
// Strategy: query the latest pending payment_session via raw SQL through the
// reset-phone endpoint? — actually no, we don't have an SQL surface. Instead,
// we expose a tiny "expire-latest-pending" variant: pass `latest=true` and
// the backend looks up the most-recent pending row.
//
// Reads BACKEND_INTERNAL_URL from env (Maestro injects it from the flow).
const url = BACKEND_INTERNAL_URL || 'http://localhost:3001'
const resp = http.post(`${url}/internal/_test/force-expire-payment`, {
  body: JSON.stringify({ latest: true }),
  headers: { 'Content-Type': 'application/json' },
})
if (resp.status !== 200) {
  throw new Error(`force-expire-payment failed (${resp.status}): ${resp.body}`)
}
const data = json(resp.body)
output.PAYMENT_ID = data.id
