feat(server): listen to Plaid webhooks

This commit is contained in:
Ahmed Bouhuolia
2024-02-14 17:11:07 +02:00
parent 706a324121
commit 1fd8a53ed1
8 changed files with 71 additions and 51 deletions

View File

@@ -16,7 +16,6 @@ export class PlaidBankingController extends BaseController {
router.post('/link-token', this.linkToken.bind(this));
router.post('/exchange-token', this.exchangeToken.bind(this));
router.post('/webhooks', this.webhooks.bind(this));
return router;
}
@@ -36,7 +35,7 @@ export class PlaidBankingController extends BaseController {
}
/**
*
* Exchanges the given public token.
* @param {Request} req
* @param {response} res
* @returns {Response}
@@ -51,21 +50,4 @@ export class PlaidBankingController extends BaseController {
});
return res.status(200).send({});
}
public async webhooks(req: Request, res: Response) {
const { tenantId } = req;
const {
webhook_type: webhookType,
webhook_code: webhookCode,
item_id: plaidItemId,
} = req.body;
await this.plaidApp.webhooks(
tenantId,
webhookType,
plaidItemId,
webhookCode
);
return res.status(200).send({ code: 200, message: 'ok' });
}
}

View File

@@ -0,0 +1,47 @@
import { Router } from 'express';
import { PlaidApplication } from '@/services/Banking/Plaid/PlaidApplication';
import { Request, Response } from 'express';
import { Inject, Service } from 'typedi';
import BaseController from '../BaseController';
@Service()
export class Webhooks extends BaseController {
@Inject()
private plaidApp: PlaidApplication;
/**
* Router constructor.
*/
router() {
const router = Router();
router.post('/plaid', this.plaidWebhooks.bind(this));
return router;
}
/**
* Listens to Plaid webhooks.
* @param {Request} req
* @param {Response} res
* @returns {Response}
*/
public async plaidWebhooks(req: Request, res: Response) {
const { tenantId } = req;
const {
webhook_type: webhookType,
webhook_code: webhookCode,
item_id: plaidItemId,
} = req.body;
console.log(req.body, 'triggered');
await this.plaidApp.webhooks(
tenantId,
plaidItemId,
webhookType,
webhookCode
);
return res.status(200).send({ code: 200, message: 'ok' });
}
}