Skip to content
Merged
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
1 change: 1 addition & 0 deletions api/spec/packages/aip/src/billing/index.tsp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./profile.tsp";
import "./tax.tsp";
import "./operations.tsp";
import "./totals.tsp";
66 changes: 66 additions & 0 deletions api/spec/packages/aip/src/billing/totals.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import "../shared/index.tsp";

namespace Billing;

/**
* Totals contains the summaries of all calculations for a billing resource.
*/
#suppress "@openmeter/api-spec-aip/repeated-prefix-grouping" "taxes_* totals are intentionally kept flat for API compatibility"
@friendlyName("BillingTotals")
model BillingTotals {
/**
* The total value of the resource before taxes, discounts and commitments.
*/
@visibility(Lifecycle.Read)
@summary("Amount")
amount: Shared.Numeric;

/**
* The total tax amount applied to the resource.
*/
@visibility(Lifecycle.Read)
@summary("Taxes total")
taxes_total: Shared.Numeric;

/**
* The total tax amount already included in the resource amount.
*/
@visibility(Lifecycle.Read)
@summary("Inclusive taxes total")
taxes_inclusive_total: Shared.Numeric;

/**
* The total tax amount added on top of the resource amount.
*/
@visibility(Lifecycle.Read)
@summary("Exclusive taxes total")
taxes_exclusive_total: Shared.Numeric;

/**
* The total amount contributed by additional charges.
*/
@visibility(Lifecycle.Read)
@summary("Charges total")
charges_total: Shared.Numeric;

/**
* The total amount deducted through discounts.
*/
@visibility(Lifecycle.Read)
@summary("Discounts total")
discounts_total: Shared.Numeric;

/**
* The total amount deducted through credits before taxes are applied.
*/
@visibility(Lifecycle.Read)
@summary("Credits total")
credits_total: Shared.Numeric;

/**
* The final total value of the resource after taxes, discounts and commitments.
*/
@visibility(Lifecycle.Read)
@summary("Total")
total: Shared.Numeric;
}
275 changes: 275 additions & 0 deletions api/spec/packages/aip/src/customers/charges/charges.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
import "../../shared/index.tsp";
import "../../productcatalog/index.tsp";
import "../../subscriptions/index.tsp";
import "../customer.tsp";

namespace Customers;

/**
* Type of a charge.
*
* Values:
* - `flat_fee`: A fixed-amount charge.
* - `usage_based`: A usage-priced charge.
*/
@friendlyName("BillingChargeType")
@summary("Charge type")
enum ChargeType {
FlatFee: "flat_fee",
UsageBased: "usage_based",
}

/**
* Lifecycle status of a charge.
Comment thread
turip marked this conversation as resolved.
*
* Values:
* - `created`: The charge has been created but is not active yet.
* - `active`: The charge is active.
* - `final`: The charge is fully finalized and no further changes are expected.
* - `deleted`: The charge has been deleted.
*/
@friendlyName("BillingChargeStatus")
@summary("Charge status")
enum ChargeStatus {
Created: "created",
Active: "active",
Final: "final",
Deleted: "deleted",
}

