@frigear-nu/payments 0.0.8 → 0.0.10
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/dist/module.json +1 -1
- package/dist/module.mjs +13 -2
- package/dist/runtime/app/widgets/RecentTransactions.d.vue.ts +3 -0
- package/dist/runtime/app/widgets/RecentTransactions.vue +54 -0
- package/dist/runtime/app/widgets/RecentTransactions.vue.d.ts +3 -0
- package/dist/runtime/app/widgets/RevenueStat.d.vue.ts +3 -0
- package/dist/runtime/app/widgets/RevenueStat.vue +21 -0
- package/dist/runtime/app/widgets/RevenueStat.vue.d.ts +3 -0
- package/dist/runtime/i18n/lang/da.json +5 -1
- package/dist/runtime/i18n/lang/en.json +5 -1
- package/dist/runtime/server/db/schema.postgresql.d.ts +301 -0
- package/dist/runtime/server/db/schema.postgresql.js +31 -0
- package/dist/runtime/server/mcp/tools/my-payments.js +5 -2
- package/dist/runtime/server/routes/admin/recent.get.d.ts +2 -0
- package/dist/runtime/server/routes/admin/recent.get.js +23 -0
- package/package.json +9 -9
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addServerHandler, addServerImportsDir, addServerPlugin, addImports } from '@nuxt/kit';
|
|
2
|
-
import { registerModule, registerTailwindSource, registerLocales, registerDatabaseTable, moduleApiUrl } from '@frigear-nu/module-kit/utils';
|
|
1
|
+
import { defineNuxtModule, createResolver, addServerHandler, hasNuxtModule, addServerImportsDir, addServerPlugin, addImports } from '@nuxt/kit';
|
|
2
|
+
import { registerModule, registerTailwindSource, registerLocales, registerDatabaseTable, moduleApiUrl, inlineModuleRuntime } from '@frigear-nu/module-kit/utils';
|
|
3
3
|
import { addAuthScope } from '@frigear-nu/auth/utils';
|
|
4
4
|
import { extendUsersAdmin } from '@frigear-nu/users/utils';
|
|
5
5
|
import { addMcpDefinitions } from '@frigear-nu/mcp/utils';
|
|
@@ -80,7 +80,18 @@ const module$1 = defineNuxtModule({
|
|
|
80
80
|
span: 2
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
|
+
addServerHandler({
|
|
84
|
+
route: moduleApiUrl("payments", "admin/recent"),
|
|
85
|
+
method: "get",
|
|
86
|
+
handler: resolver.resolve("./runtime/server/routes/admin/recent.get")
|
|
87
|
+
});
|
|
88
|
+
if (hasNuxtModule("@frigear-nu/admin") && hasNuxtModule("@frigear-nu/widget")) {
|
|
89
|
+
const { extendWidgets } = await import('@frigear-nu/widget/utils');
|
|
90
|
+
extendWidgets(nuxt, "admin.dashboard.top", { id: "payments-revenue-stat", component: resolver.resolve("./runtime/app/widgets/RevenueStat.vue"), order: 30 });
|
|
91
|
+
extendWidgets(nuxt, "admin.dashboard.side", { id: "payments-recent", component: resolver.resolve("./runtime/app/widgets/RecentTransactions.vue"), order: 20 });
|
|
92
|
+
}
|
|
83
93
|
addServerImportsDir(resolver.resolve("./runtime/server/utils"));
|
|
94
|
+
inlineModuleRuntime(nuxt, resolver);
|
|
84
95
|
addServerPlugin(resolver.resolve("./runtime/server/plugins/invoice-payments"));
|
|
85
96
|
if (options.settings?.mcp === true) addMcpDefinitions(nuxt, resolver.resolve("./runtime/server/mcp"));
|
|
86
97
|
addImports([
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { formatMoney } from "@frigear-nu/ui/money";
|
|
3
|
+
defineOptions({ name: "PaymentsRecentTransactions" });
|
|
4
|
+
const t = useModuleT("payments.admin");
|
|
5
|
+
const status = useModuleT("payments.status");
|
|
6
|
+
const usersPage = useRuntimeConfig().public.users?.pages?.admin;
|
|
7
|
+
const { data, status: fetchStatus } = useLazyFetch("/api/payments/admin/recent", { key: "admin-payments-recent" });
|
|
8
|
+
const date = (value) => value ? new Date(value).toLocaleDateString() : "\u2013";
|
|
9
|
+
const color = (value) => value === "paid" ? "success" : value === "failed" ? "error" : "neutral";
|
|
10
|
+
const userTo = (id) => usersPage ? `${usersPage.replace(/\/+$/, "")}/${id}` : void 0;
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<template>
|
|
14
|
+
<AdminListCard
|
|
15
|
+
:title="t('recent', 'Recent transactions')"
|
|
16
|
+
:loading="fetchStatus === 'pending' && !data"
|
|
17
|
+
:is-empty="!data?.items.length"
|
|
18
|
+
:empty="t('empty', 'No payments yet.')"
|
|
19
|
+
>
|
|
20
|
+
<li
|
|
21
|
+
v-for="payment in data?.items"
|
|
22
|
+
:key="payment.id"
|
|
23
|
+
class="flex items-center justify-between gap-3"
|
|
24
|
+
>
|
|
25
|
+
<div class="min-w-0">
|
|
26
|
+
<NuxtLink
|
|
27
|
+
v-if="userTo(payment.userId)"
|
|
28
|
+
:to="userTo(payment.userId)"
|
|
29
|
+
class="text-highlighted block truncate font-medium hover:underline"
|
|
30
|
+
>
|
|
31
|
+
{{ payment.userName ?? payment.description ?? t("defaultDescription", "Payment") }}
|
|
32
|
+
</NuxtLink>
|
|
33
|
+
<span
|
|
34
|
+
v-else
|
|
35
|
+
class="text-highlighted block truncate font-medium"
|
|
36
|
+
>{{ payment.userName ?? payment.description ?? t("defaultDescription", "Payment") }}</span>
|
|
37
|
+
<p class="text-muted truncate text-xs">
|
|
38
|
+
{{ date(payment.paidAt ?? payment.createdAt) }}<template v-if="payment.description && payment.userName">
|
|
39
|
+
· {{ payment.description }}
|
|
40
|
+
</template>
|
|
41
|
+
</p>
|
|
42
|
+
</div>
|
|
43
|
+
<div class="flex shrink-0 flex-col items-end gap-1">
|
|
44
|
+
<span class="text-highlighted font-medium">{{ formatMoney(payment.amount, payment.currency) }}</span>
|
|
45
|
+
<UBadge
|
|
46
|
+
size="sm"
|
|
47
|
+
variant="subtle"
|
|
48
|
+
:color="color(payment.status)"
|
|
49
|
+
:label="status(payment.status, payment.status)"
|
|
50
|
+
/>
|
|
51
|
+
</div>
|
|
52
|
+
</li>
|
|
53
|
+
</AdminListCard>
|
|
54
|
+
</template>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { formatMoney } from "@frigear-nu/ui/money";
|
|
3
|
+
defineOptions({ name: "PaymentsRevenueStat" });
|
|
4
|
+
const t = useModuleT("payments.admin");
|
|
5
|
+
const { data, status } = useLazyFetch("/api/payments/admin/recent", { key: "admin-payments-recent" });
|
|
6
|
+
const main = computed(() => data.value?.revenue[0]);
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<template>
|
|
10
|
+
<AdminStatCard
|
|
11
|
+
:label="t('revenue', 'Revenue, 30 days')"
|
|
12
|
+
icon="i-lucide-circle-dollar-sign"
|
|
13
|
+
:loading="status === 'pending' && !data"
|
|
14
|
+
:empty="t('noRevenue', 'No payments yet.')"
|
|
15
|
+
>
|
|
16
|
+
<template v-if="main">
|
|
17
|
+
<span>{{ formatMoney(main.amount, main.currency) }}</span>
|
|
18
|
+
<span class="text-muted text-sm font-normal">{{ t("transactions", "{count} transactions").replace("{count}", String(main.count)) }}</span>
|
|
19
|
+
</template>
|
|
20
|
+
</AdminStatCard>
|
|
21
|
+
</template>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
@@ -20,7 +20,11 @@
|
|
|
20
20
|
"statusColumn": "Status",
|
|
21
21
|
"refunded": "Refunderet",
|
|
22
22
|
"reference": "Reference",
|
|
23
|
-
"defaultDescription": "Betaling"
|
|
23
|
+
"defaultDescription": "Betaling",
|
|
24
|
+
"revenue": "Omsætning, 30 dage",
|
|
25
|
+
"noRevenue": "Ingen betalinger endnu.",
|
|
26
|
+
"transactions": "{count} transaktioner",
|
|
27
|
+
"recent": "Seneste transaktioner"
|
|
24
28
|
}
|
|
25
29
|
}
|
|
26
30
|
}
|
|
@@ -20,7 +20,11 @@
|
|
|
20
20
|
"statusColumn": "Status",
|
|
21
21
|
"refunded": "Refunded",
|
|
22
22
|
"reference": "Reference",
|
|
23
|
-
"defaultDescription": "Payment"
|
|
23
|
+
"defaultDescription": "Payment",
|
|
24
|
+
"revenue": "Revenue, 30 days",
|
|
25
|
+
"noRevenue": "No payments yet.",
|
|
26
|
+
"transactions": "{count} transactions",
|
|
27
|
+
"recent": "Recent transactions"
|
|
24
28
|
}
|
|
25
29
|
}
|
|
26
30
|
}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import type { PaymentItem } from '../../../types.js';
|
|
2
|
+
export declare const payments: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
3
|
+
name: "payments";
|
|
4
|
+
schema: undefined;
|
|
5
|
+
columns: {
|
|
6
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
7
|
+
name: "id";
|
|
8
|
+
tableName: "payments";
|
|
9
|
+
dataType: "string";
|
|
10
|
+
columnType: "PgText";
|
|
11
|
+
data: string;
|
|
12
|
+
driverParam: string;
|
|
13
|
+
notNull: true;
|
|
14
|
+
hasDefault: false;
|
|
15
|
+
isPrimaryKey: true;
|
|
16
|
+
isAutoincrement: false;
|
|
17
|
+
hasRuntimeDefault: false;
|
|
18
|
+
enumValues: [string, ...string[]];
|
|
19
|
+
baseColumn: never;
|
|
20
|
+
identity: undefined;
|
|
21
|
+
generated: undefined;
|
|
22
|
+
}, {}, {}>;
|
|
23
|
+
userId: import("drizzle-orm/pg-core").PgColumn<{
|
|
24
|
+
name: "userId";
|
|
25
|
+
tableName: "payments";
|
|
26
|
+
dataType: "number";
|
|
27
|
+
columnType: "PgInteger";
|
|
28
|
+
data: number;
|
|
29
|
+
driverParam: string | number;
|
|
30
|
+
notNull: true;
|
|
31
|
+
hasDefault: false;
|
|
32
|
+
isPrimaryKey: false;
|
|
33
|
+
isAutoincrement: false;
|
|
34
|
+
hasRuntimeDefault: false;
|
|
35
|
+
enumValues: undefined;
|
|
36
|
+
baseColumn: never;
|
|
37
|
+
identity: undefined;
|
|
38
|
+
generated: undefined;
|
|
39
|
+
}, {}, {}>;
|
|
40
|
+
status: import("drizzle-orm/pg-core").PgColumn<{
|
|
41
|
+
name: "status";
|
|
42
|
+
tableName: "payments";
|
|
43
|
+
dataType: "string";
|
|
44
|
+
columnType: "PgText";
|
|
45
|
+
data: string;
|
|
46
|
+
driverParam: string;
|
|
47
|
+
notNull: true;
|
|
48
|
+
hasDefault: true;
|
|
49
|
+
isPrimaryKey: false;
|
|
50
|
+
isAutoincrement: false;
|
|
51
|
+
hasRuntimeDefault: false;
|
|
52
|
+
enumValues: [string, ...string[]];
|
|
53
|
+
baseColumn: never;
|
|
54
|
+
identity: undefined;
|
|
55
|
+
generated: undefined;
|
|
56
|
+
}, {}, {}>;
|
|
57
|
+
amount: import("drizzle-orm/pg-core").PgColumn<{
|
|
58
|
+
name: "amount";
|
|
59
|
+
tableName: "payments";
|
|
60
|
+
dataType: "number";
|
|
61
|
+
columnType: "PgInteger";
|
|
62
|
+
data: number;
|
|
63
|
+
driverParam: string | number;
|
|
64
|
+
notNull: true;
|
|
65
|
+
hasDefault: false;
|
|
66
|
+
isPrimaryKey: false;
|
|
67
|
+
isAutoincrement: false;
|
|
68
|
+
hasRuntimeDefault: false;
|
|
69
|
+
enumValues: undefined;
|
|
70
|
+
baseColumn: never;
|
|
71
|
+
identity: undefined;
|
|
72
|
+
generated: undefined;
|
|
73
|
+
}, {}, {}>;
|
|
74
|
+
currency: import("drizzle-orm/pg-core").PgColumn<{
|
|
75
|
+
name: "currency";
|
|
76
|
+
tableName: "payments";
|
|
77
|
+
dataType: "string";
|
|
78
|
+
columnType: "PgText";
|
|
79
|
+
data: string;
|
|
80
|
+
driverParam: string;
|
|
81
|
+
notNull: true;
|
|
82
|
+
hasDefault: false;
|
|
83
|
+
isPrimaryKey: false;
|
|
84
|
+
isAutoincrement: false;
|
|
85
|
+
hasRuntimeDefault: false;
|
|
86
|
+
enumValues: [string, ...string[]];
|
|
87
|
+
baseColumn: never;
|
|
88
|
+
identity: undefined;
|
|
89
|
+
generated: undefined;
|
|
90
|
+
}, {}, {}>;
|
|
91
|
+
description: import("drizzle-orm/pg-core").PgColumn<{
|
|
92
|
+
name: "description";
|
|
93
|
+
tableName: "payments";
|
|
94
|
+
dataType: "string";
|
|
95
|
+
columnType: "PgText";
|
|
96
|
+
data: string;
|
|
97
|
+
driverParam: string;
|
|
98
|
+
notNull: false;
|
|
99
|
+
hasDefault: false;
|
|
100
|
+
isPrimaryKey: false;
|
|
101
|
+
isAutoincrement: false;
|
|
102
|
+
hasRuntimeDefault: false;
|
|
103
|
+
enumValues: [string, ...string[]];
|
|
104
|
+
baseColumn: never;
|
|
105
|
+
identity: undefined;
|
|
106
|
+
generated: undefined;
|
|
107
|
+
}, {}, {}>;
|
|
108
|
+
referenceType: import("drizzle-orm/pg-core").PgColumn<{
|
|
109
|
+
name: "referenceType";
|
|
110
|
+
tableName: "payments";
|
|
111
|
+
dataType: "string";
|
|
112
|
+
columnType: "PgText";
|
|
113
|
+
data: string;
|
|
114
|
+
driverParam: string;
|
|
115
|
+
notNull: false;
|
|
116
|
+
hasDefault: false;
|
|
117
|
+
isPrimaryKey: false;
|
|
118
|
+
isAutoincrement: false;
|
|
119
|
+
hasRuntimeDefault: false;
|
|
120
|
+
enumValues: [string, ...string[]];
|
|
121
|
+
baseColumn: never;
|
|
122
|
+
identity: undefined;
|
|
123
|
+
generated: undefined;
|
|
124
|
+
}, {}, {}>;
|
|
125
|
+
referenceId: import("drizzle-orm/pg-core").PgColumn<{
|
|
126
|
+
name: "referenceId";
|
|
127
|
+
tableName: "payments";
|
|
128
|
+
dataType: "string";
|
|
129
|
+
columnType: "PgText";
|
|
130
|
+
data: string;
|
|
131
|
+
driverParam: string;
|
|
132
|
+
notNull: false;
|
|
133
|
+
hasDefault: false;
|
|
134
|
+
isPrimaryKey: false;
|
|
135
|
+
isAutoincrement: false;
|
|
136
|
+
hasRuntimeDefault: false;
|
|
137
|
+
enumValues: [string, ...string[]];
|
|
138
|
+
baseColumn: never;
|
|
139
|
+
identity: undefined;
|
|
140
|
+
generated: undefined;
|
|
141
|
+
}, {}, {}>;
|
|
142
|
+
checkoutSessionId: import("drizzle-orm/pg-core").PgColumn<{
|
|
143
|
+
name: "checkoutSessionId";
|
|
144
|
+
tableName: "payments";
|
|
145
|
+
dataType: "string";
|
|
146
|
+
columnType: "PgText";
|
|
147
|
+
data: string;
|
|
148
|
+
driverParam: string;
|
|
149
|
+
notNull: false;
|
|
150
|
+
hasDefault: false;
|
|
151
|
+
isPrimaryKey: false;
|
|
152
|
+
isAutoincrement: false;
|
|
153
|
+
hasRuntimeDefault: false;
|
|
154
|
+
enumValues: [string, ...string[]];
|
|
155
|
+
baseColumn: never;
|
|
156
|
+
identity: undefined;
|
|
157
|
+
generated: undefined;
|
|
158
|
+
}, {}, {}>;
|
|
159
|
+
invoiceId: import("drizzle-orm/pg-core").PgColumn<{
|
|
160
|
+
name: "invoiceId";
|
|
161
|
+
tableName: "payments";
|
|
162
|
+
dataType: "string";
|
|
163
|
+
columnType: "PgText";
|
|
164
|
+
data: string;
|
|
165
|
+
driverParam: string;
|
|
166
|
+
notNull: false;
|
|
167
|
+
hasDefault: false;
|
|
168
|
+
isPrimaryKey: false;
|
|
169
|
+
isAutoincrement: false;
|
|
170
|
+
hasRuntimeDefault: false;
|
|
171
|
+
enumValues: [string, ...string[]];
|
|
172
|
+
baseColumn: never;
|
|
173
|
+
identity: undefined;
|
|
174
|
+
generated: undefined;
|
|
175
|
+
}, {}, {}>;
|
|
176
|
+
paymentIntentId: import("drizzle-orm/pg-core").PgColumn<{
|
|
177
|
+
name: "paymentIntentId";
|
|
178
|
+
tableName: "payments";
|
|
179
|
+
dataType: "string";
|
|
180
|
+
columnType: "PgText";
|
|
181
|
+
data: string;
|
|
182
|
+
driverParam: string;
|
|
183
|
+
notNull: false;
|
|
184
|
+
hasDefault: false;
|
|
185
|
+
isPrimaryKey: false;
|
|
186
|
+
isAutoincrement: false;
|
|
187
|
+
hasRuntimeDefault: false;
|
|
188
|
+
enumValues: [string, ...string[]];
|
|
189
|
+
baseColumn: never;
|
|
190
|
+
identity: undefined;
|
|
191
|
+
generated: undefined;
|
|
192
|
+
}, {}, {}>;
|
|
193
|
+
refundedAmount: import("drizzle-orm/pg-core").PgColumn<{
|
|
194
|
+
name: "refundedAmount";
|
|
195
|
+
tableName: "payments";
|
|
196
|
+
dataType: "number";
|
|
197
|
+
columnType: "PgInteger";
|
|
198
|
+
data: number;
|
|
199
|
+
driverParam: string | number;
|
|
200
|
+
notNull: true;
|
|
201
|
+
hasDefault: true;
|
|
202
|
+
isPrimaryKey: false;
|
|
203
|
+
isAutoincrement: false;
|
|
204
|
+
hasRuntimeDefault: false;
|
|
205
|
+
enumValues: undefined;
|
|
206
|
+
baseColumn: never;
|
|
207
|
+
identity: undefined;
|
|
208
|
+
generated: undefined;
|
|
209
|
+
}, {}, {}>;
|
|
210
|
+
metadata: import("drizzle-orm/pg-core").PgColumn<{
|
|
211
|
+
name: "metadata";
|
|
212
|
+
tableName: "payments";
|
|
213
|
+
dataType: "json";
|
|
214
|
+
columnType: "PgJsonb";
|
|
215
|
+
data: Record<string, string>;
|
|
216
|
+
driverParam: unknown;
|
|
217
|
+
notNull: false;
|
|
218
|
+
hasDefault: false;
|
|
219
|
+
isPrimaryKey: false;
|
|
220
|
+
isAutoincrement: false;
|
|
221
|
+
hasRuntimeDefault: false;
|
|
222
|
+
enumValues: undefined;
|
|
223
|
+
baseColumn: never;
|
|
224
|
+
identity: undefined;
|
|
225
|
+
generated: undefined;
|
|
226
|
+
}, {}, {
|
|
227
|
+
$type: Record<string, string>;
|
|
228
|
+
}>;
|
|
229
|
+
items: import("drizzle-orm/pg-core").PgColumn<{
|
|
230
|
+
name: "items";
|
|
231
|
+
tableName: "payments";
|
|
232
|
+
dataType: "json";
|
|
233
|
+
columnType: "PgJsonb";
|
|
234
|
+
data: PaymentItem[];
|
|
235
|
+
driverParam: unknown;
|
|
236
|
+
notNull: false;
|
|
237
|
+
hasDefault: false;
|
|
238
|
+
isPrimaryKey: false;
|
|
239
|
+
isAutoincrement: false;
|
|
240
|
+
hasRuntimeDefault: false;
|
|
241
|
+
enumValues: undefined;
|
|
242
|
+
baseColumn: never;
|
|
243
|
+
identity: undefined;
|
|
244
|
+
generated: undefined;
|
|
245
|
+
}, {}, {
|
|
246
|
+
$type: PaymentItem[];
|
|
247
|
+
}>;
|
|
248
|
+
paidAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
249
|
+
name: "paidAt";
|
|
250
|
+
tableName: "payments";
|
|
251
|
+
dataType: "date";
|
|
252
|
+
columnType: "PgTimestamp";
|
|
253
|
+
data: Date;
|
|
254
|
+
driverParam: string;
|
|
255
|
+
notNull: false;
|
|
256
|
+
hasDefault: false;
|
|
257
|
+
isPrimaryKey: false;
|
|
258
|
+
isAutoincrement: false;
|
|
259
|
+
hasRuntimeDefault: false;
|
|
260
|
+
enumValues: undefined;
|
|
261
|
+
baseColumn: never;
|
|
262
|
+
identity: undefined;
|
|
263
|
+
generated: undefined;
|
|
264
|
+
}, {}, {}>;
|
|
265
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
266
|
+
name: "createdAt";
|
|
267
|
+
tableName: "payments";
|
|
268
|
+
dataType: "date";
|
|
269
|
+
columnType: "PgTimestamp";
|
|
270
|
+
data: Date;
|
|
271
|
+
driverParam: string;
|
|
272
|
+
notNull: true;
|
|
273
|
+
hasDefault: true;
|
|
274
|
+
isPrimaryKey: false;
|
|
275
|
+
isAutoincrement: false;
|
|
276
|
+
hasRuntimeDefault: true;
|
|
277
|
+
enumValues: undefined;
|
|
278
|
+
baseColumn: never;
|
|
279
|
+
identity: undefined;
|
|
280
|
+
generated: undefined;
|
|
281
|
+
}, {}, {}>;
|
|
282
|
+
updatedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
283
|
+
name: "updatedAt";
|
|
284
|
+
tableName: "payments";
|
|
285
|
+
dataType: "date";
|
|
286
|
+
columnType: "PgTimestamp";
|
|
287
|
+
data: Date;
|
|
288
|
+
driverParam: string;
|
|
289
|
+
notNull: true;
|
|
290
|
+
hasDefault: true;
|
|
291
|
+
isPrimaryKey: false;
|
|
292
|
+
isAutoincrement: false;
|
|
293
|
+
hasRuntimeDefault: true;
|
|
294
|
+
enumValues: undefined;
|
|
295
|
+
baseColumn: never;
|
|
296
|
+
identity: undefined;
|
|
297
|
+
generated: undefined;
|
|
298
|
+
}, {}, {}>;
|
|
299
|
+
};
|
|
300
|
+
dialect: "pg";
|
|
301
|
+
}>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { pgTable, text, integer, jsonb, timestamp, index } from "drizzle-orm/pg-core";
|
|
2
|
+
export const payments = pgTable("payments", {
|
|
3
|
+
/** `pay_` + random id. */
|
|
4
|
+
id: text().primaryKey(),
|
|
5
|
+
userId: integer().notNull(),
|
|
6
|
+
/** `pending | paid | failed | expired | refunded | partially_refunded`. */
|
|
7
|
+
status: text().notNull().default("pending"),
|
|
8
|
+
/** Total in the currency's minor unit. */
|
|
9
|
+
amount: integer().notNull(),
|
|
10
|
+
currency: text().notNull(),
|
|
11
|
+
description: text(),
|
|
12
|
+
/** What the payment is for (e.g. `event_ticket`) and the id of that thing. */
|
|
13
|
+
referenceType: text(),
|
|
14
|
+
referenceId: text(),
|
|
15
|
+
/** `null` for payments recorded from a Stripe invoice (e.g. a membership renewal), which have no Checkout session. */
|
|
16
|
+
checkoutSessionId: text().unique(),
|
|
17
|
+
/** Stripe invoice id for payments recorded from an invoice (see `recordInvoicePayment`). */
|
|
18
|
+
invoiceId: text().unique(),
|
|
19
|
+
paymentIntentId: text(),
|
|
20
|
+
refundedAmount: integer().notNull().default(0),
|
|
21
|
+
metadata: jsonb().$type(),
|
|
22
|
+
/** The line items the session was created from, so an expired session can be rebuilt. `null` for rows created before this column existed. */
|
|
23
|
+
items: jsonb().$type(),
|
|
24
|
+
paidAt: timestamp({ withTimezone: true }),
|
|
25
|
+
createdAt: timestamp({ withTimezone: true }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
|
|
26
|
+
updatedAt: timestamp({ withTimezone: true }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()).$onUpdateFn(() => /* @__PURE__ */ new Date())
|
|
27
|
+
}, (t) => [
|
|
28
|
+
index("payment_user_idx").on(t.userId),
|
|
29
|
+
index("payment_reference_idx").on(t.referenceType, t.referenceId),
|
|
30
|
+
index("payment_intent_idx").on(t.paymentIntentId)
|
|
31
|
+
]);
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { fieldsFromCents } from "@frigear-nu/mcp/utils";
|
|
2
3
|
export default defineScopedMcpTool({
|
|
3
|
-
description: "List your own payments, newest first: tickets, memberships and other charges with amount, status, refunds and what each was for.",
|
|
4
|
+
description: "List your own payments, newest first: tickets, memberships and other charges with amount, status, refunds and what each was for. Amounts are in whole currency units (52.2 = 52.20), not cents.",
|
|
4
5
|
scopes: ["payments:read"],
|
|
5
6
|
annotations: { readOnlyHint: true },
|
|
6
7
|
inputSchema: { limit: z.number().int().min(1).max(100).optional().describe("How many payments to return (default 50).") },
|
|
7
|
-
handler: async ({ limit }, { user }) => ({
|
|
8
|
+
handler: async ({ limit }, { user }) => ({
|
|
9
|
+
payments: (await listUserPayments(user.id, { limit: limit ?? 50 })).map((payment) => fieldsFromCents({ ...payment, currency: payment.currency.toUpperCase() }, ["amount", "refundedAmount"], payment.currency))
|
|
10
|
+
})
|
|
8
11
|
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { db, schema } from "@nuxthub/db";
|
|
2
|
+
import { and, count, desc, eq, gte, inArray, sql } from "drizzle-orm";
|
|
3
|
+
const DAYS = 30;
|
|
4
|
+
const LIMIT = 8;
|
|
5
|
+
export default defineEventHandler(async (event) => {
|
|
6
|
+
await authorizeUsersAdmin(event, "view");
|
|
7
|
+
const since = new Date(Date.now() - DAYS * 24 * 60 * 60 * 1e3);
|
|
8
|
+
const settled = inArray(schema.payments.status, ["paid", "partially_refunded"]);
|
|
9
|
+
const when = sql`coalesce(${schema.payments.paidAt}, ${schema.payments.createdAt})`;
|
|
10
|
+
const [revenue, rows] = await Promise.all([
|
|
11
|
+
db.select({
|
|
12
|
+
currency: schema.payments.currency,
|
|
13
|
+
amount: sql`sum(${schema.payments.amount} - ${schema.payments.refundedAmount})`,
|
|
14
|
+
count: count()
|
|
15
|
+
}).from(schema.payments).where(and(settled, gte(schema.payments.paidAt, since))).groupBy(schema.payments.currency).orderBy(desc(count())),
|
|
16
|
+
db.select({ payment: schema.payments, userName: schema.users.name }).from(schema.payments).leftJoin(schema.users, eq(schema.users.id, schema.payments.userId)).where(inArray(schema.payments.status, ["paid", "partially_refunded", "refunded", "failed"])).orderBy(desc(when)).limit(LIMIT)
|
|
17
|
+
]);
|
|
18
|
+
return {
|
|
19
|
+
days: DAYS,
|
|
20
|
+
revenue: revenue.map((row) => ({ currency: row.currency, amount: Number(row.amount), count: row.count })),
|
|
21
|
+
items: rows.map((row) => ({ ...toPaymentDto(row.payment), userName: row.userName }))
|
|
22
|
+
};
|
|
23
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frigear-nu/payments",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "One-time payments (Stripe Checkout, refunds and payment lifecycle hooks) for the frigear ecosystem, built on @frigear-nu/stripe.",
|
|
5
5
|
"homepage": "https://docs.frigear.dev/modules/payments",
|
|
6
6
|
"repository": {
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"playground"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@frigear-nu/auth": "0.0.
|
|
34
|
-
"@frigear-nu/mcp": "0.0.
|
|
35
|
-
"@frigear-nu/module-kit": "0.1
|
|
36
|
-
"@frigear-nu/stripe": "0.0.
|
|
37
|
-
"@frigear-nu/ui": "0.0.
|
|
38
|
-
"@frigear-nu/users": "1.0.
|
|
33
|
+
"@frigear-nu/auth": "0.0.5",
|
|
34
|
+
"@frigear-nu/mcp": "0.0.5",
|
|
35
|
+
"@frigear-nu/module-kit": "1.0.1",
|
|
36
|
+
"@frigear-nu/stripe": "0.0.10",
|
|
37
|
+
"@frigear-nu/ui": "0.0.9",
|
|
38
|
+
"@frigear-nu/users": "1.0.11",
|
|
39
39
|
"@libsql/client": "^0.18.0",
|
|
40
40
|
"@nuxt/kit": "^4.6.0",
|
|
41
41
|
"drizzle-kit": "^0.31.11",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"zod": "^4.6.5"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@frigear-nu/widget": "0.0.
|
|
49
|
+
"@frigear-nu/widget": "0.0.4",
|
|
50
50
|
"@nuxt/ui": "^4.10.0",
|
|
51
51
|
"@nuxthub/core": "^0.10.8"
|
|
52
52
|
},
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@frigear-nu/widget": "0.0.
|
|
62
|
+
"@frigear-nu/widget": "0.0.4",
|
|
63
63
|
"@nuxt/devtools": "^3.4.2",
|
|
64
64
|
"@nuxt/eslint-config": "^1.17.0",
|
|
65
65
|
"@nuxt/module-builder": "^1.0.3",
|