mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-13 19:30:30 +00:00
feat: Stripe connect using OAuth
This commit is contained in:
@@ -13,6 +13,13 @@ export class StripeIntegrationController extends BaseController {
|
||||
public router() {
|
||||
const router = Router();
|
||||
|
||||
router.get('/link', this.getStripeConnectLink.bind(this));
|
||||
router.post(
|
||||
'/callback',
|
||||
[body('code').exists()],
|
||||
this.validationResult,
|
||||
this.exchangeOAuth.bind(this)
|
||||
);
|
||||
router.post('/account', asyncMiddleware(this.createAccount.bind(this)));
|
||||
router.post(
|
||||
'/account_link',
|
||||
@@ -27,6 +34,47 @@ export class StripeIntegrationController extends BaseController {
|
||||
return router;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves Stripe OAuth2 connect link.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
* @returns {Promise<Response|void>}
|
||||
*/
|
||||
public async getStripeConnectLink(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) {
|
||||
try {
|
||||
const authorizationUri = this.stripePaymentApp.getStripeConnectLink();
|
||||
|
||||
return res.status(200).send({ url: authorizationUri });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exchanges the given Stripe authorization code to Stripe user id and access token.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public async exchangeOAuth(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
const { code } = this.matchedBodyData(req);
|
||||
|
||||
try {
|
||||
await this.stripePaymentApp.exchangeStripeOAuthToken(tenantId, code);
|
||||
|
||||
return res.status(200).send({});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Stripe checkout session for the given payment link id.
|
||||
* @param {Request} req
|
||||
|
||||
Reference in New Issue
Block a user