|
| 1 | +import "../../shared/index.tsp"; |
| 2 | +import "../../productcatalog/index.tsp"; |
| 3 | +import "../../subscriptions/index.tsp"; |
| 4 | +import "../customer.tsp"; |
| 5 | + |
| 6 | +namespace Customers; |
| 7 | + |
| 8 | +/** |
| 9 | + * Type of a charge. |
| 10 | + */ |
| 11 | +@friendlyName("BillingChargeType") |
| 12 | +@summary("Charge type") |
| 13 | +enum ChargeType { |
| 14 | + /** |
| 15 | + * A fixed-amount charge. |
| 16 | + */ |
| 17 | + FlatFee: "flat_fee", |
| 18 | + |
| 19 | + /** |
| 20 | + * A usage-priced charge. |
| 21 | + */ |
| 22 | + UsageBased: "usage_based", |
| 23 | +} |
| 24 | + |
| 25 | +/** |
| 26 | + * Lifecycle status of a charge. |
| 27 | + */ |
| 28 | +@friendlyName("BillingChargeStatus") |
| 29 | +@summary("Charge status") |
| 30 | +enum ChargeStatus { |
| 31 | + /** |
| 32 | + * The charge has been created but is not active yet. |
| 33 | + */ |
| 34 | + Created: "created", |
| 35 | + |
| 36 | + /** |
| 37 | + * The charge is active. |
| 38 | + */ |
| 39 | + Active: "active", |
| 40 | + |
| 41 | + /** |
| 42 | + * The charge is settled for the service period, but late events may still arrive. |
| 43 | + */ |
| 44 | + Settled: "settled", |
| 45 | + |
| 46 | + /** |
| 47 | + * The charge is fully finalized and no further changes are expected. |
| 48 | + */ |
| 49 | + Final: "final", |
| 50 | + |
| 51 | + /** |
| 52 | + * The charge has been deleted. |
| 53 | + */ |
| 54 | + Deleted: "deleted", |
| 55 | +} |
| 56 | + |
| 57 | +/** |
| 58 | + * Shared fields present on all customer charge responses. |
| 59 | + */ |
| 60 | +#suppress "@openmeter/api-spec-aip/repeated-prefix-grouping" "charge temporal fields should remain flat" |
| 61 | +@friendlyName("BillingChargeBase") |
| 62 | +@summary("Charge") |
| 63 | +model ChargeBase<T extends ChargeType> { |
| 64 | + ...Shared.Resource; |
| 65 | + |
| 66 | + /** |
| 67 | + * The type of the charge. |
| 68 | + */ |
| 69 | + @visibility(Lifecycle.Read) |
| 70 | + @summary("Type") |
| 71 | + type: T; |
| 72 | + |
| 73 | + /** |
| 74 | + * The customer owning the charge. |
| 75 | + */ |
| 76 | + @visibility(Lifecycle.Read) |
| 77 | + @summary("Customer") |
| 78 | + customer: CustomerReference; |
| 79 | + |
| 80 | + /** |
| 81 | + * The charge is managed by the following entity. |
| 82 | + */ |
| 83 | + @visibility(Lifecycle.Read) |
| 84 | + @summary("Managed by") |
| 85 | + managed_by: Shared.ResourceManagedBy; |
| 86 | + |
| 87 | + /** |
| 88 | + * The subscription that originated the charge, when the charge was created from a subscription item. |
| 89 | + */ |
| 90 | + @visibility(Lifecycle.Read) |
| 91 | + @summary("Subscription") |
| 92 | + subscription?: Subscriptions.SubscriptionReference; |
| 93 | + |
| 94 | + /** |
| 95 | + * The currency of the charge. |
| 96 | + */ |
| 97 | + @visibility(Lifecycle.Read) |
| 98 | + @summary("Currency") |
| 99 | + currency: Shared.CurrencyCode; |
| 100 | + |
| 101 | + /** |
| 102 | + * The lifecycle status of the charge. |
| 103 | + */ |
| 104 | + @visibility(Lifecycle.Read) |
| 105 | + @summary("Status") |
| 106 | + status: ChargeStatus; |
| 107 | + |
| 108 | + /** |
| 109 | + * The timestamp when the charge is intended to be invoiced. |
| 110 | + */ |
| 111 | + @visibility(Lifecycle.Read) |
| 112 | + @summary("Invoice at") |
| 113 | + invoice_at: Shared.DateTime; |
| 114 | + |
| 115 | + /** |
| 116 | + * The effective service period covered by the charge. |
| 117 | + */ |
| 118 | + @visibility(Lifecycle.Read) |
| 119 | + @summary("Service period") |
| 120 | + service_period: Shared.ClosedPeriod; |
| 121 | + |
| 122 | + /** |
| 123 | + * The full, unprorated service period of the charge. |
| 124 | + */ |
| 125 | + @visibility(Lifecycle.Read) |
| 126 | + @summary("Full service period") |
| 127 | + full_service_period: Shared.ClosedPeriod; |
| 128 | + |
| 129 | + /** |
| 130 | + * The billing period the charge belongs to. |
| 131 | + */ |
| 132 | + @visibility(Lifecycle.Read) |
| 133 | + @summary("Billing period") |
| 134 | + billing_period: Shared.ClosedPeriod; |
| 135 | + |
| 136 | + /** |
| 137 | + * The earliest time when the charge should be advanced again by background processing. |
| 138 | + */ |
| 139 | + @visibility(Lifecycle.Read) |
| 140 | + @summary("Advance after") |
| 141 | + advance_after?: Shared.DateTime; |
| 142 | + |
| 143 | + /** |
| 144 | + * The price of the charge. |
| 145 | + */ |
| 146 | + @visibility(Lifecycle.Read) |
| 147 | + @summary("Price") |
| 148 | + price: Shared.CurrencyAmount; |
| 149 | + |
| 150 | + /** |
| 151 | + * Unique reference ID of the charge. |
| 152 | + */ |
| 153 | + @visibility(Lifecycle.Read) |
| 154 | + @summary("Unique reference ID") |
| 155 | + unique_reference_id?: string; |
| 156 | + |
| 157 | + /** |
| 158 | + * Settlement mode of the charge. |
| 159 | + */ |
| 160 | + @visibility(Lifecycle.Read) |
| 161 | + @summary("Settlement mode") |
| 162 | + settlement_mode: ProductCatalog.SettlementMode; |
| 163 | +} |
| 164 | + |
| 165 | +/** |
| 166 | + * A flat fee charge for a customer. |
| 167 | + */ |
| 168 | +@friendlyName("BillingFlatFeeCharge") |
| 169 | +@summary("Flat fee charge") |
| 170 | +model FlatFeeCharge { |
| 171 | + ...ChargeBase<ChargeType.FlatFee>; |
| 172 | + |
| 173 | + /** |
| 174 | + * Payment term of the flat fee charge. |
| 175 | + */ |
| 176 | + @visibility(Lifecycle.Read, Lifecycle.Create) |
| 177 | + @summary("Payment term") |
| 178 | + payment_term: ProductCatalog.PricePaymentTerm; |
| 179 | + |
| 180 | + /** |
| 181 | + * The discounts applied to the charge. |
| 182 | + */ |
| 183 | + @visibility(Lifecycle.Read, Lifecycle.Create) |
| 184 | + @summary("Discounts") |
| 185 | + discounts?: OmitProperties<ProductCatalog.Discounts, "usage">; |
| 186 | + |
| 187 | + /** |
| 188 | + * The feature associated with the charge, when applicable. |
| 189 | + */ |
| 190 | + @visibility(Lifecycle.Read, Lifecycle.Create) |
| 191 | + @summary("Feature key") |
| 192 | + feature_key?: string; |
| 193 | + |
| 194 | + /** |
| 195 | + * The proration configuration of the charge. |
| 196 | + */ |
| 197 | + @visibility(Lifecycle.Read, Lifecycle.Create) |
| 198 | + @summary("Proration configuration") |
| 199 | + proration_configuration: ProductCatalog.ProrationConfiguration; |
| 200 | + |
| 201 | + // Calculated fields |
| 202 | + /** |
| 203 | + * The amount after proration of the charge. |
| 204 | + */ |
| 205 | + @visibility(Lifecycle.Read) |
| 206 | + @summary("Amount after proration") |
| 207 | + amount_after_proration: Shared.CurrencyAmount; |
| 208 | +} |
| 209 | + |
| 210 | +/** |
| 211 | + * A usage-based charge for a customer. |
| 212 | + */ |
| 213 | +@friendlyName("BillingChargeTotals") |
| 214 | +model ChargeTotals { |
| 215 | + /** |
| 216 | + * The amount of the charge already booked to the internal accounting system. |
| 217 | + */ |
| 218 | + @visibility(Lifecycle.Read) |
| 219 | + @summary("Booked") |
| 220 | + booked: Shared.Totals; |
| 221 | + |
| 222 | + /** |
| 223 | + * The realtime amount of the charge. |
| 224 | + * |
| 225 | + * Requires the `realtime_usage` expand. |
| 226 | + */ |
| 227 | + @visibility(Lifecycle.Read) |
| 228 | + @summary("Realtime totals") |
| 229 | + realtime?: Shared.Totals; |
| 230 | +} |
| 231 | + |
| 232 | +/** |
| 233 | + * A usage-based charge for a customer. |
| 234 | + */ |
| 235 | +@friendlyName("BillingUsageBasedCharge") |
| 236 | +@summary("Usage-based charge") |
| 237 | +model UsageBasedCharge { |
| 238 | + ...ChargeBase<ChargeType.UsageBased>; |
| 239 | + |
| 240 | + /** |
| 241 | + * Discounts applied to the usage-based charge. |
| 242 | + */ |
| 243 | + @visibility(Lifecycle.Read, Lifecycle.Create) |
| 244 | + @summary("Discounts") |
| 245 | + discounts?: ProductCatalog.Discounts; |
| 246 | + |
| 247 | + /** |
| 248 | + * The feature associated with the charge. |
| 249 | + */ |
| 250 | + @visibility(Lifecycle.Read, Lifecycle.Create) |
| 251 | + @summary("Feature key") |
| 252 | + feature_key: string; |
| 253 | + |
| 254 | + // Status fields |
| 255 | + |
| 256 | + /** Aggregated booked and realtime totals for the charge. */ |
| 257 | + @visibility(Lifecycle.Read) |
| 258 | + @summary("Totals for the charge") |
| 259 | + totals: ChargeTotals; |
| 260 | +} |
| 261 | + |
| 262 | +/** |
| 263 | + * Customer charge. |
| 264 | + */ |
| 265 | +@friendlyName("BillingCharge") |
| 266 | +@summary("Customer charge") |
| 267 | +@discriminated(#{ envelope: "none", discriminatorPropertyName: "type" }) |
| 268 | +union Charge { |
| 269 | + /** |
| 270 | + * A flat fee charge. |
| 271 | + */ |
| 272 | + flat_fee: FlatFeeCharge, |
| 273 | + |
| 274 | + /** |
| 275 | + * A usage-based charge. |
| 276 | + */ |
| 277 | + usage_based: UsageBasedCharge, |
| 278 | +} |
| 279 | + |
| 280 | +/** |
| 281 | + * Expands for customer charges. |
| 282 | + */ |
| 283 | +@friendlyName("BillingChargesExpand") |
| 284 | +@summary("Customer charge expands") |
| 285 | +enum ChargesExpand { |
| 286 | + /** |
| 287 | + * The charge's realizations. |
| 288 | + */ |
| 289 | + RealtimeUsage: "realtime_usage", |
| 290 | +} |
0 commit comments