Added add/remove/get organization payment methods and get cloud plans from license server

This commit is contained in:
Tuan Dang
2023-05-23 22:28:41 +03:00
parent 899d46514c
commit 83dd35299c
8 changed files with 182 additions and 50 deletions
-39
View File
@@ -1,39 +0,0 @@
import { Types } from 'mongoose';
import * as Sentry from '@sentry/node';
import { Organization } from '../../models';
import { EELicenseService } from '../services';
import { getLicenseServerUrl } from '../../config';
import { licenseServerKeyRequest } from '../../config/request';
import { OrganizationNotFoundError } from '../../utils/errors';
export const getOrganizationPlanHelper = async ({
organizationId
}: {
organizationId: Types.ObjectId;
}) => {
try {
if (EELicenseService.instanceType === 'cloud') {
// instance of Infisical is a cloud instance
const organization = await Organization.findById(organizationId);
if (!organization) throw OrganizationNotFoundError();
const cachedPlan = EELicenseService.localFeatureSet.get(organizationId.toString());
if (cachedPlan) return cachedPlan;
const { data: { currentPlan } } = await licenseServerKeyRequest.get(
`${await getLicenseServerUrl()}/api/license-server/v1/customers/${organization.customerId}/cloud-plan`
);
// cache fetched plan for organization
EELicenseService.localFeatureSet.set(organizationId.toString(), currentPlan);
return currentPlan;
}
return EELicenseService.globalFeatureSet;
} catch (err) {
Sentry.setUser(null);
Sentry.captureException(err);
return EELicenseService.globalFeatureSet;
}
}