// @requirements REQ-EU-ORDER-ACTION REQ-EU-GUARANTEE-LABEL REQ-PRODUCT-MOBILE REQ-PRODUCT-A11Y import {readFile} from 'node:fs/promises'; import {createPaidOrderDefinition,createPaidOrderReview} from 'notabenda-authoring/orders'; import {buildDurabilityGuaranteeLabel} from 'notabenda-authoring/guarantees'; import {renderPaidOrderReview} from 'notabenda/orders'; const fixed=amountMinor=>({kind:'fixed',amountMinor}); export async function paidOrderFiles(){ const bytes=await readFile(new URL('../guarantees/producer/juniper-jw-01.svg',import.meta.url)),settings=JSON.parse(await readFile(new URL('../guarantees/producer/config.json',import.meta.url),'utf8')),built=buildDurabilityGuaranteeLabel(settings,bytes),files={...built.files,[built.label.asset.url.slice(1).replace(/\.svg$/u,'.NOTICE.txt')]:await readFile(new URL('../guarantees/producer/NOTICE.md',import.meta.url),'utf8'),'assets/orders.css':await readFile(new URL('../../packages/notabenda/dist/orders.css',import.meta.url),'utf8'),'assets/orders.mjs':await readFile(new URL('./client.mjs',import.meta.url),'utf8')}; const lamp={id:'lamp',productId:built.label.product.id,name:'Juniper desk lamp',kind:'goods',characteristics:['JW-01 · green powder-coated aluminium · adjustable arm.','8 W integrated LED · 2700 K warm white · EU plug.'],commitment:{duration:'One purchase; delivery within 5 working days.',termination:'14-day withdrawal period after delivery, subject to the supplied withdrawal information. Statutory rights remain.',minimum:'One lamp. No subscription or maintenance purchase is required.'},guarantee:{status:'label-provided',label:built.label}}; const planning={id:'planning',productId:'workspace-planning',name:'Workspace planning',kind:'service',characteristics:['One 30-minute remote planning appointment each month.','Appointments begin after the withdrawal period. No early-performance request is collected here.'],commitment:{duration:'Monthly subscription; renews until cancelled.',termination:'Cancel before the next monthly billing date; access continues to the end of the paid month.',minimum:'One month. No minimum commitment beyond the current paid month.'},guarantee:null}; const inspection={id:'inspection',productId:'workspace-inspection',name:'Workspace inspection',kind:'service',characteristics:['An on-site assessment of a single workspace.','A written recommendation follows the visit. The fee is payable only if you request the visit.'],commitment:{duration:'One visit, on a date agreed separately.',termination:'No automatic renewal. Withdrawal information must be supplied before ordering.',minimum:'One visit if requested; no ongoing membership.'},guarantee:null}; const templates={ mixed:{title:'A lamp. A better workspace.',description:'One purchase and a monthly service, with their own prices and commitments.',items:[lamp,planning],pricing:{currency:'EUR',fractionDigits:2,payments:[{id:'lamp-price',lineIds:['lamp'],label:'Desk lamp',amount:fixed('12900'),due:{kind:'now'},recurrence:{kind:'once'}},{id:'planning-price',lineIds:['planning'],label:'Planning membership',amount:fixed('600'),due:{kind:'now'},recurrence:{kind:'recurring',period:'Every month',cycles:null,monthlyCost:fixed('600'),changes:'€6 each month until cancelled. No introductory price.'}}],totalPrice:{kind:'calculated',method:'€129 for the lamp, plus €6 for each month of planning membership.',reason:'The membership has no fixed end date; its total depends on how long you keep it.'},dueNow:fixed('13500'),taxAndChargesNotice:'Prices include VAT and standard delivery. No other mandatory charges.'}}, deferred:{title:'Pay a deposit. See the full price.',description:'The total stays visible when part of a purchase is payable later.',items:[lamp],pricing:{currency:'EUR',fractionDigits:2,payments:[{id:'deposit',lineIds:['lamp'],label:'Lamp deposit',amount:fixed('2900'),due:{kind:'now'},recurrence:{kind:'once'}},{id:'balance',lineIds:['lamp'],label:'Lamp balance',amount:fixed('10000'),due:{kind:'later',when:'Before dispatch, within 5 working days.'},recurrence:{kind:'once'}}],totalPrice:fixed('12900'),dueNow:fixed('2900'),taxAndChargesNotice:'The €129 total includes VAT and standard delivery. No other mandatory charges.'}}, conditional:{title:'Nothing due now. Still an obligation.',description:'A payment condition and a calculation method belong beside the final action.',items:[inspection],pricing:{currency:'EUR',fractionDigits:2,payments:[{id:'inspection-fee',lineIds:['inspection'],label:'Inspection fee',amount:{kind:'calculated',method:'€40 per actual hour on site, including VAT. No travel or other fees.',reason:'The required hours depend on the workspace and cannot reasonably be calculated in advance.'},due:{kind:'conditional',condition:'Only if you request and receive the visit. Payment is due within 14 days of the invoice.'},recurrence:{kind:'once'}}],totalPrice:{kind:'calculated',method:'€40 multiplied by the actual hours on site, including VAT.',reason:'The required hours cannot reasonably be determined before the visit.'},dueNow:fixed('0'),taxAndChargesNotice:'VAT is included in the hourly rate. No travel or additional mandatory charges.'}}, }; for(const [route,template] of Object.entries(templates)){ const definition=createPaidOrderDefinition({profile:'eu-paid-distance-order-v1',siteId:'juniper-order-example',locale:'en',direction:'ltr',reviewStatus:'draft',items:template.items,documents:[]},{allowPreview:true}),quote={quoteId:'static-preview',revision:'1',contextRef:'0'.repeat(64),definitionId:definition.definitionId,issuedAt:'2026-10-19T00:00:00.000Z',expiresAt:'2026-10-19T00:15:00.000Z',lines:template.items.map(i=>({itemId:i.id,quantity:1})),pricing:template.pricing},review=createPaidOrderReview(definition,quote,{[built.label.asset.url]:bytes},{allowPreview:true}); files['orders/'+route+'/template.json']=JSON.stringify({definition,lines:quote.lines,pricing:quote.pricing}); for(const dark of [false,true]){const prefix=dark?'dark/':''; files[prefix+'orders/'+route+'/index.html']=`Order review · Juniper Notes
Juniper Notes

BEFORE YOU ORDER

${template.title}

${template.description}

Try the final action without making a purchase. No payment is taken and no contract is formed.

`; } } return files; }