Skip to content

Commit 3e00e15

Browse files
committed
feat: hold money
1 parent 5acdd88 commit 3e00e15

File tree

13 files changed

+295
-90
lines changed

13 files changed

+295
-90
lines changed

apps/backend/src/api/routes/billing.controller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ export class BillingController {
2424
@Param('id') body: string
2525
) {
2626
return {
27-
exists: !!(await this._subscriptionService.checkSubscription(
27+
status: await this._stripeService.checkSubscription(
2828
org.id,
2929
body
30-
)),
30+
),
3131
};
3232
}
3333

@@ -39,7 +39,7 @@ export class BillingController {
3939
@Req() req: Request
4040
) {
4141
const uniqueId = req?.cookies?.track;
42-
return this._stripeService.subscribe(uniqueId, org.id, user.id, body);
42+
return this._stripeService.subscribe(uniqueId, org.id, user.id, body, org.allowTrial);
4343
}
4444

4545
@Get('/portal')

apps/backend/src/api/routes/users.controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export class UsersController {
6868
isLifetime: !!organization?.subscription?.isLifetime,
6969
admin: !!user.isSuperAdmin,
7070
impersonate: !!req.cookies.impersonate,
71+
allowTrial: organization?.allowTrial,
7172
// @ts-ignore
7273
publicApi: organization?.users[0]?.role === 'SUPERADMIN' || organization?.users[0]?.role === 'ADMIN'
7374
? organization?.apiKey

apps/frontend/src/components/billing/main.billing.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ export const MainBillingComponent: FC<{
481481
.format('D MMM, YYYY')}`
482482
: 'Cancel subscription'
483483
: // @ts-ignore
484-
user?.tier === 'FREE' || user?.tier?.current === 'FREE'
484+
(user?.tier === 'FREE' || user?.tier?.current === 'FREE') && user.allowTrial
485485
? 'Start 7 days free trial'
486486
: 'Purchase'}
487487
</Button>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { FC, useCallback, useEffect, useState } from 'react';
2+
import Loading from 'react-loading';
3+
import { useFetch } from '@gitroom/helpers/utils/custom.fetch';
4+
import { timer } from '@gitroom/helpers/utils/timer';
5+
import { useToaster } from '@gitroom/react/toaster/toaster';
6+
7+
export const CheckPayment: FC<{ check: string; mutate: () => void }> = (props) => {
8+
const [showLoader, setShowLoader] = useState(true);
9+
const fetch = useFetch();
10+
const toaster = useToaster();
11+
12+
const checkSubscription = useCallback(async () => {
13+
const {status} = await (await fetch('/billing/check/' + props.check)).json();
14+
if (status === 0) {
15+
await timer(1000);
16+
return checkSubscription();
17+
}
18+
19+
if (status === 1) {
20+
toaster.show(
21+
'We could not validate your payment method, please try again',
22+
'warning'
23+
);
24+
setShowLoader(false);
25+
}
26+
27+
if (status === 2) {
28+
setShowLoader(false);
29+
props.mutate();
30+
}
31+
}, []);
32+
33+
useEffect(() => {
34+
checkSubscription();
35+
}, []);
36+
37+
if (showLoader) {
38+
return (
39+
<div className="fixed bg-black/40 w-full h-full flex justify-center items-center z-[400]">
40+
<div>
41+
<Loading type="spin" color="#612AD5" height={250} width={250} />
42+
</div>
43+
</div>
44+
);
45+
}
46+
47+
return null;
48+
};

apps/frontend/src/components/layout/layout.settings.tsx

Lines changed: 67 additions & 53 deletions
Large diffs are not rendered by default.

apps/frontend/src/components/layout/user.context.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const UserContext = createContext<
1717
totalChannels: number;
1818
isLifetime?: boolean;
1919
impersonate: boolean;
20+
allowTrial: boolean;
2021
})
2122
>(undefined);
2223

apps/frontend/tailwind.config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ module.exports = {
131131
'100%': { overflow: 'hidden' },
132132
},
133133
fadeDown: {
134-
'0%': { opacity: 0, transform: 'translateY(-30px)' },
135-
'10%': { opacity: 1, transform: 'translateY(0)' },
136-
'85%': { opacity: 1, transform: 'translateY(0)' },
137-
'90%': { opacity: 1, transform: 'translateY(10px)' },
138-
'100%': { opacity: 0, transform: 'translateY(-30px)' },
134+
'0%': { opacity: 0, marginTop: -30},
135+
'10%': { opacity: 1, marginTop: 0 },
136+
'85%': { opacity: 1, marginTop: 0 },
137+
'90%': { opacity: 1, marginTop: 10 },
138+
'100%': { opacity: 0, marginTop: -30 },
139139
},
140140
normalFadeDown: {
141141
'0%': { opacity: 0, transform: 'translateY(-30px)' },

libraries/nestjs-libraries/src/database/prisma/organizations/organization.repository.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ export class OrganizationRepository {
215215
data: {
216216
name: body.company,
217217
apiKey: AuthService.fixedEncryption(makeId(20)),
218+
allowTrial: true,
218219
users: {
219220
create: {
220221
role: Role.SUPERADMIN,
@@ -246,6 +247,14 @@ export class OrganizationRepository {
246247
});
247248
}
248249

250+
getOrgByCustomerId(customerId: string) {
251+
return this._organization.model.organization.findFirst({
252+
where: {
253+
paymentId: customerId,
254+
},
255+
});
256+
}
257+
249258
async getTeam(orgId: string) {
250259
return this._organization.model.organization.findUnique({
251260
where: {

libraries/nestjs-libraries/src/database/prisma/organizations/organization.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ export class OrganizationService {
6060
return this._organizationRepository.getTeam(orgId);
6161
}
6262

63+
getOrgByCustomerId(customerId: string) {
64+
return this._organizationRepository.getOrgByCustomerId(customerId);
65+
}
66+
6367
async inviteTeamMember(orgId: string, body: AddTeamMemberDto) {
6468
const timeLimit = dayjs().add(1, 'hour').format('YYYY-MM-DD HH:mm:ss');
6569
const id = makeId(5);

libraries/nestjs-libraries/src/database/prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ model Organization {
2525
Integration Integration[]
2626
post Post[] @relation("organization")
2727
submittedPost Post[] @relation("submittedForOrg")
28+
allowTrial Boolean @default(false)
2829
Comments Comments[]
2930
notifications Notifications[]
3031
buyerOrganization MessagesGroup[]

0 commit comments

Comments
 (0)