@pairz/billing 0.0.1 → 1.0.0-rc.81
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/LICENSE +21 -0
- package/README.md +46 -1
- package/contract.d.ts +7 -0
- package/contract.js +7 -0
- package/credits/actions/check.d.ts +13 -0
- package/credits/actions/check.js +127 -0
- package/credits/actions/manage.d.ts +9 -0
- package/credits/actions/manage.js +266 -0
- package/credits/actions/state.d.ts +2 -0
- package/credits/actions/state.js +172 -0
- package/credits/collections/credit.d.ts +103 -0
- package/credits/collections/credit.js +31 -0
- package/credits/collections/payment.d.ts +132 -0
- package/credits/collections/payment.js +32 -0
- package/credits/collections/plan.d.ts +421 -0
- package/credits/collections/plan.js +97 -0
- package/credits/collections/room.d.ts +78 -0
- package/credits/collections/room.js +24 -0
- package/credits/contract.d.ts +19 -0
- package/credits/contract.js +12 -0
- package/credits/mod.d.ts +40 -0
- package/credits/mod.js +76 -0
- package/credits/shared/apply.d.ts +66 -0
- package/credits/shared/apply.js +106 -0
- package/credits/shared/settings.d.ts +70 -0
- package/credits/shared/settings.js +28 -0
- package/credits/shared/standing.d.ts +71 -0
- package/credits/shared/standing.js +235 -0
- package/credits/shared/walk.d.ts +50 -0
- package/credits/shared/walk.js +127 -0
- package/credits/views/web/add.d.ts +25 -0
- package/credits/views/web/add.js +92 -0
- package/credits/views/web/budget.d.ts +16 -0
- package/credits/views/web/budget.js +62 -0
- package/credits/views/web/composer.d.ts +13 -0
- package/credits/views/web/composer.js +65 -0
- package/credits/views/web/history.d.ts +12 -0
- package/credits/views/web/history.js +55 -0
- package/credits/views/web/numbers.d.ts +256 -0
- package/credits/views/web/numbers.js +291 -0
- package/credits/views/web/org.d.ts +31 -0
- package/credits/views/web/org.js +238 -0
- package/credits/views/web/plan.d.ts +32 -0
- package/credits/views/web/plan.js +87 -0
- package/credits/views/web/setup.d.ts +11 -0
- package/credits/views/web/setup.js +39 -0
- package/credits/views/web/staff.d.ts +20 -0
- package/credits/views/web/staff.js +265 -0
- package/credits/views/web/style.d.ts +9 -0
- package/credits/views/web/style.js +190 -0
- package/credits/views/web/types.d.ts +17 -0
- package/credits/views/web/types.js +32 -0
- package/credits/web.d.ts +13 -0
- package/credits/web.js +47 -0
- package/mod.d.ts +26 -0
- package/mod.js +25 -0
- package/package.json +59 -3
- package/stripe/actions/checkout.d.ts +4 -0
- package/stripe/actions/checkout.js +191 -0
- package/stripe/actions/fact.d.ts +1 -0
- package/stripe/actions/fact.js +39 -0
- package/stripe/mod.d.ts +30 -0
- package/stripe/mod.js +52 -0
- package/stripe/routes/webhook.d.ts +16 -0
- package/stripe/routes/webhook.js +56 -0
- package/stripe/shared/api.d.ts +14 -0
- package/stripe/shared/api.js +42 -0
- package/stripe/shared/events.d.ts +42 -0
- package/stripe/shared/events.js +226 -0
- package/stripe/shared/settings.d.ts +39 -0
- package/stripe/shared/settings.js +10 -0
- package/web.d.ts +13 -0
- package/web.js +13 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What people see of where the org stands.
|
|
3
|
+
*
|
|
4
|
+
* - `billing.state` `{}`: for the Billing section. Its people see whether work
|
|
5
|
+
* can go on and why not; its owners and admins, the plan, balance, month,
|
|
6
|
+
* credits and payments, and the plans it can move to (`pay.plans`: those for
|
|
7
|
+
* its kind of org that its way of paying sells it now, its own kind's first;
|
|
8
|
+
* `pay.elsewhere`, those only another kind of org can have); platform staff,
|
|
9
|
+
* also the plans there are to set.
|
|
10
|
+
* With limits off (`enforce`), only staff see anything, and nothing starts.
|
|
11
|
+
* - `billing.notice` `{}`: what to say above the composer, if anything: that
|
|
12
|
+
* the org can't spend (to everyone), or is running low (to those who can act
|
|
13
|
+
* on it).
|
|
14
|
+
*
|
|
15
|
+
* Both only read and settle what's due, so neither is recorded.
|
|
16
|
+
*/
|
|
17
|
+
import { defineAction, people } from "pairz";
|
|
18
|
+
import { runsOrg } from "pairz/plugins/access/contract";
|
|
19
|
+
import { billableSeats } from "../contract.js";
|
|
20
|
+
import { orgKind, settingsOf, unfit, } from "../shared/settings.js";
|
|
21
|
+
import { NO_LIMIT, refresh, rooms, seatsOf, standingOf, verdictOf } from "../shared/standing.js";
|
|
22
|
+
/** A waiver as who runs the org sees it: what, and until when; why and who are staff's. */
|
|
23
|
+
const withoutWhy = (waived) => Object.fromEntries(Object.entries(waived).map(([what, w]) => {
|
|
24
|
+
const { reason: _reason, by: _by, ...shown } = w;
|
|
25
|
+
return [what, shown];
|
|
26
|
+
}));
|
|
27
|
+
/** A plan as it's offered: what it is, costs and gives, and who it's for. */
|
|
28
|
+
const offer = ([name, terms]) => ({
|
|
29
|
+
name,
|
|
30
|
+
title: terms.title,
|
|
31
|
+
seat: terms.seat,
|
|
32
|
+
credits: terms.credits,
|
|
33
|
+
...(terms.for ? { for: terms.for } : {}),
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* The plans an org can move to by itself: those a seat's price is known for,
|
|
37
|
+
* that its way of paying can sell it now, for its kind of org (its own kind's
|
|
38
|
+
* first); and apart, those only another kind of org can have.
|
|
39
|
+
*/
|
|
40
|
+
async function offersOf(ctx, set) {
|
|
41
|
+
const kind = orgKind(ctx);
|
|
42
|
+
const sold = set.pay?.sellable
|
|
43
|
+
? new Set(await ctx.call(set.pay.sellable, {}))
|
|
44
|
+
: undefined;
|
|
45
|
+
const priced = Object.entries(set.plans)
|
|
46
|
+
.filter(([name, terms]) => terms.seat && (!sold || sold.has(name)));
|
|
47
|
+
const fits = priced.filter(([, terms]) => !unfit(terms, kind))
|
|
48
|
+
.sort(([, a], [, b]) => Number(b.for === kind) - Number(a.for === kind));
|
|
49
|
+
const elsewhere = priced.filter(([, terms]) => unfit(terms, kind));
|
|
50
|
+
return {
|
|
51
|
+
plans: fits.map(offer),
|
|
52
|
+
...(elsewhere.length ? { elsewhere: elsewhere.map(offer) } : {}),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
async function sight(ctx) {
|
|
56
|
+
const me = await ctx.call("org.me", {})
|
|
57
|
+
.catch(() => undefined);
|
|
58
|
+
const staff = me?.staff === true || ctx.actor?.staff === true;
|
|
59
|
+
return { staff, runs: staff || runsOrg(me?.role) };
|
|
60
|
+
}
|
|
61
|
+
export const stateAction = defineAction({
|
|
62
|
+
description: "Where the org stands: whether it can spend; its plan and credits for who runs it",
|
|
63
|
+
record: false,
|
|
64
|
+
input: { type: "object", additionalProperties: false },
|
|
65
|
+
allow: people,
|
|
66
|
+
run: async (ctx) => {
|
|
67
|
+
const { staff, runs } = await sight(ctx);
|
|
68
|
+
const set = settingsOf(ctx);
|
|
69
|
+
const now = new Date().toISOString();
|
|
70
|
+
if (!set.enforce && !staff)
|
|
71
|
+
return { on: false, runs, staff };
|
|
72
|
+
const room = set.enforce ? await refresh(ctx, now) : undefined;
|
|
73
|
+
const verdict = room ? verdictOf(room) : { ok: true };
|
|
74
|
+
if (!runs)
|
|
75
|
+
return { on: true, runs, staff, ...verdict };
|
|
76
|
+
const s = await standingOf(ctx, now);
|
|
77
|
+
const seats = s.plan ? await seatsOf(ctx, s.plan) : undefined;
|
|
78
|
+
const payments = await ctx.as().db.collection("payment").find({}, {
|
|
79
|
+
sort: { at: -1 },
|
|
80
|
+
limit: 50,
|
|
81
|
+
});
|
|
82
|
+
const lowOn = !room
|
|
83
|
+
? undefined
|
|
84
|
+
: room.lowCredits !== undefined && room.credits < room.lowCredits
|
|
85
|
+
? "credits"
|
|
86
|
+
: room.lowBudget !== undefined && room.budget < room.lowBudget
|
|
87
|
+
? "budget"
|
|
88
|
+
: undefined;
|
|
89
|
+
return {
|
|
90
|
+
on: set.enforce,
|
|
91
|
+
runs,
|
|
92
|
+
staff,
|
|
93
|
+
...verdict,
|
|
94
|
+
low: !!lowOn,
|
|
95
|
+
...(lowOn ? { lowOn } : {}),
|
|
96
|
+
plan: s.plan && {
|
|
97
|
+
name: s.plan.name,
|
|
98
|
+
terms: s.plan.terms,
|
|
99
|
+
since: s.plan.since,
|
|
100
|
+
channel: s.plan.channel,
|
|
101
|
+
...(s.plan.status ? { status: s.plan.status } : {}),
|
|
102
|
+
...(s.plan.customer ? { customer: s.plan.customer } : {}),
|
|
103
|
+
...(s.plan.subscription ? { subscription: s.plan.subscription } : {}),
|
|
104
|
+
...(typeof s.plan.seats === "number" ? { fixedSeats: s.plan.seats } : {}),
|
|
105
|
+
...(s.plan.waived ? { waived: staff ? s.plan.waived : withoutWhy(s.plan.waived) } : {}),
|
|
106
|
+
},
|
|
107
|
+
...(seats !== undefined ? { seats, billedSeats: billableSeats(s.plan, seats, now) } : {}),
|
|
108
|
+
...(s.period ? { period: s.period } : {}),
|
|
109
|
+
balance: s.walked.balance,
|
|
110
|
+
buckets: s.walked.buckets,
|
|
111
|
+
debt: s.walked.debt,
|
|
112
|
+
waived: s.waivedUsage,
|
|
113
|
+
month: s.month,
|
|
114
|
+
// Why it was given, and by whom, for staff; those who run the org, what it is.
|
|
115
|
+
history: s.history.slice(0, 100).map(({ by: who, reason, ...credit }) => staff
|
|
116
|
+
? {
|
|
117
|
+
...credit,
|
|
118
|
+
...(credit.note ?? reason ? { note: credit.note ?? reason } : {}),
|
|
119
|
+
...(who ? { by: who } : {}),
|
|
120
|
+
}
|
|
121
|
+
: credit),
|
|
122
|
+
// What it was and came to, for who runs the org; what a channel kept, and who, for staff.
|
|
123
|
+
payments: staff ? payments : payments.map((p) => ({
|
|
124
|
+
_id: p._id,
|
|
125
|
+
channel: p.channel,
|
|
126
|
+
ref: p.ref,
|
|
127
|
+
amount: p.amount,
|
|
128
|
+
currency: p.currency,
|
|
129
|
+
purpose: p.purpose,
|
|
130
|
+
...(p.credits !== undefined ? { credits: p.credits } : {}),
|
|
131
|
+
...(p.note ? { note: p.note } : {}),
|
|
132
|
+
at: p.at,
|
|
133
|
+
})),
|
|
134
|
+
pay: set.pay
|
|
135
|
+
? {
|
|
136
|
+
topUps: set.topUps,
|
|
137
|
+
min: set.topUpMin,
|
|
138
|
+
max: set.topUpMax,
|
|
139
|
+
...await offersOf(ctx, set),
|
|
140
|
+
manage: !!s.plan?.customer,
|
|
141
|
+
}
|
|
142
|
+
: null,
|
|
143
|
+
...(staff ? { plans: set.plans } : {}),
|
|
144
|
+
};
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
export const noticeAction = defineAction({
|
|
148
|
+
description: "What to say above the composer about what the org can spend, if anything",
|
|
149
|
+
record: false,
|
|
150
|
+
input: { type: "object", additionalProperties: false },
|
|
151
|
+
allow: people,
|
|
152
|
+
run: async (ctx) => {
|
|
153
|
+
if (!settingsOf(ctx).enforce)
|
|
154
|
+
return null;
|
|
155
|
+
const now = new Date().toISOString();
|
|
156
|
+
const kept = await rooms(ctx).findOne({ _id: "room" });
|
|
157
|
+
const room = kept && now < kept.until ? kept : await refresh(ctx, now);
|
|
158
|
+
const { runs } = await sight(ctx);
|
|
159
|
+
const verdict = verdictOf(room);
|
|
160
|
+
if (!verdict.ok)
|
|
161
|
+
return { tone: "stop", why: verdict.why, text: verdict.message, runs };
|
|
162
|
+
if (!runs)
|
|
163
|
+
return null;
|
|
164
|
+
if (room.lowCredits !== undefined && room.credits < room.lowCredits) {
|
|
165
|
+
return { tone: "low", why: "credits", left: Math.max(room.credits, 0), runs };
|
|
166
|
+
}
|
|
167
|
+
if (room.lowBudget !== undefined && room.budget < room.lowBudget && room.budget < NO_LIMIT) {
|
|
168
|
+
return { tone: "low", why: "budget", left: Math.max(room.budget, 0), runs };
|
|
169
|
+
}
|
|
170
|
+
return null;
|
|
171
|
+
},
|
|
172
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credits an org was given or bought, in USD, appended and never changed: the
|
|
3
|
+
* same `_id` again is the one already kept, so a grant that comes from
|
|
4
|
+
* something (a period, a code, a payment) can't land twice. A negative amount
|
|
5
|
+
* takes credits away.
|
|
6
|
+
*/
|
|
7
|
+
import { type Infer } from "pairz";
|
|
8
|
+
export declare const creditSchema: {
|
|
9
|
+
readonly type: "object";
|
|
10
|
+
readonly properties: {
|
|
11
|
+
readonly kind: {
|
|
12
|
+
readonly type: "string";
|
|
13
|
+
readonly enum: readonly ["trial", "plan", "gift", "referral", "purchase", "waived", "adjustment"];
|
|
14
|
+
};
|
|
15
|
+
readonly amount: {
|
|
16
|
+
readonly type: "number";
|
|
17
|
+
};
|
|
18
|
+
readonly at: {
|
|
19
|
+
readonly type: "string";
|
|
20
|
+
};
|
|
21
|
+
/** The first day (UTC, `YYYY-MM-DD`) it no longer counts; none: it doesn't expire. */
|
|
22
|
+
readonly expires: {
|
|
23
|
+
readonly type: "string";
|
|
24
|
+
};
|
|
25
|
+
/** What to show for it. */
|
|
26
|
+
readonly note: {
|
|
27
|
+
readonly type: "string";
|
|
28
|
+
};
|
|
29
|
+
/** Why it was given, and who gave it: for staff. */
|
|
30
|
+
readonly reason: {
|
|
31
|
+
readonly type: "string";
|
|
32
|
+
};
|
|
33
|
+
readonly by: {
|
|
34
|
+
readonly type: "string";
|
|
35
|
+
};
|
|
36
|
+
/** Taken away, what it comes out of first: a refund, of what the money bought. */
|
|
37
|
+
readonly takes: {
|
|
38
|
+
readonly type: "string";
|
|
39
|
+
};
|
|
40
|
+
/** From a test mode: it stops counting when the app goes live. */
|
|
41
|
+
readonly sandbox: {
|
|
42
|
+
readonly type: "boolean";
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
readonly required: readonly ["kind", "amount", "at"];
|
|
46
|
+
};
|
|
47
|
+
export type Credit = Infer<typeof creditSchema> & {
|
|
48
|
+
_id: string;
|
|
49
|
+
};
|
|
50
|
+
export declare const credit: Omit<import("pairz").CollectionDef, "schema" | "queries"> & {
|
|
51
|
+
queries?: Record<string, import("pairz").QueryDef<import("pairz").WithId<{
|
|
52
|
+
[x: string]: unknown;
|
|
53
|
+
expires?: string | undefined;
|
|
54
|
+
note?: string | undefined;
|
|
55
|
+
reason?: string | undefined;
|
|
56
|
+
by?: string | undefined;
|
|
57
|
+
takes?: string | undefined;
|
|
58
|
+
sandbox?: boolean | undefined;
|
|
59
|
+
kind: "trial" | "plan" | "gift" | "referral" | "purchase" | "waived" | "adjustment";
|
|
60
|
+
amount: number;
|
|
61
|
+
at: string;
|
|
62
|
+
}>>> | undefined;
|
|
63
|
+
} & {
|
|
64
|
+
schema: {
|
|
65
|
+
readonly type: "object";
|
|
66
|
+
readonly properties: {
|
|
67
|
+
readonly kind: {
|
|
68
|
+
readonly type: "string";
|
|
69
|
+
readonly enum: readonly ["trial", "plan", "gift", "referral", "purchase", "waived", "adjustment"];
|
|
70
|
+
};
|
|
71
|
+
readonly amount: {
|
|
72
|
+
readonly type: "number";
|
|
73
|
+
};
|
|
74
|
+
readonly at: {
|
|
75
|
+
readonly type: "string";
|
|
76
|
+
};
|
|
77
|
+
/** The first day (UTC, `YYYY-MM-DD`) it no longer counts; none: it doesn't expire. */
|
|
78
|
+
readonly expires: {
|
|
79
|
+
readonly type: "string";
|
|
80
|
+
};
|
|
81
|
+
/** What to show for it. */
|
|
82
|
+
readonly note: {
|
|
83
|
+
readonly type: "string";
|
|
84
|
+
};
|
|
85
|
+
/** Why it was given, and who gave it: for staff. */
|
|
86
|
+
readonly reason: {
|
|
87
|
+
readonly type: "string";
|
|
88
|
+
};
|
|
89
|
+
readonly by: {
|
|
90
|
+
readonly type: "string";
|
|
91
|
+
};
|
|
92
|
+
/** Taken away, what it comes out of first: a refund, of what the money bought. */
|
|
93
|
+
readonly takes: {
|
|
94
|
+
readonly type: "string";
|
|
95
|
+
};
|
|
96
|
+
/** From a test mode: it stops counting when the app goes live. */
|
|
97
|
+
readonly sandbox: {
|
|
98
|
+
readonly type: "boolean";
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
readonly required: readonly ["kind", "amount", "at"];
|
|
102
|
+
};
|
|
103
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credits an org was given or bought, in USD, appended and never changed: the
|
|
3
|
+
* same `_id` again is the one already kept, so a grant that comes from
|
|
4
|
+
* something (a period, a code, a payment) can't land twice. A negative amount
|
|
5
|
+
* takes credits away.
|
|
6
|
+
*/
|
|
7
|
+
import { defineCollection } from "pairz";
|
|
8
|
+
export const creditSchema = {
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
kind: {
|
|
12
|
+
type: "string",
|
|
13
|
+
enum: ["trial", "plan", "gift", "referral", "purchase", "waived", "adjustment"],
|
|
14
|
+
},
|
|
15
|
+
amount: { type: "number" },
|
|
16
|
+
at: { type: "string" },
|
|
17
|
+
/** The first day (UTC, `YYYY-MM-DD`) it no longer counts; none: it doesn't expire. */
|
|
18
|
+
expires: { type: "string" },
|
|
19
|
+
/** What to show for it. */
|
|
20
|
+
note: { type: "string" },
|
|
21
|
+
/** Why it was given, and who gave it: for staff. */
|
|
22
|
+
reason: { type: "string" },
|
|
23
|
+
by: { type: "string" },
|
|
24
|
+
/** Taken away, what it comes out of first: a refund, of what the money bought. */
|
|
25
|
+
takes: { type: "string" },
|
|
26
|
+
/** From a test mode: it stops counting when the app goes live. */
|
|
27
|
+
sandbox: { type: "boolean" },
|
|
28
|
+
},
|
|
29
|
+
required: ["kind", "amount", "at"],
|
|
30
|
+
};
|
|
31
|
+
export const credit = defineCollection({ records: true, schema: creditSchema });
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Money that came in, however it came: appended, one for each thing a channel
|
|
3
|
+
* collected (`_id`: `<channel>:<ref>`). What commissions and accounts read,
|
|
4
|
+
* so they never need to know who collected it.
|
|
5
|
+
*/
|
|
6
|
+
import { type Infer } from "pairz";
|
|
7
|
+
export declare const paymentSchema: {
|
|
8
|
+
readonly type: "object";
|
|
9
|
+
readonly properties: {
|
|
10
|
+
/** `manual`, `stripe`… and which account of it (a seller). */
|
|
11
|
+
readonly channel: {
|
|
12
|
+
readonly type: "string";
|
|
13
|
+
};
|
|
14
|
+
readonly seller: {
|
|
15
|
+
readonly type: "string";
|
|
16
|
+
};
|
|
17
|
+
readonly ref: {
|
|
18
|
+
readonly type: "string";
|
|
19
|
+
};
|
|
20
|
+
/** What was collected, in its currency's main unit, before tax. */
|
|
21
|
+
readonly amount: {
|
|
22
|
+
readonly type: "number";
|
|
23
|
+
};
|
|
24
|
+
readonly currency: {
|
|
25
|
+
readonly type: "string";
|
|
26
|
+
};
|
|
27
|
+
/** USD per unit of its currency, when it isn't USD. */
|
|
28
|
+
readonly rate: {
|
|
29
|
+
readonly type: "number";
|
|
30
|
+
};
|
|
31
|
+
/** What the channel kept. */
|
|
32
|
+
readonly fee: {
|
|
33
|
+
readonly type: "number";
|
|
34
|
+
};
|
|
35
|
+
/** What it was for, and the credits it bought (USD). */
|
|
36
|
+
readonly purpose: {
|
|
37
|
+
readonly type: "string";
|
|
38
|
+
readonly enum: readonly ["seats", "credits", "contract", "refund"];
|
|
39
|
+
};
|
|
40
|
+
readonly credits: {
|
|
41
|
+
readonly type: "number";
|
|
42
|
+
};
|
|
43
|
+
readonly note: {
|
|
44
|
+
readonly type: "string";
|
|
45
|
+
};
|
|
46
|
+
readonly by: {
|
|
47
|
+
readonly type: "string";
|
|
48
|
+
};
|
|
49
|
+
/** From a test mode: no real money. */
|
|
50
|
+
readonly sandbox: {
|
|
51
|
+
readonly type: "boolean";
|
|
52
|
+
};
|
|
53
|
+
readonly at: {
|
|
54
|
+
readonly type: "string";
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
readonly required: readonly ["channel", "ref", "amount", "currency", "purpose", "at"];
|
|
58
|
+
};
|
|
59
|
+
export type Payment = Infer<typeof paymentSchema> & {
|
|
60
|
+
_id: string;
|
|
61
|
+
};
|
|
62
|
+
export declare const payment: Omit<import("pairz").CollectionDef, "schema" | "queries"> & {
|
|
63
|
+
queries?: Record<string, import("pairz").QueryDef<import("pairz").WithId<{
|
|
64
|
+
[x: string]: unknown;
|
|
65
|
+
credits?: number | undefined;
|
|
66
|
+
note?: string | undefined;
|
|
67
|
+
by?: string | undefined;
|
|
68
|
+
sandbox?: boolean | undefined;
|
|
69
|
+
seller?: string | undefined;
|
|
70
|
+
rate?: number | undefined;
|
|
71
|
+
fee?: number | undefined;
|
|
72
|
+
amount: number;
|
|
73
|
+
at: string;
|
|
74
|
+
currency: string;
|
|
75
|
+
channel: string;
|
|
76
|
+
purpose: "credits" | "seats" | "contract" | "refund";
|
|
77
|
+
ref: string;
|
|
78
|
+
}>>> | undefined;
|
|
79
|
+
} & {
|
|
80
|
+
schema: {
|
|
81
|
+
readonly type: "object";
|
|
82
|
+
readonly properties: {
|
|
83
|
+
/** `manual`, `stripe`… and which account of it (a seller). */
|
|
84
|
+
readonly channel: {
|
|
85
|
+
readonly type: "string";
|
|
86
|
+
};
|
|
87
|
+
readonly seller: {
|
|
88
|
+
readonly type: "string";
|
|
89
|
+
};
|
|
90
|
+
readonly ref: {
|
|
91
|
+
readonly type: "string";
|
|
92
|
+
};
|
|
93
|
+
/** What was collected, in its currency's main unit, before tax. */
|
|
94
|
+
readonly amount: {
|
|
95
|
+
readonly type: "number";
|
|
96
|
+
};
|
|
97
|
+
readonly currency: {
|
|
98
|
+
readonly type: "string";
|
|
99
|
+
};
|
|
100
|
+
/** USD per unit of its currency, when it isn't USD. */
|
|
101
|
+
readonly rate: {
|
|
102
|
+
readonly type: "number";
|
|
103
|
+
};
|
|
104
|
+
/** What the channel kept. */
|
|
105
|
+
readonly fee: {
|
|
106
|
+
readonly type: "number";
|
|
107
|
+
};
|
|
108
|
+
/** What it was for, and the credits it bought (USD). */
|
|
109
|
+
readonly purpose: {
|
|
110
|
+
readonly type: "string";
|
|
111
|
+
readonly enum: readonly ["seats", "credits", "contract", "refund"];
|
|
112
|
+
};
|
|
113
|
+
readonly credits: {
|
|
114
|
+
readonly type: "number";
|
|
115
|
+
};
|
|
116
|
+
readonly note: {
|
|
117
|
+
readonly type: "string";
|
|
118
|
+
};
|
|
119
|
+
readonly by: {
|
|
120
|
+
readonly type: "string";
|
|
121
|
+
};
|
|
122
|
+
/** From a test mode: no real money. */
|
|
123
|
+
readonly sandbox: {
|
|
124
|
+
readonly type: "boolean";
|
|
125
|
+
};
|
|
126
|
+
readonly at: {
|
|
127
|
+
readonly type: "string";
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
readonly required: readonly ["channel", "ref", "amount", "currency", "purpose", "at"];
|
|
131
|
+
};
|
|
132
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Money that came in, however it came: appended, one for each thing a channel
|
|
3
|
+
* collected (`_id`: `<channel>:<ref>`). What commissions and accounts read,
|
|
4
|
+
* so they never need to know who collected it.
|
|
5
|
+
*/
|
|
6
|
+
import { defineCollection } from "pairz";
|
|
7
|
+
export const paymentSchema = {
|
|
8
|
+
type: "object",
|
|
9
|
+
properties: {
|
|
10
|
+
/** `manual`, `stripe`… and which account of it (a seller). */
|
|
11
|
+
channel: { type: "string" },
|
|
12
|
+
seller: { type: "string" },
|
|
13
|
+
ref: { type: "string" },
|
|
14
|
+
/** What was collected, in its currency's main unit, before tax. */
|
|
15
|
+
amount: { type: "number" },
|
|
16
|
+
currency: { type: "string" },
|
|
17
|
+
/** USD per unit of its currency, when it isn't USD. */
|
|
18
|
+
rate: { type: "number" },
|
|
19
|
+
/** What the channel kept. */
|
|
20
|
+
fee: { type: "number" },
|
|
21
|
+
/** What it was for, and the credits it bought (USD). */
|
|
22
|
+
purpose: { type: "string", enum: ["seats", "credits", "contract", "refund"] },
|
|
23
|
+
credits: { type: "number" },
|
|
24
|
+
note: { type: "string" },
|
|
25
|
+
by: { type: "string" },
|
|
26
|
+
/** From a test mode: no real money. */
|
|
27
|
+
sandbox: { type: "boolean" },
|
|
28
|
+
at: { type: "string" },
|
|
29
|
+
},
|
|
30
|
+
required: ["channel", "ref", "amount", "currency", "purpose", "at"],
|
|
31
|
+
};
|
|
32
|
+
export const payment = defineCollection({ records: true, schema: paymentSchema });
|