/**
* Shared fields present on all customer charge responses.
*/
#suppress "@openmeter/api-spec-aip/repeated-prefix-grouping" "charge temporal fields should remain flat"
@friendlyName("BillingChargeBase")
@summary("Charge")
model ChargeBase<T extends ChargeType> {
...Shared.Resource;

/**
* The type of the charge.
*/
@visibility(Lifecycle.Read)
@summary("Type")
type: T;

/**
* The customer owning the charge.
*/
@visibility(Lifecycle.Read)
@summary("Customer")
customer: CustomerReference;

/**
* The charge is managed by the following entity.
*/
@visibility(Lifecycle.Read)
@summary("Managed by")
managed_by: Shared.ResourceManagedBy;

/**
* The subscription that originated the charge, when the charge was created from a subscription item.
*/
@visibility(Lifecycle.Read)
@summary("Subscription")
subscription?: Subscriptions.SubscriptionReference;

/**
* The currency of the charge.
*/
@visibility(Lifecycle.Read)
@summary("Currency")
currency: Shared.CurrencyCode;

/**
* The lifecycle status of the charge.
*/
@visibility(Lifecycle.Read)
@summary("Status")
status: ChargeStatus;

/**
* The timestamp when the charge is intended to be invoiced.
*/
@visibility(Lifecycle.Read)
@summary("Invoice at")
invoice_at: Shared.DateTime;

/**
* The effective service period covered by the charge.
*/
@visibility(Lifecycle.Read)
@summary("Service period")
service_period: Shared.ClosedPeriod;

/**
* The full, unprorated service period of the charge.
*/
@visibility(Lifecycle.Read)
@summary("Full service period")
full_service_period: Shared.ClosedPeriod;

/**
* The billing period the charge belongs to.
*/
@visibility(Lifecycle.Read)
@summary("Billing period")
billing_period: Shared.ClosedPeriod;

/**
* The earliest time when the charge should be advanced again by background processing.
*/
@visibility(Lifecycle.Read)
@summary("Advance after")
advance_after?: Shared.DateTime;

/**
* The price of the charge.
*/
@visibility(Lifecycle.Read)
@summary("Price")
price: Shared.CurrencyAmount;

/**
* Unique reference ID of the charge.
*/
@visibility(Lifecycle.Read)
@summary("Unique reference ID")
unique_reference_id?: string;

/**
* Settlement mode of the charge.
*/
@visibility(Lifecycle.Read)
@summary("Settlement mode")
settlement_mode: ProductCatalog.SettlementMode;
}

/**
* A flat fee charge for a customer.
*/
@friendlyName("BillingFlatFeeCharge")
@summary("Flat fee charge")
model FlatFeeCharge {
...ChargeBase<ChargeType.FlatFee>;

/**
* Payment term of the flat fee charge.
*/
@visibility(Lifecycle.Read, Lifecycle.Create)
@summary("Payment term")
payment_term: ProductCatalog.PricePaymentTerm;

/**
* The discounts applied to the charge.
*/
@visibility(Lifecycle.Read, Lifecycle.Create)
@summary("Discounts")
discounts?: OmitProperties<ProductCatalog.Discounts, "usage">;

/**
* The feature associated with the charge, when applicable.
*/
@visibility(Lifecycle.Read, Lifecycle.Create)
@summary("Feature key")
feature_key?: string;

/**
* The proration configuration of the charge.
*/
@visibility(Lifecycle.Read, Lifecycle.Create)
@summary("Proration configuration")
proration_configuration: ProductCatalog.ProrationConfiguration;

// Calculated fields
/**
* The amount after proration of the charge.
*/
@visibility(Lifecycle.Read)
@summary("Amount after proration")
amount_after_proration: Shared.CurrencyAmount;
}

/**
* The totals of a change.
*
* RealTime is only expanded when the `real_time_usage` expand is used.
*/
@friendlyName("BillingChargeTotals")
model ChargeTotals {
Comment thread
turip marked this conversation as resolved.
/**
* The amount of the charge already booked to the internal accounting system.
*/
@visibility(Lifecycle.Read)
@summary("Booked")
booked: Billing.BillingTotals;

/**
* The realtime amount of the charge.
*
* Requires the `realtime_usage` expand.
Comment thread
turip marked this conversation as resolved.
*/
@visibility(Lifecycle.Read)
@summary("Realtime totals")
realtime?: Billing.BillingTotals;
}
Comment on lines +193 to +215
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Typo and expand name mismatch in ChargeTotals.

A couple small issues here:

  1. Line 194: "The totals of a change" should be "The totals of a charge"
  2. Line 210: The doc references realtime_usage but the ChargesExpand enum on line 274 defines it as real_time_usage (with an underscore between real and time)
