@fleetless/contracts 6.5.0 → 7.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/artifacts/openapi.json +5805 -1805
- package/artifacts/routes.json +75 -13
- package/artifacts/schema/addon-catalogue-entry.schema.json +1 -15
- package/artifacts/schema/billing-address.schema.json +7 -1
- package/artifacts/schema/billing-change-request.schema.json +9 -0
- package/artifacts/schema/billing-change-response.schema.json +2219 -625
- package/artifacts/schema/billing-details-update.schema.json +70 -0
- package/artifacts/schema/billing-details.schema.json +27 -3
- package/artifacts/schema/billing-view.schema.json +56 -24
- package/artifacts/schema/checkout-request.schema.json +90 -154
- package/artifacts/schema/checkout-response.schema.json +531 -17
- package/artifacts/schema/invoice-pay-request.schema.json +16 -0
- package/artifacts/schema/payment-method-change-request.schema.json +7 -0
- package/artifacts/schema/plan-catalogue-entry.schema.json +1 -15
- package/artifacts/schema/plan-prices.schema.json +1 -15
- package/artifacts/schema/purchase-billing-details.schema.json +111 -0
- package/artifacts/schema/purchase-conflict-details.schema.json +582 -0
- package/artifacts/schema/purchase-hold-reason.schema.json +9 -0
- package/artifacts/schema/purchase-intent-confirm-request.schema.json +40 -0
- package/artifacts/schema/purchase-intent-lookup-query.schema.json +56 -0
- package/artifacts/schema/purchase-intent-response.schema.json +1554 -0
- package/artifacts/schema/purchase-operation-key.schema.json +7 -0
- package/artifacts/schema/purchase-operation.schema.json +11 -0
- package/artifacts/schema/purchase-quote.schema.json +43 -0
- package/artifacts/schema/purchase-refusal-rule.schema.json +13 -0
- package/artifacts/schema/vat-decision.schema.json +77 -0
- package/artifacts/schema/vat-id-check-response.schema.json +111 -25
- package/artifacts/schema/vies-pending-reason.schema.json +9 -0
- package/dist/billing.d.ts +1128 -75
- package/dist/billing.js +174 -66
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/plans.d.ts +4 -9
- package/dist/plans.js +4 -7
- package/dist/routes.js +33 -60
- package/package.json +1 -1
package/dist/billing.js
CHANGED
|
@@ -27,9 +27,9 @@ export const DE_VAT_RATE_PERCENT = 19;
|
|
|
27
27
|
export function isEuCountry(country) {
|
|
28
28
|
return EU_COUNTRIES.includes(country);
|
|
29
29
|
}
|
|
30
|
-
/** EUR
|
|
31
|
-
export function currencyForCountry(
|
|
32
|
-
return
|
|
30
|
+
/** All new purchase prices are EUR, independent of the billing country. */
|
|
31
|
+
export function currencyForCountry(_country) {
|
|
32
|
+
return 'eur';
|
|
33
33
|
}
|
|
34
34
|
/** Who is paying: a company (may hold a VAT ID) or a person (a full name, never a VAT ID). */
|
|
35
35
|
export const payerKind = z.enum(['company', 'person']);
|
|
@@ -41,37 +41,39 @@ export const billingCycle = z.enum(['monthly', 'yearly']);
|
|
|
41
41
|
* reverse-charge note).
|
|
42
42
|
*/
|
|
43
43
|
export const vatTreatment = z.enum(['de_standard', 'reverse_charge', 'outside_eu']);
|
|
44
|
+
/** A refusal of a new paid purchase, never a restriction on free Basic. */
|
|
45
|
+
export const payerRefusalRule = z.enum(['company_required', 'vat_id_required', 'vat_id_invalid']);
|
|
46
|
+
export const viesPendingReason = z.enum(['vies_unavailable', 'vies_unverified', 'vies_identifier_missing']);
|
|
47
|
+
export const vatDecision = z.discriminatedUnion('state', [
|
|
48
|
+
z.object({ state: z.literal('eligible'), treatment: vatTreatment, rate_percent: z.number().int().min(0).max(100) }).strict(),
|
|
49
|
+
z.object({ state: z.literal('pending'), reason: viesPendingReason }).strict(),
|
|
50
|
+
z.object({ state: z.literal('refused'), rule: payerRefusalRule }).strict(),
|
|
51
|
+
]);
|
|
44
52
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
|
|
50
|
-
export const payerRefusalRule = z.enum(['eu_person', 'vat_id_required', 'vat_id_invalid']);
|
|
51
|
-
/**
|
|
52
|
-
* Who may pay, and the VAT they pay. `vatIdValid`: `null` = no VAT ID
|
|
53
|
-
* given; `true` = VIES valid **or unverified** (VIES unreachable is
|
|
54
|
-
* accepted); `false` = VIES said invalid.
|
|
55
|
-
*
|
|
56
|
-
* Germany is unconditional — company or person, VAT ID optional, 19 %
|
|
57
|
-
* regardless of whether a given ID checks out. A German VAT ID's validity
|
|
58
|
-
* never gates checkout, only the renewal sweep later (dunning);
|
|
59
|
-
* `vatFor` only ever prices the charge in hand.
|
|
53
|
+
* New paid purchase VAT classification. `vies: null` means no VAT ID;
|
|
54
|
+
* unverified/unavailable means an ID was supplied but has no definitive evidence.
|
|
55
|
+
* Only a direct, current-buyer VIES verdict with an identifier permits reverse charge.
|
|
56
|
+
* Cloud separately validates complete purchase details and the current email policy,
|
|
57
|
+
* and binds the evidence to the buyer and quote under its charge lock.
|
|
60
58
|
*/
|
|
61
59
|
export function vatFor(input) {
|
|
62
|
-
const { kind, country,
|
|
60
|
+
const { kind, country, vies } = input;
|
|
61
|
+
if (kind !== 'company')
|
|
62
|
+
return { state: 'refused', rule: 'company_required' };
|
|
63
63
|
if (country === SELLER_COUNTRY)
|
|
64
|
-
return {
|
|
65
|
-
if (isEuCountry(country))
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return
|
|
64
|
+
return { state: 'eligible', treatment: 'de_standard', rate_percent: DE_VAT_RATE_PERCENT };
|
|
65
|
+
if (!isEuCountry(country))
|
|
66
|
+
return { state: 'eligible', treatment: 'outside_eu', rate_percent: 0 };
|
|
67
|
+
if (vies === null)
|
|
68
|
+
return { state: 'refused', rule: 'vat_id_required' };
|
|
69
|
+
if (vies.status === 'invalid')
|
|
70
|
+
return { state: 'refused', rule: 'vat_id_invalid' };
|
|
71
|
+
if (vies.status === 'valid') {
|
|
72
|
+
return vies.requestIdentifier?.trim()
|
|
73
|
+
? { state: 'eligible', treatment: 'reverse_charge', rate_percent: 0 }
|
|
74
|
+
: { state: 'pending', reason: 'vies_identifier_missing' };
|
|
73
75
|
}
|
|
74
|
-
return {
|
|
76
|
+
return { state: 'pending', reason: vies.status === 'unavailable' ? 'vies_unavailable' : 'vies_unverified' };
|
|
75
77
|
}
|
|
76
78
|
/** VIES's member-state code: `EL` for `GR`, the country otherwise. */
|
|
77
79
|
export function viesCountry(country) {
|
|
@@ -99,7 +101,9 @@ export function normalizeVatId(country, raw) {
|
|
|
99
101
|
return vies + cleaned;
|
|
100
102
|
}
|
|
101
103
|
function priceKeyFor(cycle, currency) {
|
|
102
|
-
|
|
104
|
+
if (currency !== 'eur')
|
|
105
|
+
throw new Error('billing: new prices require EUR; read historical amounts from their recorded snapshots');
|
|
106
|
+
return `eur_${cycle === 'monthly' ? 'month' : 'year'}`;
|
|
103
107
|
}
|
|
104
108
|
function planPriceCentsFor(plan, cycle, currency) {
|
|
105
109
|
const prices = PLANS[plan].prices;
|
|
@@ -172,6 +176,7 @@ export function remainingDays(now, end, days) {
|
|
|
172
176
|
*/
|
|
173
177
|
export function changeNetCents(input) {
|
|
174
178
|
const { from, to, currency, periodStart, periodEnd, now } = input;
|
|
179
|
+
priceKeyFor(to.cycle, currency); // Also reject a non-EUR zero-charge change.
|
|
175
180
|
const days = periodDays(periodStart, periodEnd);
|
|
176
181
|
const remaining = remainingDays(now, periodEnd, days);
|
|
177
182
|
if (from.cycle === 'monthly' && to.cycle === 'yearly') {
|
|
@@ -243,13 +248,14 @@ export const BILLING_LOCK_DAY = 14;
|
|
|
243
248
|
* nothing here invents a cent amount of its own.
|
|
244
249
|
* ---------------------------------------------------------------------------
|
|
245
250
|
*/
|
|
246
|
-
/**
|
|
251
|
+
/** Historical address read and owner edit shape; purchase validation is stricter. */
|
|
247
252
|
export const billingAddress = z.object({
|
|
248
253
|
line1: z.string().trim().min(1).max(200).meta({ description: 'Street and number, or the first address line.' }),
|
|
249
254
|
line2: z.string().trim().max(200).nullable().meta({ description: 'A second address line, or `null` when there is none.' }),
|
|
250
255
|
postal_code: z.string().trim().min(1).max(20).meta({ description: 'Postal or ZIP code.' }),
|
|
251
256
|
city: z.string().trim().min(1).max(100).meta({ description: 'City or town.' }),
|
|
252
|
-
country: countryCode.meta({ description: "The billing country
|
|
257
|
+
country: countryCode.meta({ description: "The billing country, used for purchase eligibility and VAT." }),
|
|
258
|
+
state: z.string().trim().min(1).max(100).optional().meta({ description: "State or region. A new US purchase requires a two-letter state code; historical addresses may omit it." }),
|
|
253
259
|
}).strict();
|
|
254
260
|
/**
|
|
255
261
|
* Who is paying: a `company` (may hold a VAT
|
|
@@ -264,8 +270,9 @@ export const billingDetails = z.discriminatedUnion('kind', [
|
|
|
264
270
|
kind: z.literal('company').meta({ description: 'Billed as a company.' }),
|
|
265
271
|
company_name: z.string().trim().min(1).max(200).meta({ description: "The company's legal name, printed on the invoice." }),
|
|
266
272
|
vat_id: z.string().trim().max(20).nullable().meta({
|
|
267
|
-
description: "The company's VAT ID, or `null` for none. Required
|
|
273
|
+
description: "The company's VAT ID, or `null` for none. Required for a new purchase in another EU country; direct VIES must confirm it with an identifier.",
|
|
268
274
|
}),
|
|
275
|
+
tax_id: z.string().trim().max(100).nullable().optional().meta({ description: "Free-text Tax ID. Required for a new non-EU purchase; historical records may omit it." }),
|
|
269
276
|
address: billingAddress.meta({ description: 'The billing address.' }),
|
|
270
277
|
invoice_email: z.email().meta({ description: 'Where invoices and billing mail are sent.' }),
|
|
271
278
|
}).strict().meta({ description: "A company: name and an optional VAT ID, never 'full name'." }),
|
|
@@ -276,31 +283,116 @@ export const billingDetails = z.discriminatedUnion('kind', [
|
|
|
276
283
|
invoice_email: z.email().meta({ description: 'Where invoices and billing mail are sent.' }),
|
|
277
284
|
}).strict().meta({ description: 'A person: a full name, never a VAT ID — only a company can be VAT-registered.' }),
|
|
278
285
|
]);
|
|
279
|
-
/**
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
286
|
+
/** New paid write shape. Historical payer reads keep using `billingDetails`. */
|
|
287
|
+
export const purchaseBillingDetails = billingDetails.options[0].superRefine((payer, ctx) => {
|
|
288
|
+
const country = payer.address.country;
|
|
289
|
+
if (isEuCountry(country) && country !== SELLER_COUNTRY && !payer.vat_id?.trim()) {
|
|
290
|
+
ctx.addIssue({ code: 'custom', path: ['vat_id'], message: 'vat_id_required' });
|
|
291
|
+
}
|
|
292
|
+
if (!isEuCountry(country) && !payer.tax_id?.trim()) {
|
|
293
|
+
ctx.addIssue({ code: 'custom', path: ['tax_id'], message: 'tax_id_required' });
|
|
294
|
+
}
|
|
295
|
+
if (country === 'US' && !/^[A-Z]{2}$/.test(payer.address.state ?? '')) {
|
|
296
|
+
ctx.addIssue({ code: 'custom', path: ['address', 'state'], message: 'us_state_required' });
|
|
297
|
+
}
|
|
298
|
+
}).meta({ description: 'New company purchase. Other EU countries require VAT ID; non-EU requires Tax ID; US requires two-letter state. Cloud additionally checks the versioned public-email policy and current VIES evidence.' });
|
|
299
|
+
/** Generate before POST, persist across reloads; unique within the authenticated org. */
|
|
300
|
+
export const purchaseOperationKey = z.uuid().meta({ description: 'Client-generated UUID persisted before the start request. Unique per org and reused only for identical input.' });
|
|
301
|
+
export const purchaseOperation = z.enum(['checkout', 'paid_change', 'invoice_payment', 'payment_method_invoice', 'mandate_setup']);
|
|
302
|
+
const chargeOperation = purchaseOperation.exclude(['mandate_setup']);
|
|
303
|
+
/** Starting a checkout records an intent; only confirming its current quote may create a payment. */
|
|
287
304
|
export const checkoutRequest = z.object({
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
}),
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
305
|
+
operation_key: purchaseOperationKey,
|
|
306
|
+
plan: z.enum(['plus', 'pro']).meta({ description: 'The paid plan to buy; Basic requires no checkout.' }),
|
|
307
|
+
cycle: billingCycle.meta({ description: 'Monthly, or yearly at 15 percent off.' }),
|
|
308
|
+
addons: orgAddons.partial().strict().optional().meta({ description: 'Add-on units to buy; Pro only. Cloud refuses add-ons on Plus.' }),
|
|
309
|
+
billing: purchaseBillingDetails.meta({ description: 'The company buying the plan. Country requirements, current VIES and the email policy must pass before charging.' }),
|
|
310
|
+
accept_terms: z.literal(true).meta({ description: 'Confirms the terms of service for this purchase.' }),
|
|
311
|
+
}).strict();
|
|
312
|
+
const purchaseCents = z.number().int().nonnegative();
|
|
313
|
+
/** Current amount to confirm. Issued USD invoices must be held, never relabelled EUR. */
|
|
314
|
+
export const purchaseQuote = z.object({
|
|
315
|
+
currency: z.literal('eur').meta({ description: 'Every new quote is in EUR.' }),
|
|
316
|
+
net_cents: purchaseCents.meta({ description: 'Current charge excluding VAT, in cents.' }),
|
|
317
|
+
vat_cents: purchaseCents.meta({ description: 'VAT on the current charge, in cents.' }),
|
|
318
|
+
gross_cents: purchaseCents.meta({ description: 'Total to confirm, including VAT, in cents.' }),
|
|
319
|
+
rate_percent: z.number().int().min(0).max(100).meta({ description: 'VAT rate in whole percent.' }),
|
|
298
320
|
}).strict();
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
321
|
+
const intentIdentity = {
|
|
322
|
+
intent_id: z.uuid().meta({ description: 'Opaque persisted purchase intent identity.' }),
|
|
323
|
+
operation_key: purchaseOperationKey,
|
|
324
|
+
operation: chargeOperation,
|
|
325
|
+
invoice_id: z.uuid().optional().meta({ description: 'The due charge or issued invoice, for invoice-paying operations.' }),
|
|
326
|
+
};
|
|
327
|
+
const quoteIdentity = {
|
|
328
|
+
quote_revision: z.string().trim().min(1).max(200).meta({ description: 'Opaque revision of the displayed quote; echo it when confirming.' }),
|
|
329
|
+
buyer_fingerprint: z.string().trim().min(1).max(200).meta({ description: 'Opaque revision of buyer details and email policy; never full VIES evidence.' }),
|
|
330
|
+
};
|
|
331
|
+
export const purchaseHoldReason = z.enum(['legacy_usd_invoice', 'legacy_payer_unresolved', 'mandate_policy_unresolved']);
|
|
332
|
+
export const purchaseRefusalRule = z.enum(['company_required', 'vat_id_required', 'vat_id_invalid', 'tax_id_required', 'us_state_required', 'public_email_domain', 'invoice_not_open']);
|
|
333
|
+
// Cross-field invariants also travel in JSON Schema so non-TypeScript callers
|
|
334
|
+
// cannot treat an invoice payment as an unbound checkout or a held setup as a charge.
|
|
335
|
+
const intentRules = [
|
|
336
|
+
{ if: { properties: { operation: { enum: ['invoice_payment', 'payment_method_invoice'] } }, required: ['operation'] }, then: { required: ['invoice_id'] } },
|
|
337
|
+
{ if: { properties: { operation: { const: 'mandate_setup' } }, required: ['operation'] }, then: { properties: { state: { const: 'held' }, reason: { const: 'mandate_policy_unresolved' } }, required: ['reason'] } },
|
|
338
|
+
{ if: { properties: { reason: { const: 'mandate_policy_unresolved' } }, required: ['reason'] }, then: { properties: { operation: { const: 'mandate_setup' } } } },
|
|
339
|
+
{ if: { properties: { payment: { properties: { kind: { const: 'mandate' } }, required: ['kind'] } }, required: ['payment'] }, then: { properties: { operation: { const: 'paid_change' } } } },
|
|
340
|
+
];
|
|
341
|
+
function validateIntent(intent, ctx) {
|
|
342
|
+
if (['invoice_payment', 'payment_method_invoice'].includes(intent.operation) && !intent.invoice_id) {
|
|
343
|
+
ctx.addIssue({ code: 'custom', path: ['invoice_id'], message: 'An invoice-paying intent must name the invoice or due charge.' });
|
|
344
|
+
}
|
|
345
|
+
if ((intent.operation === 'mandate_setup') !== (intent.reason === 'mandate_policy_unresolved')) {
|
|
346
|
+
ctx.addIssue({ code: 'custom', path: ['reason'], message: 'Mandate setup remains held until its integration policy is resolved.' });
|
|
347
|
+
}
|
|
348
|
+
if (intent.payment?.kind === 'mandate' && intent.operation !== 'paid_change') {
|
|
349
|
+
ctx.addIssue({ code: 'custom', path: ['payment'], message: 'Owner checkout and invoice payment require a hosted payment.' });
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
/** Public owner read. No unpaid state can contain a provider redirect. */
|
|
353
|
+
export const purchaseIntent = z.discriminatedUnion('state', [
|
|
354
|
+
z.object({ ...intentIdentity, state: z.literal('awaiting_vies'), reason: viesPendingReason, next_attempt_at: z.iso.datetime() }).strict(),
|
|
355
|
+
z.object({ ...intentIdentity, ...quoteIdentity, state: z.literal('eligible'), quote: purchaseQuote }).strict(),
|
|
356
|
+
z.object({
|
|
357
|
+
...intentIdentity, operation: purchaseOperation, state: z.literal('held'), reason: purchaseHoldReason,
|
|
358
|
+
original_amount: z.object({ currency: planCurrency, gross_cents: purchaseCents }).strict().optional()
|
|
359
|
+
.meta({ description: 'Recorded balance of a held invoice; not a new quote or authorization.' }),
|
|
360
|
+
}).strict(),
|
|
361
|
+
z.object({ ...intentIdentity, state: z.literal('invalid_vat_id'), field: z.literal('billing.vat_id'), rule: z.literal('vat_id_invalid') }).strict(),
|
|
362
|
+
z.object({ ...intentIdentity, state: z.literal('refused'), field: z.string().min(1), rule: purchaseRefusalRule }).strict(),
|
|
363
|
+
z.object({
|
|
364
|
+
...intentIdentity, state: z.literal('payment_started'), payment_id: z.uuid(),
|
|
365
|
+
payment: z.discriminatedUnion('kind', [
|
|
366
|
+
z.object({ kind: z.literal('hosted'), checkout_id: z.uuid(), checkout_url: z.url() }).strict(),
|
|
367
|
+
z.object({ kind: z.literal('mandate') }).strict(),
|
|
368
|
+
]),
|
|
369
|
+
}).strict(),
|
|
370
|
+
]).superRefine(validateIntent).meta({ allOf: intentRules });
|
|
371
|
+
/** Shared by checkout, invoice payment and method change. Mandate-only setup remains held. */
|
|
372
|
+
export const checkoutResponse = purchaseIntent;
|
|
373
|
+
/** Lookup needs one identity, plus the expected operation; a mismatch discloses nothing. */
|
|
374
|
+
export const purchaseIntentLookupQuery = z.object({
|
|
375
|
+
operation_key: purchaseOperationKey.optional().meta({ description: 'The client operation key; supply this or intent_id, never both.' }),
|
|
376
|
+
intent_id: z.uuid().optional().meta({ description: 'The persisted intent ID; supply this or operation_key, never both.' }),
|
|
377
|
+
operation: purchaseOperation.meta({ description: 'Expected operation; a mismatch returns 404 without disclosure.' }),
|
|
378
|
+
}).strict().refine((q) => (q.operation_key !== undefined) !== (q.intent_id !== undefined), {
|
|
379
|
+
message: 'Supply exactly one of operation_key or intent_id.',
|
|
380
|
+
}).meta({
|
|
381
|
+
description: 'Owner lookup by exactly one identity and the expected operation.',
|
|
382
|
+
oneOf: [
|
|
383
|
+
{ required: ['operation_key'], not: { required: ['intent_id'] } },
|
|
384
|
+
{ required: ['intent_id'], not: { required: ['operation_key'] } },
|
|
385
|
+
],
|
|
303
386
|
});
|
|
387
|
+
export const purchaseIntentConfirmRequest = z.object({
|
|
388
|
+
operation_key: purchaseOperationKey, operation: chargeOperation, ...quoteIdentity,
|
|
389
|
+
}).strict();
|
|
390
|
+
/** `409 target_state_conflict` details. Stale confirmation returns the new owner-visible intent. */
|
|
391
|
+
export const purchaseConflictDetails = z.discriminatedUnion('rule', [
|
|
392
|
+
z.object({ field: z.literal('operation_key'), rule: z.literal('operation_key_reused') }).strict(),
|
|
393
|
+
z.object({ field: z.literal('intent'), rule: z.enum(['stale_quote', 'buyer_changed', 'not_eligible', 'invoice_not_open']), current_intent: purchaseIntent }).strict(),
|
|
394
|
+
]);
|
|
395
|
+
export const invoicePayRequest = z.object({ operation_key: purchaseOperationKey }).strict();
|
|
304
396
|
/** `GET /api/billing/checkout/:id`'s answer: the return page's poll. */
|
|
305
397
|
export const checkoutStatus = z.object({
|
|
306
398
|
checkout_id: z.uuid().meta({ description: 'The checkout this status is for.' }),
|
|
@@ -313,18 +405,19 @@ export const checkoutStatus = z.object({
|
|
|
313
405
|
plan: planId.meta({ description: "The org's plan after applying — unchanged unless `purpose` is `upgrade` and `status` is `paid`." }),
|
|
314
406
|
});
|
|
315
407
|
/** VIES's answer to a VAT-ID check: `unverified` when VIES could not be reached in time. */
|
|
316
|
-
export const vatIdStatus = z.enum(['valid', 'unverified', 'invalid']);
|
|
408
|
+
export const vatIdStatus = z.enum(['valid', 'unverified', 'invalid', 'unavailable']);
|
|
317
409
|
/** `POST /api/billing/vat-id/check`'s body: the VAT-ID-on-blur check the checkout and `PATCH /api/billing/details` both use. */
|
|
318
410
|
export const vatIdCheckRequest = z.object({
|
|
319
411
|
country: countryCode.meta({ description: "The VAT ID's country." }),
|
|
320
412
|
vat_id: z.string().trim().min(1).max(20).meta({ description: 'The VAT ID as typed; normalized before the VIES lookup (`normalizeVatId`).' }),
|
|
321
413
|
}).strict();
|
|
322
|
-
/**
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
})
|
|
414
|
+
/** Public display only: successful full evidence is never returned here. */
|
|
415
|
+
const vatCheckIdentity = { vat_id: z.string(), name: z.string().nullable() };
|
|
416
|
+
export const vatIdCheckResponse = z.discriminatedUnion('state', [
|
|
417
|
+
z.object({ ...vatCheckIdentity, state: z.literal('eligible'), status: z.literal('valid') }).strict(),
|
|
418
|
+
z.object({ ...vatCheckIdentity, state: z.literal('refused'), status: z.literal('invalid'), rule: z.literal('vat_id_invalid') }).strict(),
|
|
419
|
+
z.object({ ...vatCheckIdentity, state: z.literal('pending'), status: z.enum(['valid', 'unverified', 'unavailable']), reason: viesPendingReason }).strict(),
|
|
420
|
+
]);
|
|
328
421
|
/**
|
|
329
422
|
* `POST /api/billing/change`'s body: the **absolute** target state, never a
|
|
330
423
|
* delta — the route compares it with the org's current state
|
|
@@ -335,6 +428,7 @@ export const vatIdCheckResponse = z.object({
|
|
|
335
428
|
* `.refine()` has no JSON Schema rendering.
|
|
336
429
|
*/
|
|
337
430
|
export const billingChangeRequest = z.object({
|
|
431
|
+
operation_key: purchaseOperationKey,
|
|
338
432
|
plan: z.enum(['plus', 'pro']).optional().meta({ description: 'The target plan. Omitted leaves the plan as it is.' }),
|
|
339
433
|
cycle: billingCycle.optional().meta({ description: 'The target cycle. Omitted leaves the cycle as it is.' }),
|
|
340
434
|
addons: orgAddons.partial().strict().optional().meta({
|
|
@@ -345,8 +439,11 @@ export const billingChangeRequest = z.object({
|
|
|
345
439
|
export const billingCancelRequest = z.object({
|
|
346
440
|
reason: z.string().trim().max(500).optional().meta({ description: 'An optional free-text reason. Shown to nobody but Fleetless.' }),
|
|
347
441
|
}).strict();
|
|
348
|
-
/**
|
|
442
|
+
/** Owner corrections; Cloud revalidates the complete merged buyer before any later charge. */
|
|
349
443
|
export const billingDetailsUpdate = z.object({
|
|
444
|
+
company_name: z.string().trim().min(1).max(200).optional(),
|
|
445
|
+
address: billingAddress.optional(),
|
|
446
|
+
tax_id: z.string().trim().max(100).nullable().optional(),
|
|
350
447
|
invoice_email: z.email().optional().meta({ description: 'Replaces the invoice email. Omitted leaves it as it is.' }),
|
|
351
448
|
vat_id: z.string().trim().max(20).nullable().optional().meta({
|
|
352
449
|
description: 'Replaces the VAT ID; `null` clears it. Omitted leaves it as it is. A new ID is re-checked through VIES.',
|
|
@@ -359,6 +456,7 @@ export const billingDetailsUpdate = z.object({
|
|
|
359
456
|
export const paymentMethodKind = z.enum(['card', 'paypal', 'applepay']);
|
|
360
457
|
/** `POST /api/billing/payment-method`'s body. */
|
|
361
458
|
export const paymentMethodChangeRequest = z.object({
|
|
459
|
+
operation_key: purchaseOperationKey,
|
|
362
460
|
method: paymentMethodKind.meta({
|
|
363
461
|
description: "The new mandate's method. Offer what `billingView.payment_method_options` lists: `applepay` may be refused with " +
|
|
364
462
|
"`400 validation_error` `{ field: 'method', rule: 'applepay_needs_open_invoice' }` unless an invoice is open.",
|
|
@@ -414,7 +512,7 @@ export const billingAccount = z.object({
|
|
|
414
512
|
vat: z.object({
|
|
415
513
|
treatment: vatTreatment.meta({ description: 'How the account is taxed.' }),
|
|
416
514
|
rate_percent: z.number().int().meta({ description: 'The VAT rate, in whole percent.' }),
|
|
417
|
-
}).meta({ description: '
|
|
515
|
+
}).nullable().meta({ description: 'Recorded VAT treatment; null while the current buyer has no eligible decision. Never infer zero rating from a pending account.' }),
|
|
418
516
|
currency: planCurrency.meta({ description: "The org's billing currency, fixed at the first payment." }),
|
|
419
517
|
cycle: billingCycle.meta({ description: 'The current billing cycle.' }),
|
|
420
518
|
status: billingAccountStatus.meta({ description: "The account's own status." }),
|
|
@@ -465,7 +563,17 @@ export const billingView = z.object({
|
|
|
465
563
|
invoices: z.array(billingInvoice).meta({ description: 'Newest first, at most 24.' }),
|
|
466
564
|
});
|
|
467
565
|
/** `POST /api/billing/change`'s answer: the billing view afterwards, and what was charged right now, if anything. */
|
|
468
|
-
|
|
566
|
+
const acceptedBillingChange = z.object({
|
|
469
567
|
billing: billingView.meta({ description: 'The billing view after the change.' }),
|
|
470
568
|
charged: billingInvoice.nullable().meta({ description: 'The invoice charged now, or `null` when the change was only scheduled for the period\'s end.' }),
|
|
471
|
-
});
|
|
569
|
+
}).strict();
|
|
570
|
+
export const billingChangeResponse = z.union([
|
|
571
|
+
acceptedBillingChange,
|
|
572
|
+
z.object({ intent: purchaseIntent }).strict(),
|
|
573
|
+
z.object({ ...acceptedBillingChange.shape, intent: purchaseIntent.options[5].superRefine(validateIntent).meta({ allOf: intentRules }) }).strict(),
|
|
574
|
+
]);
|
|
575
|
+
/** Confirmation/lookup recovers the same payment, and the resulting view for a paid change. */
|
|
576
|
+
export const purchaseIntentResponse = z.union([
|
|
577
|
+
purchaseIntent,
|
|
578
|
+
z.object({ ...acceptedBillingChange.shape, intent: purchaseIntent.options[5].superRefine(validateIntent).meta({ allOf: intentRules }) }).strict(),
|
|
579
|
+
]);
|
package/dist/index.d.ts
CHANGED
|
@@ -59,3 +59,5 @@ export { planCurrency, orgAddons, orgPlanUsage, planChangeKeep, planChangeReason
|
|
|
59
59
|
export type { PlanCurrency, OrgAddons, OrgPlanUsage, PlanChangeKeep, PlanChangeReason, PendingPlanChange, OrgLock, OrgPlan, PlanChangeRequest, PlanOverrides, AdminPlanChangeRequest, } from './plans.js';
|
|
60
60
|
export { countryCode, EU_COUNTRIES, SELLER_COUNTRY, DE_VAT_RATE_PERCENT, isEuCountry, currencyForCountry, payerKind, billingCycle, vatTreatment, payerRefusalRule, vatFor, viesCountry, normalizeVatId, periodNetCents, prorateCents, vatCents, chargeAmounts, DAY_MS, periodDays, remainingDays, changeNetCents, checkoutQuote, BILLING_RETRY_DAYS, BILLING_LOCK_DAY, billingAddress, billingDetails, checkoutRequest, checkoutResponse, checkoutStatus, vatIdStatus, vatIdCheckRequest, vatIdCheckResponse, billingChangeRequest, billingCancelRequest, billingDetailsUpdate, paymentMethodKind, paymentMethodChangeRequest, billingAccountStatus, paymentMethod, invoiceStatus, billingInvoice, billingAccount, billingView, billingChangeResponse, } from './billing.js';
|
|
61
61
|
export type { PayerKind, BillingCycle, VatTreatment, PayerRefusalRule, VatDecision, ChargeAmounts, BillingState, QuoteLine, CheckoutQuote, BillingAddress, BillingDetails, CheckoutRequest, CheckoutResponse, CheckoutStatus, VatIdStatus, VatIdCheckRequest, VatIdCheckResponse, BillingChangeRequest, BillingCancelRequest, BillingDetailsUpdate, PaymentMethodKind, PaymentMethodChangeRequest, BillingAccountStatus, PaymentMethod, InvoiceStatus, BillingInvoice, BillingAccount, BillingView, BillingChangeResponse, } from './billing.js';
|
|
62
|
+
export { purchaseBillingDetails, purchaseOperationKey, purchaseOperation, purchaseQuote, purchaseHoldReason, purchaseRefusalRule, purchaseIntent, purchaseIntentLookupQuery, purchaseIntentConfirmRequest, purchaseConflictDetails, invoicePayRequest, purchaseIntentResponse, vatDecision, viesPendingReason, } from './billing.js';
|
|
63
|
+
export type { PurchaseBillingDetails, PurchaseOperation, PurchaseQuote, PurchaseIntent, PurchaseIntentLookupQuery, PurchaseIntentConfirmRequest, PurchaseConflictDetails, InvoicePayRequest, PurchaseIntentResponse, ViesVerdict, ViesPendingReason, } from './billing.js';
|
package/dist/index.js
CHANGED
|
@@ -71,3 +71,4 @@ export { planId, PLAN_ORDER, planLimitKey, planLimits, planFeature, planFeatures
|
|
|
71
71
|
export { planCurrency, orgAddons, orgPlanUsage, planChangeKeep, planChangeReason, pendingPlanChange, orgLock, orgPlan, planChangeRequest, planOverrides, adminPlanChangeRequest, } from './plans.js';
|
|
72
72
|
// 2026-10-04 — billing through Mollie (#104).
|
|
73
73
|
export { countryCode, EU_COUNTRIES, SELLER_COUNTRY, DE_VAT_RATE_PERCENT, isEuCountry, currencyForCountry, payerKind, billingCycle, vatTreatment, payerRefusalRule, vatFor, viesCountry, normalizeVatId, periodNetCents, prorateCents, vatCents, chargeAmounts, DAY_MS, periodDays, remainingDays, changeNetCents, checkoutQuote, BILLING_RETRY_DAYS, BILLING_LOCK_DAY, billingAddress, billingDetails, checkoutRequest, checkoutResponse, checkoutStatus, vatIdStatus, vatIdCheckRequest, vatIdCheckResponse, billingChangeRequest, billingCancelRequest, billingDetailsUpdate, paymentMethodKind, paymentMethodChangeRequest, billingAccountStatus, paymentMethod, invoiceStatus, billingInvoice, billingAccount, billingView, billingChangeResponse, } from './billing.js';
|
|
74
|
+
export { purchaseBillingDetails, purchaseOperationKey, purchaseOperation, purchaseQuote, purchaseHoldReason, purchaseRefusalRule, purchaseIntent, purchaseIntentLookupQuery, purchaseIntentConfirmRequest, purchaseConflictDetails, invoicePayRequest, purchaseIntentResponse, vatDecision, viesPendingReason, } from './billing.js';
|
package/dist/plans.d.ts
CHANGED
|
@@ -79,9 +79,7 @@ export declare const planFeatures: z.ZodObject<{
|
|
|
79
79
|
export type PlanFeatures = z.infer<typeof planFeatures>;
|
|
80
80
|
export declare const planPrices: z.ZodObject<{
|
|
81
81
|
eur_month: z.ZodNumber;
|
|
82
|
-
usd_month: z.ZodNumber;
|
|
83
82
|
eur_year: z.ZodNumber;
|
|
84
|
-
usd_year: z.ZodNumber;
|
|
85
83
|
}, z.core.$strip>;
|
|
86
84
|
export type PlanPrices = z.infer<typeof planPrices>;
|
|
87
85
|
export declare const planSupport: z.ZodEnum<{
|
|
@@ -120,9 +118,7 @@ export declare const planCatalogueEntry: z.ZodObject<{
|
|
|
120
118
|
}, z.core.$strip>;
|
|
121
119
|
prices: z.ZodNullable<z.ZodObject<{
|
|
122
120
|
eur_month: z.ZodNumber;
|
|
123
|
-
usd_month: z.ZodNumber;
|
|
124
121
|
eur_year: z.ZodNumber;
|
|
125
|
-
usd_year: z.ZodNumber;
|
|
126
122
|
}, z.core.$strip>>;
|
|
127
123
|
support: z.ZodEnum<{
|
|
128
124
|
email: "email";
|
|
@@ -166,13 +162,12 @@ export declare const addonCatalogueEntry: z.ZodObject<{
|
|
|
166
162
|
per_unit: z.ZodNumber;
|
|
167
163
|
prices: z.ZodObject<{
|
|
168
164
|
eur_month: z.ZodNumber;
|
|
169
|
-
usd_month: z.ZodNumber;
|
|
170
165
|
eur_year: z.ZodNumber;
|
|
171
|
-
usd_year: z.ZodNumber;
|
|
172
166
|
}, z.core.$strip>;
|
|
173
167
|
}, z.core.$strip>;
|
|
174
168
|
export type AddonCatalogueEntry = z.infer<typeof addonCatalogueEntry>;
|
|
175
169
|
/**
|
|
170
|
+
* Historical conversion helper only; the current catalogue and all new quotes are EUR.
|
|
176
171
|
* **No floating-point money, anywhere.** `eurCents * 1.15` would introduce
|
|
177
172
|
* the fraction of a cent that floating point cannot hold exactly, so the
|
|
178
173
|
* conversion is integer arithmetic throughout: scale by 115, add 9_999 to
|
|
@@ -186,8 +181,8 @@ export declare function usdCentsFromEurCents(eurCents: number): number;
|
|
|
186
181
|
export declare function yearlyEurCents(monthEurCents: number): number;
|
|
187
182
|
/**
|
|
188
183
|
* The catalogue writes every price through this one function, from the
|
|
189
|
-
* monthly EUR cents alone — never as
|
|
190
|
-
* so the
|
|
184
|
+
* monthly EUR cents alone — never as yearly numbers typed separately —
|
|
185
|
+
* so the yearly rule is applied once, here. New catalogue prices are EUR-only.
|
|
191
186
|
*/
|
|
192
187
|
export declare function pricesFromEurMonth(eurMonthCents: number): PlanPrices;
|
|
193
188
|
/**
|
|
@@ -210,7 +205,7 @@ export declare function requiredPlanFor(feature: PlanFeature): PlanId;
|
|
|
210
205
|
* `null` when no plan above it raises the limit any further.
|
|
211
206
|
*/
|
|
212
207
|
export declare function nextPlanRaising(plan: PlanId, key: PlanLimitKey): PlanId | null;
|
|
213
|
-
/**
|
|
208
|
+
/** Recorded currency. USD remains readable for historical accounts, invoices and payments. */
|
|
214
209
|
export declare const planCurrency: z.ZodEnum<{
|
|
215
210
|
eur: "eur";
|
|
216
211
|
usd: "usd";
|
package/dist/plans.js
CHANGED
|
@@ -70,9 +70,7 @@ export const planFeatures = z.object(Object.fromEntries(planFeature.options.map(
|
|
|
70
70
|
const cents = z.number().int().nonnegative();
|
|
71
71
|
export const planPrices = z.object({
|
|
72
72
|
eur_month: cents.meta({ description: 'Per month in euro cents, excluding VAT.' }),
|
|
73
|
-
usd_month: cents.meta({ description: 'Per month in US dollar cents, excluding VAT: the euro price × 1.15, rounded up to a whole dollar.' }),
|
|
74
73
|
eur_year: cents.meta({ description: 'Per year in euro cents, excluding VAT: twelve months less 15 %.' }),
|
|
75
|
-
usd_year: cents.meta({ description: 'Per year in US dollar cents, excluding VAT: the yearly euro price × 1.15, rounded up to a whole dollar.' }),
|
|
76
74
|
});
|
|
77
75
|
export const planSupport = z.enum(['community', 'email', 'priority', 'named_contact']);
|
|
78
76
|
export const planCatalogueEntry = z.object({
|
|
@@ -96,6 +94,7 @@ export const addonCatalogueEntry = z.object({
|
|
|
96
94
|
prices: planPrices.meta({ description: 'The price of one unit.' }),
|
|
97
95
|
});
|
|
98
96
|
/**
|
|
97
|
+
* Historical conversion helper only; the current catalogue and all new quotes are EUR.
|
|
99
98
|
* **No floating-point money, anywhere.** `eurCents * 1.15` would introduce
|
|
100
99
|
* the fraction of a cent that floating point cannot hold exactly, so the
|
|
101
100
|
* conversion is integer arithmetic throughout: scale by 115, add 9_999 to
|
|
@@ -113,16 +112,14 @@ export function yearlyEurCents(monthEurCents) {
|
|
|
113
112
|
}
|
|
114
113
|
/**
|
|
115
114
|
* The catalogue writes every price through this one function, from the
|
|
116
|
-
* monthly EUR cents alone — never as
|
|
117
|
-
* so the
|
|
115
|
+
* monthly EUR cents alone — never as yearly numbers typed separately —
|
|
116
|
+
* so the yearly rule is applied once, here. New catalogue prices are EUR-only.
|
|
118
117
|
*/
|
|
119
118
|
export function pricesFromEurMonth(eurMonthCents) {
|
|
120
119
|
const eurYear = yearlyEurCents(eurMonthCents);
|
|
121
120
|
return {
|
|
122
121
|
eur_month: eurMonthCents,
|
|
123
|
-
usd_month: usdCentsFromEurCents(eurMonthCents),
|
|
124
122
|
eur_year: eurYear,
|
|
125
|
-
usd_year: usdCentsFromEurCents(eurYear),
|
|
126
123
|
};
|
|
127
124
|
}
|
|
128
125
|
/**
|
|
@@ -282,7 +279,7 @@ export function nextPlanRaising(plan, key) {
|
|
|
282
279
|
* and the change it has queued but not yet crossed into.
|
|
283
280
|
* ---------------------------------------------------------------------------
|
|
284
281
|
*/
|
|
285
|
-
/**
|
|
282
|
+
/** Recorded currency. USD remains readable for historical accounts, invoices and payments. */
|
|
286
283
|
export const planCurrency = z.enum(['eur', 'usd']);
|
|
287
284
|
/**
|
|
288
285
|
* How many units of each add-on an org has bought. Only a plan with the
|