feat: Onboard accounts to Stripe Connect

This commit is contained in:
Ahmed Bouhuolia
2024-09-08 11:42:26 +02:00
parent 6d24474162
commit a183666df6
14 changed files with 360 additions and 3 deletions

View File

@@ -0,0 +1,46 @@
import { NextFunction, Request, Response, Router } from 'express';
import { Service, Inject } from 'typedi';
import { StripePaymentService } from '@/services/StripePayment/StripePaymentService';
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
@Service()
export class StripeIntegrationController {
@Inject()
private stripePaymentService: StripePaymentService;
router() {
const router = Router();
router.post('/account', asyncMiddleware(this.createAccount.bind(this)));
router.post(
'/account_session',
asyncMiddleware(this.createAccountSession.bind(this))
);
return router;
}
public async createAccount(req: Request, res: Response, next: NextFunction) {
try {
const accountId = await this.stripePaymentService.createAccount();
res.status(201).json({ accountId });
} catch (error) {
next(error);
}
}
public async createAccountSession(
req: Request,
res: Response,
next: NextFunction
) {
const { account } = req.body;
try {
const clientSecret = await this.stripePaymentService.createAccountSession(
account
);
res.status(200).json({ clientSecret });
} catch (error) {
next(error);
}
}
}