Overdue Invoice Chaser
Module 21 · business · intermediate
pause.js
// Pause (or resume) chasing one invoice: a promise to pay, a dispute, or "I called them".
const b = $('Pause API').first().json.body ?? {};
const id = String(b.invoice_id ?? '').trim();
if (!id) return [{ json: { ok: false, error: 'invoice_id is required' } }];
const db = $getWorkflowStaticData('global');
db.ar ??= {};
const led = (db.ar[id] ??= { sent: {} });
if (b.resume === true) { led.paused_until = null; led.pause_reason = null; }
else { led.paused_until = b.until ? String(b.until).slice(0, 10) : 'indefinite'; led.pause_reason = String(b.reason ?? 'paused'); }
return [{ json: { ok: true, invoice_id: id, paused_until: led.paused_until, reason: led.pause_reason, sent: led.sent } }];