-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaymentUtilsServer.ts
94 lines (89 loc) · 2.48 KB
/
paymentUtilsServer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
'use server';
import { PAYMENT_PROVIDER } from '@/constants';
import type { SAPayload } from '@/types';
import {
createCheckoutSessionAction,
getMRRStripe,
getSubscriptionsListStripe,
manageSubsciptionStripe,
startTrialStripe,
} from './stripe/stripeServerUtils';
export const getMRR = (startOfMonth: Date, endOfMonth: Date) => {
switch (PAYMENT_PROVIDER) {
case 'stripe':
return getMRRStripe(startOfMonth, endOfMonth);
case 'lemonsqueezy':
throw Error('under development');
default:
return getMRRStripe(startOfMonth, endOfMonth);
}
};
export const getSubscriptions = async (
startOfMonth: Date,
endOfMonth: Date,
) => {
switch (PAYMENT_PROVIDER) {
case 'stripe':
return getSubscriptionsListStripe(startOfMonth, endOfMonth);
case 'lemonsqueezy':
throw Error('under development');
default:
return getSubscriptionsListStripe(startOfMonth, endOfMonth);
}
};
export const createSubscription = async (
organizationId: string,
priceId: string,
): Promise<SAPayload<string>> => {
switch (PAYMENT_PROVIDER) {
case 'stripe': {
const data = await createCheckoutSessionAction({
organizationId,
priceId,
});
return { status: 'success', data };
}
case 'lemonsqueezy':
return { status: 'error', message: 'under development' };
default: {
const data = await createCheckoutSessionAction({
organizationId,
priceId,
});
return { status: 'success', data };
}
}
};
export const startTrial = async (
organizationId: string,
priceId: string,
): Promise<SAPayload<string>> => {
switch (PAYMENT_PROVIDER) {
case 'stripe': {
const data = await startTrialStripe(organizationId, priceId);
return { status: 'success', data };
}
case 'lemonsqueezy':
return { status: 'error', message: 'under development' };
default: {
const data = await startTrialStripe(organizationId, priceId);
return { status: 'success', data };
}
}
};
export const manageSubscription = async (
organizationId: string,
): Promise<SAPayload<string>> => {
switch (PAYMENT_PROVIDER) {
case 'stripe': {
const data = await manageSubsciptionStripe(organizationId);
return { status: 'success', data };
}
case 'lemonsqueezy':
return { status: 'error', message: 'under development' };
default: {
const data = await manageSubsciptionStripe(organizationId);
return { status: 'success', data };
}
}
};