Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

1.6 KB
Raw Blame
export function stageRates(rows,start=0){let previous=Number(start);return rows.map(row=>{if(row.kind==='ramp')previous=Number(row.target);return previous;});}
export function decodeStages(json,start=0){let previous=Number(start);const stages=JSON.parse(json);if(!Array.isArray(stages))throw Error('Stages must be an array');return stages.map(s=>{const row={kind:s.fault?'fault':s.target_rps===previous?'hold':'ramp',target:Number(s.target_rps),duration:Number(s.duration_seconds),...(s.fault?{fault:{...s.fault}}:{})};previous=row.target;return row;});}
export function encodeStages(rows,start=0){let previous=Number(start);if(!rows.length||rows.length>50)throw Error('Choose 1–50 stages');return rows.map(row=>{if(!['hold','ramp','fault'].includes(row.kind))throw Error('Choose Ramp, Hold or Fault');const target=row.kind==='ramp'?Number(row.target):previous,duration=Number(row.duration);if(!Number.isFinite(target)||target<=0||!Number.isInteger(duration)||duration<1)throw Error('Stages need positive TPS and whole-second durations');previous=target;
let fault;if(row.kind==='fault'){const f=row.fault;if(!f?.targetId||!['outage','restart','failover'].includes(f.action)||duration>300)throw Error('Choose a fault target, action and duration of 1–300 seconds');fault={targetId:f.targetId,action:f.action};}
return {target_rps:target,duration_seconds:duration,...(fault?{fault}:{})};});}
export function rampPoints(start,stages){let time=0;const points=[{t:0,value:Number(start)}];for(const s of stages){time+=s.duration_seconds;points.push({t:time,value:s.target_rps});}return points;}