mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat(server): api endpoint to get Plaid link token
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { PlaidLinkTokenService } from './PlaidLinkToken';
|
||||
|
||||
@Service()
|
||||
export class PlaidApplication {
|
||||
@Inject()
|
||||
private getLinkTokenService: PlaidLinkTokenService;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param tenantId
|
||||
* @param itemId
|
||||
* @returns
|
||||
*/
|
||||
public getLinkToken(tenantId: number) {
|
||||
return this.getLinkTokenService.getLinkToken(tenantId);
|
||||
}
|
||||
}
|
||||
37
packages/server/src/services/Banking/Plaid/PlaidLinkToken.ts
Normal file
37
packages/server/src/services/Banking/Plaid/PlaidLinkToken.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { PlaidClientWrapper } from '@/lib/Plaid';
|
||||
import { Service } from 'typedi';
|
||||
|
||||
@Service()
|
||||
export class PlaidLinkTokenService {
|
||||
/**
|
||||
* Retrieves the plaid link token.
|
||||
* @param {number} tenantId
|
||||
* @returns
|
||||
*/
|
||||
async getLinkToken(tenantId: number) {
|
||||
const accessToken = null;
|
||||
|
||||
// must include transactions in order to receive transactions webhooks
|
||||
const products = ['transactions'];
|
||||
const linkTokenParams = {
|
||||
user: {
|
||||
// This should correspond to a unique id for the current user.
|
||||
client_user_id: 'uniqueId' + tenantId,
|
||||
},
|
||||
client_name: 'Pattern',
|
||||
products,
|
||||
country_codes: ['US'],
|
||||
language: 'en',
|
||||
// webhook: httpTunnel.public_url + '/services/webhook',
|
||||
access_token: accessToken,
|
||||
};
|
||||
// If user has entered a redirect uri in the .env file
|
||||
// if (redirect_uri.indexOf('http') === 0) {
|
||||
// linkTokenParams.redirect_uri = redirect_uri;
|
||||
// }
|
||||
const plaidInstance = new PlaidClientWrapper();
|
||||
const createResponse = await plaidInstance.linkTokenCreate(linkTokenParams);
|
||||
|
||||
return createResponse.data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user