The notice is a hint, not the truth
Mercado Pago sends a notice when a payment changes. That notice can arrive repeated, late or out of order, so the server never trusts its body: it checks the signature in constant time, drops an old timestamp, records the event only once and reads the payment again from the provider API.
// Order of the states of ONE payment: a rank below the order's rank is a late event
export function paymentStatusRank(status: string) {
switch (status) {
case 'charged_back': return 60;
case 'refunded': return 50;
case 'partially_refunded': return 40;
case 'paid': case 'payment_in_mediation': return 30;
case 'payment_rejected': case 'payment_cancelled': case 'payment_expired': return 25;
case 'payment_authorized': return 20;
case 'payment_in_process': return 15;
default: return 10;
}
}
