mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
fix metered plan
This commit is contained in:
@@ -1,17 +1,14 @@
|
||||
export default class MeteredPlan {
|
||||
private monthlyPriceId: string;
|
||||
private yearlyPriceId: string;
|
||||
private unitName: string;
|
||||
private pricePerUnit: number;
|
||||
|
||||
public constructor(
|
||||
monthlyPriceId: string,
|
||||
yearlyPriceId: string,
|
||||
pricePerUnit: number,
|
||||
unitName: string
|
||||
) {
|
||||
this.monthlyPriceId = monthlyPriceId;
|
||||
this.yearlyPriceId = yearlyPriceId;
|
||||
|
||||
this.pricePerUnit = pricePerUnit;
|
||||
this.unitName = unitName;
|
||||
@@ -21,9 +18,6 @@ export default class MeteredPlan {
|
||||
return this.monthlyPriceId;
|
||||
}
|
||||
|
||||
public getYearlyPriceId(): string {
|
||||
return this.yearlyPriceId;
|
||||
}
|
||||
|
||||
public getPricePerUnit(): number {
|
||||
return this.pricePerUnit;
|
||||
|
||||
@@ -96,6 +96,7 @@ export class BillingService extends BaseService {
|
||||
promoCode?: string | undefined;
|
||||
}): Promise<{
|
||||
id: string;
|
||||
meteredSubscriptionId: string;
|
||||
trialEndsAt: Date | null;
|
||||
}> {
|
||||
if (!this.isBillingEnabled()) {
|
||||
@@ -146,6 +147,10 @@ export class BillingService extends BaseService {
|
||||
const subscription: Stripe.Response<Stripe.Subscription> =
|
||||
await this.stripe.subscriptions.create(subscriptionParams);
|
||||
|
||||
// Create metered subscriptions
|
||||
const meteredSubscription: Stripe.Response<Stripe.Subscription> =
|
||||
await this.stripe.subscriptions.create(subscriptionParams);
|
||||
|
||||
for (const serverMeteredPlan of data.serverMeteredPlans) {
|
||||
await serverMeteredPlan.updateCurrentQuantity(data.projectId, {
|
||||
subscriptionId: subscription.id,
|
||||
@@ -221,9 +226,7 @@ export class BillingService extends BaseService {
|
||||
(item: Stripe.SubscriptionItem) => {
|
||||
return (
|
||||
item.price?.id ===
|
||||
(isYearly
|
||||
? meteredPlan.getYearlyPriceId()
|
||||
: meteredPlan.getMonthlyPriceId())
|
||||
meteredPlan.getMonthlyPriceId()
|
||||
);
|
||||
}
|
||||
);
|
||||
@@ -235,9 +238,7 @@ export class BillingService extends BaseService {
|
||||
(item: Stripe.SubscriptionItem) => {
|
||||
return (
|
||||
item.price?.id ===
|
||||
(isYearly
|
||||
? meteredPlan.getYearlyPriceId()
|
||||
: meteredPlan.getMonthlyPriceId())
|
||||
meteredPlan.getMonthlyPriceId()
|
||||
);
|
||||
}
|
||||
)?.id;
|
||||
@@ -258,9 +259,7 @@ export class BillingService extends BaseService {
|
||||
const subscriptionItem: Stripe.SubscriptionItem =
|
||||
await this.stripe.subscriptionItems.create({
|
||||
subscription: subscriptionId,
|
||||
price: isYearly
|
||||
? meteredPlan.getYearlyPriceId()
|
||||
: meteredPlan.getMonthlyPriceId(),
|
||||
price: meteredPlan.getMonthlyPriceId()
|
||||
});
|
||||
|
||||
// use stripe usage based api to update the quantity.
|
||||
|
||||
@@ -158,6 +158,28 @@ export default class Model extends TenantModel {
|
||||
})
|
||||
public paymentProviderSubscriptionId?: string = undefined;
|
||||
|
||||
|
||||
@ColumnAccessControl({
|
||||
create: [],
|
||||
read: [
|
||||
Permission.ProjectOwner,
|
||||
Permission.ProjectAdmin,
|
||||
Permission.ProjectMember,
|
||||
Permission.CanReadProject,
|
||||
Permission.UnAuthorizedSsoUser,
|
||||
Permission.ProjectUser,
|
||||
],
|
||||
update: [],
|
||||
})
|
||||
@TableColumn({ type: TableColumnType.ShortText })
|
||||
@Column({
|
||||
type: ColumnType.ShortText,
|
||||
length: ColumnLength.ShortText,
|
||||
nullable: true,
|
||||
unique: false,
|
||||
})
|
||||
public paymentProviderMeteredSubscriptionId?: string = undefined;
|
||||
|
||||
@ColumnAccessControl({
|
||||
create: [],
|
||||
read: [
|
||||
|
||||
@@ -189,7 +189,7 @@ GLOBAL_PROBE_2_DESCRIPTION="Global probe to monitor oneuptime resources"
|
||||
SENDGRID_API_KEY=
|
||||
|
||||
# METERED PLANS: This is in the format of MONTHLY_PRICE_ID,YEARLY_PRICE_ID,value per unit,unitName
|
||||
METERED_PLAN_ACTIVE_MONITORING=priceMonthlyId,priceYearlyId,1,active-monitor,month
|
||||
METERED_PLAN_ACTIVE_MONITORING=priceMonthlyId,1,active-monitor,month
|
||||
|
||||
|
||||
# Twilio Settings
|
||||
|
||||
Reference in New Issue
Block a user