Suggested fix
 /**
- * The totals of a change.
+ * The totals of a charge.
  *
  * RealTime is only expanded when the `real_time_usage` expand is used.
  */
 `@friendlyName`("BillingChargeTotals")
 model ChargeTotals {
   /**
    * The amount of the charge already booked to the internal accounting system.
    */
   `@visibility`(Lifecycle.Read)
   `@summary`("Booked")
   booked: Billing.BillingTotals;

   /**
    * The realtime amount of the charge.
    *
-   * Requires the `realtime_usage` expand.
+   * Requires the `real_time_usage` expand.
    */
   `@visibility`(Lifecycle.Read)
   `@summary`("Realtime totals")
   realtime?: Billing.BillingTotals;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* The totals of a change.
*
* RealTime is only expanded when the `real_time_usage` expand is used.
*/
@friendlyName("BillingChargeTotals")
model ChargeTotals {
/**
* The amount of the charge already booked to the internal accounting system.
*/
@visibility(Lifecycle.Read)
@summary("Booked")
booked: Billing.BillingTotals;
/**
* The realtime amount of the charge.
*
* Requires the `realtime_usage` expand.
*/
@visibility(Lifecycle.Read)
@summary("Realtime totals")
realtime?: Billing.BillingTotals;
}
/**
* The totals of a charge.
*
* RealTime is only expanded when the `real_time_usage` expand is used.
*/
`@friendlyName`("BillingChargeTotals")
model ChargeTotals {
/**
* The amount of the charge already booked to the internal accounting system.
*/
`@visibility`(Lifecycle.Read)
`@summary`("Booked")
booked: Billing.BillingTotals;
/**
* The realtime amount of the charge.
*
* Requires the `real_time_usage` expand.
*/
`@visibility`(Lifecycle.Read)
`@summary`("Realtime totals")
realtime?: Billing.BillingTotals;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/spec/packages/aip/src/customers/charges/charges.tsp` around lines 193 -
215, Fix the two doc issues in the ChargeTotals model: correct the typo in the
top comment from "change" to "charge" and update the expand reference from
`realtime_usage` to match the enum name `real_time_usage` (as defined in the
ChargesExpand enum) so the doc and enum stay consistent; locate the model
`ChargeTotals` and update its comment text and the `realtime` field's doc string
accordingly.


/**
* A usage-based charge for a customer.
*/
@friendlyName("BillingUsageBasedCharge")
@summary("Usage-based charge")
model UsageBasedCharge {
...ChargeBase<ChargeType.UsageBased>;

/**
* Discounts applied to the usage-based charge.
*/
@visibility(Lifecycle.Read, Lifecycle.Create)
@summary("Discounts")
discounts?: ProductCatalog.Discounts;

/**
* The feature associated with the charge.
*/
@visibility(Lifecycle.Read, Lifecycle.Create)
@summary("Feature key")
feature_key: string;

// Status fields

/** Aggregated booked and realtime totals for the charge. */
@visibility(Lifecycle.Read)
@summary("Totals for the charge")
totals: ChargeTotals;
}

/**
* Customer charge.
*/
@friendlyName("BillingCharge")
@summary("Customer charge")
@discriminated(#{ envelope: "none", discriminatorPropertyName: "type" })
union Charge {
/**
* A flat fee charge.
*/
flat_fee: FlatFeeCharge,

/**
* A usage-based charge.
*/
usage_based: UsageBasedCharge,
}

/**
* Expands for customer charges.
*
* Values:
* - `real_time_usage`: The charge's real-time usage.
*/
@friendlyName("BillingChargesExpand")
@summary("Customer charge expands")
enum ChargesExpand {
RealTimeUsage: "real_time_usage",
}
2 changes: 2 additions & 0 deletions api/spec/packages/aip/src/customers/charges/index.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import "./charges.tsp";
import "./operations.tsp";
Loading
Loading