Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions api/spec/src/productcatalog/commitments.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import "../types.tsp";

namespace OpenMeter.ProductCatalog;

/**
* The type of the commitment.
*/
@friendlyName("CommitmentType")
enum CommitmentType {
spend: "spend",
// usage: "usage",
}

/**
* A commitment on a plan phase.
* One of: spend.
*/
@discriminator("type")
@friendlyName("Commitment")
union Commitment {
@summary("Spend commitment")
spend: CommitmentSpend,

// @summary("Usage commitment")
// usage: CommitmentUsage,
}

/**
* Spend commitment.
*/
@friendlyName("CommitmentSpend")
model CommitmentSpend {
/**
* The type of the commitment.
*/
@visibility(Lifecycle.Read, Lifecycle.Create)
@summary("Type")
type: CommitmentType.spend;

/**
* The customer is committed to spend at least the amount.
*/
@visibility(Lifecycle.Read, Lifecycle.Create)
@summary("Minimum amount")
minimumAmount?: Money;

/**
* The customer is limited to spend at most the amount.
*/
@visibility(Lifecycle.Read, Lifecycle.Create)
@summary("Maximum amount")
maximumAmount?: Money;

/**
* The rate cards that the commitment applies to.
* When not specified, the commitment applies to all rate cards.
*/
@visibility(Lifecycle.Read, Lifecycle.Create)
@summary("Committed RateCards")
rateCards?: Key[];
}
2 changes: 1 addition & 1 deletion api/spec/src/productcatalog/discounts.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum DiscountType {
}

/**
* A discount on a price.
* A discount on a plan phase.
* One of: percentage, amount, or usage.
*/
@discriminator("type")
Expand Down
12 changes: 10 additions & 2 deletions api/spec/src/productcatalog/plan.tsp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "@typespec/http";
import "../types.tsp";
import "./ratecards.tsp";
import "./commitments.tsp";

namespace OpenMeter.ProductCatalog;

Expand Down Expand Up @@ -156,19 +157,26 @@ model PlanPhase {
duration: duration | null;

/**
* The rate cards of the plan.
* The rate cards of the phase.
*/
@visibility(Lifecycle.Read, Lifecycle.Create, Lifecycle.Update)
@summary("Rate cards")
rateCards: RateCard[];

/**
* The discounts on the plan.
* The discounts on the phase.
*/
@visibility(Lifecycle.Read, Lifecycle.Create, Lifecycle.Update)
@summary("Discounts")
discounts?: Discount[];

/**
* The commitments on the phase.
*/
@visibility(Lifecycle.Read, Lifecycle.Create, Lifecycle.Update)
@summary("Commitments")
commitments?: Commitment[];

// /**
// * Predefined overrides of the plan that can apply changes to the rate cards, discounts, and other properties based on the selected variant.
// */
Expand Down
58 changes: 20 additions & 38 deletions api/spec/src/productcatalog/prices.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -160,41 +160,23 @@ model PriceTier {
unitPrice: UnitPrice | null;
}

/**
* Spending commitments.
* The customer is committed to spend at least the minimum amount and at most the maximum amount.
*/
@friendlyName("SpendCommitments")
model SpendCommitments {
/**
* The customer is committed to spend at least the amount.
*/
@visibility(Lifecycle.Read, Lifecycle.Create, Lifecycle.Update)
@summary("Minimum amount")
minimumAmount?: Money;

/**
* The customer is limited to spend at most the amount.
*/
@visibility(Lifecycle.Read, Lifecycle.Create, Lifecycle.Update)
@summary("Maximum amount")
maximumAmount?: Money;
}

/**
* Unit price with spend commitments.
*/
@friendlyName("UnitPriceWithCommitments")
model UnitPriceWithCommitments {
...UnitPrice;
...SpendCommitments;
}

/**
* Tiered price with spend commitments.
*/
@friendlyName("TieredPriceWithCommitments")
model TieredPriceWithCommitments {
...TieredPrice;
...SpendCommitments;
}
// /**
// * Spending commitments.
// * The customer is committed to spend at least the minimum amount and at most the maximum amount.
// */
// @friendlyName("SpendCommitments")
// model SpendCommitments {
// /**
// * The customer is committed to spend at least the amount.
// */
// @visibility(Lifecycle.Read, Lifecycle.Create, Lifecycle.Update)
// @summary("Minimum amount")
// minimumAmount?: Money;

// /**
// * The customer is limited to spend at most the amount.
// */
// @visibility(Lifecycle.Read, Lifecycle.Create, Lifecycle.Update)
// @summary("Maximum amount")
// maximumAmount?: Money;
// }
37 changes: 2 additions & 35 deletions api/spec/src/productcatalog/ratecards.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ model RateCardFlatFee {
@oneOf
union RateCardUsageBasedPrice {
flat: FlatPriceWithPaymentTerm,
unit: UnitPriceWithCommitments,
tiered: TieredPriceWithCommitments,
unit: UnitPrice,
tiered: TieredPrice,
}

/**
Expand All @@ -153,39 +153,6 @@ model RateCardUsageBased {
*/
@visibility(Lifecycle.Read, Lifecycle.Create, Lifecycle.Update)
price: RateCardUsageBasedPrice | null;

// NOTE(chrisgacsal): discount on RateCard level going to be implemented in upcoming releases
// /**
// * The discount of the rate card.
// */
// @summary("Discount")
// discount?: Discount;
}

/**
* Rate card override.
*/
@friendlyName("RateCardOverride")
@discriminator("type")
union RateCardOverride {
flatFee: RateCardOverrideFlatFee,
usageBased: RateCardOverrideUsageBased,
}

/**
* Flat fee rate card override.
*/
@friendlyName("RateCardOverrideFlatFee")
model RateCardOverrideFlatFee {
...PickProperties<RateCardFlatFee, "type" | "price">;
}

/**
* Usage-based rate card override.
*/
@friendlyName("RateCardOverrideUsageBased")
model RateCardOverrideUsageBased {
...PickProperties<RateCardUsageBased, "type" | "price">;
}

/**
Expand Down
13 changes: 10 additions & 3 deletions api/spec/src/productcatalog/subscription.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "../errors.tsp";
import "./prices.tsp";
import "./ratecards.tsp";
import "./discounts.tsp";
import "./commitments.tsp";
import "../entitlements/main.tsp";

using TypeSpec.Http;
Expand Down Expand Up @@ -127,11 +128,17 @@ model SubscriptionPhaseCreate {
duration?: duration;

/**
* The discounts on the plan.
* The discounts on the phase.
*/
@summary("Discounts")
discounts?: Discount[];

/**
* The commitments on the phase.
*/
@summary("Commitments")
commitments?: Commitment[];

/**
* A locally unique identifier for the phase.
*/
Expand Down Expand Up @@ -186,8 +193,8 @@ model SubscriptionItem {
@example(#{ type: PriceType.flat, amount: "100", paymentTerm: "in_arrears" })
price:
| FlatPriceWithPaymentTerm
| UnitPriceWithCommitments
| TieredPriceWithCommitments
| UnitPrice
| TieredPrice
| null;

/**
Expand Down
Loading