fix payment service + appsumo + ui

This commit is contained in:
Emily
2025-04-22 18:42:18 +02:00
parent f631c29fb2
commit a9bbc58ad1
13 changed files with 121 additions and 65 deletions

View File

@@ -24,6 +24,8 @@ if (!TOKEN || TOKEN.length == 0) {
process.exit();
}
app.use('/webhook', webhookRouter);
app.use((req, res, next) => {
const token = req.header('x-litlyx-token');
if (token != TOKEN) {
@@ -34,8 +36,6 @@ app.use((req, res, next) => {
next();
});
app.use('/webhook', webhookRouter);
app.use('/payment', paymentRouter);
const port = parseInt(process.env.PORT);

View File

@@ -161,4 +161,30 @@ paymentRouter.post('/delete_customer', json(), async (req, res) => {
} catch (ex) {
res.status(500).json({ error: ex.message });
}
});
export const ZBodyCreateSubscription = z.object({
user_id: z.string(),
plan_tag: z.string()
});
paymentRouter.post('/create_subscription', json(), async (req, res) => {
try {
const createSubscriptionData = ZBodyCreateSubscription.parse(req.body);
const premiumData = await PremiumModel.findOne({ user_id: createSubscriptionData.user_id });
if (!premiumData) return sendJson(res, 400, { error: 'user not found' });
if (!premiumData.customer_id) return sendJson(res, 400, { error: 'user have no customer_id' });
await StripeService.createSubscription(
premiumData.customer_id,
createSubscriptionData.plan_tag
);
return sendJson(res, 200, { ok: true });
} catch (ex) {
console.error(ex);
res.status(500).json({ error: ex.message });
}
});

View File

@@ -153,22 +153,21 @@ class StripeService {
// return false;
// }
// async createSubscription(customer_id: string, planId: number) {
// if (this.disabledMode) return;
// if (!this.stripe) throw Error('Stripe not initialized');
async createSubscription(customer_id: string, planTag: string) {
if (!this.stripe) throw Error('Stripe not initialized');
// const PLAN = getPlanFromId(planId);
// if (!PLAN) throw Error('Plan not found');
const PLAN_DATA = getPlanFromTag(planTag as any);
if (!PLAN_DATA) throw Error('Plan not found');
// const subscription = await this.stripe.subscriptions.create({
// customer: customer_id,
// items: [
// { price: this.testMode ? PLAN.PRICE_TEST : PLAN.PRICE, quantity: 1 }
// ],
// });
const subscription = await this.stripe.subscriptions.create({
customer: customer_id,
items: [
{ price: this.testMode ? PLAN_DATA.PRICE_TEST : PLAN_DATA.PRICE, quantity: 1 }
],
});
// return subscription;
// }
return subscription;
}
// async createOneTimeSubscriptionDummy(customer_id: string, planId: number) {
// if (this.disabledMode) return;