mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
adding support for appsumo codes
This commit is contained in:
13
dashboard/server/services/AppsumoService.ts
Normal file
13
dashboard/server/services/AppsumoService.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
|
||||
import { AppsumoCodeModel } from '@schema/AppsumoCode'
|
||||
|
||||
export async function checkAppsumoCode(code: string) {
|
||||
const target = await AppsumoCodeModel.exists({ code, used_at: { $exists: false } });
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
export async function useAppsumoCode(code: string) {
|
||||
await AppsumoCodeModel.updateOne({ code }, { used_at: Date.now() });
|
||||
}
|
||||
@@ -168,6 +168,23 @@ class StripeService {
|
||||
return false;
|
||||
}
|
||||
|
||||
async createSubscription(customer_id: string, planId: number) {
|
||||
if (this.disabledMode) return;
|
||||
if (!this.stripe) throw Error('Stripe not initialized');
|
||||
|
||||
const PLAN = getPlanFromId(planId);
|
||||
if (!PLAN) 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 }
|
||||
],
|
||||
});
|
||||
|
||||
return subscription;
|
||||
}
|
||||
|
||||
async createOneTimeSubscriptionDummy(customer_id: string, planId: number) {
|
||||
if (this.disabledMode) return;
|
||||
if (!this.stripe) throw Error('Stripe not initialized');
|
||||
|
||||
Reference in New Issue
Block a user