@dineway-ai/plugin-payment 0.2.6 → 0.2.8
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/package.json +3 -2
- package/src/admin/subscriptions.tsx +160 -58
- package/src/admin.tsx +17 -3
- package/src/configuration/repository.ts +7 -3
- package/src/configuration/secrets.ts +1 -3
- package/src/database/index.ts +12 -0
- package/src/database/migrations/001_stripe_configuration.ts +100 -0
- package/src/database/migrations/002_subscriptions.ts +168 -0
- package/src/database/migrations/003_purchases.ts +193 -0
- package/src/database/migrations/adoption.ts +27 -0
- package/src/database/types.ts +137 -0
- package/src/index.ts +25 -0
- package/src/stripe/webhook-verifier.ts +1 -0
- package/src/subscriptions/funding.ts +256 -0
- package/src/subscriptions/index.ts +1 -0
- package/src/subscriptions/projection.ts +39 -7
- package/src/subscriptions/purchases.ts +329 -0
- package/src/subscriptions/refunds.ts +134 -0
- package/src/subscriptions/repository.ts +352 -13
- package/src/subscriptions/routes.ts +11 -40
- package/src/subscriptions/runtime.ts +6 -8
- package/src/subscriptions/schemas.ts +45 -0
- package/src/subscriptions/service.ts +486 -203
- package/src/subscriptions/types.ts +90 -0
- package/src/types.ts +2 -0
- package/src/webhooks/index.ts +2 -0
- package/src/webhooks/routes.ts +109 -0
- package/src/webhooks/types.ts +21 -0
|
@@ -3,9 +3,10 @@ import { getDb, type PluginSecretStoreOptions } from "dineway";
|
|
|
3
3
|
import {
|
|
4
4
|
PaymentStripeSecretStore,
|
|
5
5
|
PAYMENT_STRIPE_SECRET_KEY,
|
|
6
|
-
|
|
6
|
+
PAYMENT_STRIPE_WEBHOOK_SECRET,
|
|
7
7
|
} from "../configuration/secrets.js";
|
|
8
8
|
import { getPaymentStripeConfiguration } from "../configuration/service.js";
|
|
9
|
+
import { PAYMENT_WEBHOOK_PATH } from "../webhooks/types.js";
|
|
9
10
|
import { PaymentSubscriptionService } from "./service.js";
|
|
10
11
|
import { SubscriptionError, type SubscriptionOptions } from "./types.js";
|
|
11
12
|
|
|
@@ -17,7 +18,7 @@ export async function getPaymentSubscriptionService(
|
|
|
17
18
|
const config = await getPaymentStripeConfiguration(db, secretOptions);
|
|
18
19
|
const store = new PaymentStripeSecretStore(db, secretOptions);
|
|
19
20
|
const secretKey = await store.resolveForRuntime(PAYMENT_STRIPE_SECRET_KEY);
|
|
20
|
-
const webhookSecret = await store.resolveForRuntime(
|
|
21
|
+
const webhookSecret = await store.resolveForRuntime(PAYMENT_STRIPE_WEBHOOK_SECRET);
|
|
21
22
|
if (
|
|
22
23
|
config.settings.configurationStatus !== "valid" ||
|
|
23
24
|
!config.settings.stripeAccountId ||
|
|
@@ -26,7 +27,7 @@ export async function getPaymentSubscriptionService(
|
|
|
26
27
|
) {
|
|
27
28
|
throw new SubscriptionError(
|
|
28
29
|
"BILLING_UNAVAILABLE",
|
|
29
|
-
"Configure and verify Stripe and the
|
|
30
|
+
"Configure and verify Stripe and the Payment webhook first",
|
|
30
31
|
503,
|
|
31
32
|
);
|
|
32
33
|
}
|
|
@@ -47,7 +48,7 @@ export async function getSubscriptionConfiguration(options: SubscriptionOptions)
|
|
|
47
48
|
const db = await getDb();
|
|
48
49
|
const configuration = await getPaymentStripeConfiguration(db);
|
|
49
50
|
const webhookSecret = await new PaymentStripeSecretStore(db).status(
|
|
50
|
-
|
|
51
|
+
PAYMENT_STRIPE_WEBHOOK_SECRET,
|
|
51
52
|
);
|
|
52
53
|
return {
|
|
53
54
|
namespace: options.namespace,
|
|
@@ -57,9 +58,6 @@ export async function getSubscriptionConfiguration(options: SubscriptionOptions)
|
|
|
57
58
|
configuration.settings.configurationStatus === "valid" &&
|
|
58
59
|
Boolean(configuration.secretKey && webhookSecret),
|
|
59
60
|
webhookSecret,
|
|
60
|
-
webhookUrl: new URL(
|
|
61
|
-
"/_dineway/api/plugins/dineway-payment/subscriptions/webhook",
|
|
62
|
-
options.siteUrl,
|
|
63
|
-
).href,
|
|
61
|
+
webhookUrl: new URL(PAYMENT_WEBHOOK_PATH, options.siteUrl).href,
|
|
64
62
|
};
|
|
65
63
|
}
|
|
@@ -90,6 +90,51 @@ export const checkoutSchema = z
|
|
|
90
90
|
})
|
|
91
91
|
.strict();
|
|
92
92
|
export const portalSchema = checkoutSchema.pick({ locale: true, returnPath: true });
|
|
93
|
+
export const billingSubjectSchema = z
|
|
94
|
+
.object({
|
|
95
|
+
realm: subscriptionCode.refine((value) => value !== "dineway", "The Dineway realm is reserved"),
|
|
96
|
+
id: z
|
|
97
|
+
.string()
|
|
98
|
+
.min(1)
|
|
99
|
+
.max(128)
|
|
100
|
+
.regex(/^[A-Za-z0-9_.:-]+$/),
|
|
101
|
+
email: z.string().trim().email().max(320),
|
|
102
|
+
emailVerified: z.literal(true),
|
|
103
|
+
})
|
|
104
|
+
.strict();
|
|
105
|
+
const purchaseKey = z
|
|
106
|
+
.string()
|
|
107
|
+
.min(1)
|
|
108
|
+
.max(160)
|
|
109
|
+
.regex(/^[A-Za-z0-9_.:-]+$/);
|
|
110
|
+
export const purchaseSchema = z
|
|
111
|
+
.object({
|
|
112
|
+
reference: purchaseKey,
|
|
113
|
+
groupKey: purchaseKey,
|
|
114
|
+
pricing: z.discriminatedUnion("kind", [
|
|
115
|
+
z
|
|
116
|
+
.object({
|
|
117
|
+
kind: z.literal("catalogue"),
|
|
118
|
+
planCode: subscriptionCode,
|
|
119
|
+
interval: z.enum(["month", "year"]),
|
|
120
|
+
})
|
|
121
|
+
.strict(),
|
|
122
|
+
z
|
|
123
|
+
.object({
|
|
124
|
+
kind: z.literal("dynamic"),
|
|
125
|
+
name: z.string().trim().min(1).max(160),
|
|
126
|
+
amount: z.number().int().min(1).max(99999999),
|
|
127
|
+
currency: z.string().regex(/^[a-z]{3}$/),
|
|
128
|
+
interval: z.enum(["day", "week", "month", "year"]),
|
|
129
|
+
intervalCount: z.number().int().min(1).max(365),
|
|
130
|
+
})
|
|
131
|
+
.strict(),
|
|
132
|
+
]),
|
|
133
|
+
firstPeriodCredit: z.number().int().min(0).max(99999999).default(0),
|
|
134
|
+
returnPath: subscriptionReturnPath,
|
|
135
|
+
locale: subscriptionLocale.default("auto"),
|
|
136
|
+
})
|
|
137
|
+
.strict();
|
|
93
138
|
export const memberListSchema = z
|
|
94
139
|
.object({
|
|
95
140
|
cursor: z.string().max(255).optional(),
|