mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
feat: Onboard accounts to Stripe Connect
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,7 @@ import { Webhooks } from './controllers/Webhooks/Webhooks';
|
||||
import { ExportController } from './controllers/Export/ExportController';
|
||||
import { AttachmentsController } from './controllers/Attachments/AttachmentsController';
|
||||
import { OneClickDemoController } from './controllers/OneClickDemo/OneClickDemoController';
|
||||
import { StripeIntegrationController } from './controllers/StripeIntegration/StripeIntegrationController';
|
||||
|
||||
export default () => {
|
||||
const app = Router();
|
||||
@@ -147,6 +148,7 @@ export default () => {
|
||||
dashboard.use('/import', Container.get(ImportController).router());
|
||||
dashboard.use('/export', Container.get(ExportController).router());
|
||||
dashboard.use('/attachments', Container.get(AttachmentsController).router());
|
||||
dashboard.use('/stripe_integration', Container.get(StripeIntegrationController).router());
|
||||
|
||||
dashboard.use('/', Container.get(ProjectTasksController).router());
|
||||
dashboard.use('/', Container.get(ProjectTimesController).router());
|
||||
|
||||
Reference in New Issue
Block a user