Skip to content

Commit 8c17aab

Browse files
feat(api): add matrix with allocation price (#193)
1 parent bcdc8d1 commit 8c17aab

File tree

8 files changed

+796
-87
lines changed

8 files changed

+796
-87
lines changed

src/orb/resources/prices/prices.py

+150
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,76 @@ def create(
258258
"""
259259
...
260260

261+
@overload
262+
def create(
263+
self,
264+
*,
265+
cadence: Literal["annual", "monthly", "quarterly", "one_time"],
266+
currency: str,
267+
item_id: str,
268+
matrix_with_allocation_config: price_create_params.NewFloatingMatrixWithAllocationPriceMatrixWithAllocationConfig,
269+
model_type: Literal["matrix_with_allocation"],
270+
name: str,
271+
billable_metric_id: Optional[str] | NotGiven = NOT_GIVEN,
272+
billed_in_advance: Optional[bool] | NotGiven = NOT_GIVEN,
273+
external_price_id: Optional[str] | NotGiven = NOT_GIVEN,
274+
fixed_price_quantity: Optional[float] | NotGiven = NOT_GIVEN,
275+
invoice_grouping_key: Optional[str] | NotGiven = NOT_GIVEN,
276+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
277+
# The extra values given here take precedence over values defined on the client or passed to this method.
278+
extra_headers: Headers | None = None,
279+
extra_query: Query | None = None,
280+
extra_body: Body | None = None,
281+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
282+
idempotency_key: str | None = None,
283+
) -> Price:
284+
"""This endpoint is used to create a [price](../reference/price).
285+
286+
A price created
287+
using this endpoint is always an add-on, meaning that it’s not associated with a
288+
specific plan and can instead be individually added to subscriptions, including
289+
subscriptions on different plans.
290+
291+
An `external_price_id` can be optionally specified as an alias to allow
292+
ergonomic interaction with prices in the Orb API.
293+
294+
See the [Price resource](../reference/price) for the specification of different
295+
price model configurations possible in this endpoint.
296+
297+
Args:
298+
cadence: The cadence to bill for this price on.
299+
300+
currency: An ISO 4217 currency string for which this price is billed in.
301+
302+
item_id: The id of the item the plan will be associated with.
303+
304+
name: The name of the price.
305+
306+
billable_metric_id: The id of the billable metric for the price. Only needed if the price is
307+
usage-based.
308+
309+
billed_in_advance: If the Price represents a fixed cost, the price will be billed in-advance if
310+
this is true, and in-arrears if this is false.
311+
312+
external_price_id: An alias for the price.
313+
314+
fixed_price_quantity: If the Price represents a fixed cost, this represents the quantity of units
315+
applied.
316+
317+
invoice_grouping_key: The property used to group this price on an invoice
318+
319+
extra_headers: Send extra headers
320+
321+
extra_query: Add additional query parameters to the request
322+
323+
extra_body: Add additional JSON properties to the request
324+
325+
timeout: Override the client-level default timeout for this request, in seconds
326+
327+
idempotency_key: Specify a custom idempotency key for this request
328+
"""
329+
...
330+
261331
@overload
262332
def create(
263333
self,
@@ -1032,6 +1102,7 @@ def create(
10321102
["cadence", "currency", "item_id", "model_type", "name", "unit_config"],
10331103
["cadence", "currency", "item_id", "model_type", "name", "package_config"],
10341104
["cadence", "currency", "item_id", "matrix_config", "model_type", "name"],
1105+
["cadence", "currency", "item_id", "matrix_with_allocation_config", "model_type", "name"],
10351106
["cadence", "currency", "item_id", "model_type", "name", "tiered_config"],
10361107
["cadence", "currency", "item_id", "model_type", "name", "tiered_bps_config"],
10371108
["bps_config", "cadence", "currency", "item_id", "model_type", "name"],
@@ -1053,6 +1124,7 @@ def create(
10531124
model_type: Literal["unit"]
10541125
| Literal["package"]
10551126
| Literal["matrix"]
1127+
| Literal["matrix_with_allocation"]
10561128
| Literal["tiered"]
10571129
| Literal["tiered_bps"]
10581130
| Literal["bps"]
@@ -1073,6 +1145,8 @@ def create(
10731145
invoice_grouping_key: Optional[str] | NotGiven = NOT_GIVEN,
10741146
package_config: price_create_params.NewFloatingPackagePricePackageConfig | NotGiven = NOT_GIVEN,
10751147
matrix_config: price_create_params.NewFloatingMatrixPriceMatrixConfig | NotGiven = NOT_GIVEN,
1148+
matrix_with_allocation_config: price_create_params.NewFloatingMatrixWithAllocationPriceMatrixWithAllocationConfig
1149+
| NotGiven = NOT_GIVEN,
10761150
tiered_config: price_create_params.NewFloatingTieredPriceTieredConfig | NotGiven = NOT_GIVEN,
10771151
tiered_bps_config: price_create_params.NewFloatingTieredBpsPriceTieredBpsConfig | NotGiven = NOT_GIVEN,
10781152
bps_config: price_create_params.NewFloatingBpsPriceBpsConfig | NotGiven = NOT_GIVEN,
@@ -1111,6 +1185,7 @@ def create(
11111185
"invoice_grouping_key": invoice_grouping_key,
11121186
"package_config": package_config,
11131187
"matrix_config": matrix_config,
1188+
"matrix_with_allocation_config": matrix_with_allocation_config,
11141189
"tiered_config": tiered_config,
11151190
"tiered_bps_config": tiered_bps_config,
11161191
"bps_config": bps_config,
@@ -1445,6 +1520,76 @@ async def create(
14451520
"""
14461521
...
14471522

1523+
@overload
1524+
async def create(
1525+
self,
1526+
*,
1527+
cadence: Literal["annual", "monthly", "quarterly", "one_time"],
1528+
currency: str,
1529+
item_id: str,
1530+
matrix_with_allocation_config: price_create_params.NewFloatingMatrixWithAllocationPriceMatrixWithAllocationConfig,
1531+
model_type: Literal["matrix_with_allocation"],
1532+
name: str,
1533+
billable_metric_id: Optional[str] | NotGiven = NOT_GIVEN,
1534+
billed_in_advance: Optional[bool] | NotGiven = NOT_GIVEN,
1535+
external_price_id: Optional[str] | NotGiven = NOT_GIVEN,
1536+
fixed_price_quantity: Optional[float] | NotGiven = NOT_GIVEN,
1537+
invoice_grouping_key: Optional[str] | NotGiven = NOT_GIVEN,
1538+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
1539+
# The extra values given here take precedence over values defined on the client or passed to this method.
1540+
extra_headers: Headers | None = None,
1541+
extra_query: Query | None = None,
1542+
extra_body: Body | None = None,
1543+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
1544+
idempotency_key: str | None = None,
1545+
) -> Price:
1546+
"""This endpoint is used to create a [price](../reference/price).
1547+
1548+
A price created
1549+
using this endpoint is always an add-on, meaning that it’s not associated with a
1550+
specific plan and can instead be individually added to subscriptions, including
1551+
subscriptions on different plans.
1552+
1553+
An `external_price_id` can be optionally specified as an alias to allow
1554+
ergonomic interaction with prices in the Orb API.
1555+
1556+
See the [Price resource](../reference/price) for the specification of different
1557+
price model configurations possible in this endpoint.
1558+
1559+
Args:
1560+
cadence: The cadence to bill for this price on.
1561+
1562+
currency: An ISO 4217 currency string for which this price is billed in.
1563+
1564+
item_id: The id of the item the plan will be associated with.
1565+
1566+
name: The name of the price.
1567+
1568+
billable_metric_id: The id of the billable metric for the price. Only needed if the price is
1569+
usage-based.
1570+
1571+
billed_in_advance: If the Price represents a fixed cost, the price will be billed in-advance if
1572+
this is true, and in-arrears if this is false.
1573+
1574+
external_price_id: An alias for the price.
1575+
1576+
fixed_price_quantity: If the Price represents a fixed cost, this represents the quantity of units
1577+
applied.
1578+
1579+
invoice_grouping_key: The property used to group this price on an invoice
1580+
1581+
extra_headers: Send extra headers
1582+
1583+
extra_query: Add additional query parameters to the request
1584+
1585+
extra_body: Add additional JSON properties to the request
1586+
1587+
timeout: Override the client-level default timeout for this request, in seconds
1588+
1589+
idempotency_key: Specify a custom idempotency key for this request
1590+
"""
1591+
...
1592+
14481593
@overload
14491594
async def create(
14501595
self,
@@ -2219,6 +2364,7 @@ async def create(
22192364
["cadence", "currency", "item_id", "model_type", "name", "unit_config"],
22202365
["cadence", "currency", "item_id", "model_type", "name", "package_config"],
22212366
["cadence", "currency", "item_id", "matrix_config", "model_type", "name"],
2367+
["cadence", "currency", "item_id", "matrix_with_allocation_config", "model_type", "name"],
22222368
["cadence", "currency", "item_id", "model_type", "name", "tiered_config"],
22232369
["cadence", "currency", "item_id", "model_type", "name", "tiered_bps_config"],
22242370
["bps_config", "cadence", "currency", "item_id", "model_type", "name"],
@@ -2240,6 +2386,7 @@ async def create(
22402386
model_type: Literal["unit"]
22412387
| Literal["package"]
22422388
| Literal["matrix"]
2389+
| Literal["matrix_with_allocation"]
22432390
| Literal["tiered"]
22442391
| Literal["tiered_bps"]
22452392
| Literal["bps"]
@@ -2260,6 +2407,8 @@ async def create(
22602407
invoice_grouping_key: Optional[str] | NotGiven = NOT_GIVEN,
22612408
package_config: price_create_params.NewFloatingPackagePricePackageConfig | NotGiven = NOT_GIVEN,
22622409
matrix_config: price_create_params.NewFloatingMatrixPriceMatrixConfig | NotGiven = NOT_GIVEN,
2410+
matrix_with_allocation_config: price_create_params.NewFloatingMatrixWithAllocationPriceMatrixWithAllocationConfig
2411+
| NotGiven = NOT_GIVEN,
22632412
tiered_config: price_create_params.NewFloatingTieredPriceTieredConfig | NotGiven = NOT_GIVEN,
22642413
tiered_bps_config: price_create_params.NewFloatingTieredBpsPriceTieredBpsConfig | NotGiven = NOT_GIVEN,
22652414
bps_config: price_create_params.NewFloatingBpsPriceBpsConfig | NotGiven = NOT_GIVEN,
@@ -2298,6 +2447,7 @@ async def create(
22982447
"invoice_grouping_key": invoice_grouping_key,
22992448
"package_config": package_config,
23002449
"matrix_config": matrix_config,
2450+
"matrix_with_allocation_config": matrix_with_allocation_config,
23012451
"tiered_config": tiered_config,
23022452
"tiered_bps_config": tiered_bps_config,
23032453
"bps_config": bps_config,

src/orb/types/credit_note.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class LineItem(BaseModel):
7878
"""The amount of the line item, including any line item minimums and discounts."""
7979

8080
discounts: List[LineItemDiscount]
81-
"""Any line items discounts from the invoice's line item."""
81+
"""Any line item discounts from the invoice's line item."""
8282

8383
name: str
8484
"""The name of the corresponding invoice line item."""

src/orb/types/invoice.py

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ class CreditNote(BaseModel):
7979

8080
credit_note_number: str
8181

82+
memo: Optional[str] = None
83+
"""An optional memo supplied on the credit note."""
84+
8285
reason: str
8386

8487
total: str

src/orb/types/invoice_fetch_upcoming_response.py

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ class CreditNote(BaseModel):
7979

8080
credit_note_number: str
8181

82+
memo: Optional[str] = None
83+
"""An optional memo supplied on the credit note."""
84+
8285
reason: str
8386

8487
total: str

src/orb/types/price.py

+113
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@
8989
"UnitWithPercentPriceItem",
9090
"UnitWithPercentPriceMaximum",
9191
"UnitWithPercentPriceMinimum",
92+
"MatrixWithAllocationPrice",
93+
"MatrixWithAllocationPriceBillableMetric",
94+
"MatrixWithAllocationPriceItem",
95+
"MatrixWithAllocationPriceMatrixWithAllocationConfig",
96+
"MatrixWithAllocationPriceMatrixWithAllocationConfigMatrixValue",
97+
"MatrixWithAllocationPriceMaximum",
98+
"MatrixWithAllocationPriceMinimum",
9299
]
93100

94101

@@ -1132,6 +1139,111 @@ class UnitWithPercentPrice(BaseModel):
11321139
unit_with_percent_config: Dict[str, object]
11331140

11341141

1142+
class MatrixWithAllocationPriceBillableMetric(BaseModel):
1143+
id: str
1144+
1145+
1146+
class MatrixWithAllocationPriceItem(BaseModel):
1147+
id: str
1148+
1149+
name: str
1150+
1151+
1152+
class MatrixWithAllocationPriceMatrixWithAllocationConfigMatrixValue(BaseModel):
1153+
dimension_values: List[Optional[str]]
1154+
"""One or two matrix keys to filter usage to this Matrix value by.
1155+
1156+
For example, ["region", "tier"] could be used to filter cloud usage by a cloud
1157+
region and an instance tier.
1158+
"""
1159+
1160+
unit_amount: str
1161+
"""Unit price for the specified dimension_values"""
1162+
1163+
scaling_factor: Optional[float] = None
1164+
"""Optional multiplier to scale rated quantities by"""
1165+
1166+
1167+
class MatrixWithAllocationPriceMatrixWithAllocationConfig(BaseModel):
1168+
allocation: float
1169+
"""Allocation to be used to calculate the price"""
1170+
1171+
default_unit_amount: str
1172+
"""Default per unit rate for any usage not bucketed into a specified matrix_value"""
1173+
1174+
dimensions: List[Optional[str]]
1175+
"""One or two event property values to evaluate matrix groups by"""
1176+
1177+
matrix_values: List[MatrixWithAllocationPriceMatrixWithAllocationConfigMatrixValue]
1178+
"""Matrix values for specified matrix grouping keys"""
1179+
1180+
scaling_factor: Optional[float] = None
1181+
"""
1182+
Default optional multiplier to scale rated quantities that fall into the default
1183+
bucket by
1184+
"""
1185+
1186+
1187+
class MatrixWithAllocationPriceMaximum(BaseModel):
1188+
applies_to_price_ids: List[str]
1189+
"""List of price_ids that this maximum amount applies to.
1190+
1191+
For plan/plan phase maximums, this can be a subset of prices.
1192+
"""
1193+
1194+
maximum_amount: str
1195+
"""Maximum amount applied"""
1196+
1197+
1198+
class MatrixWithAllocationPriceMinimum(BaseModel):
1199+
applies_to_price_ids: List[str]
1200+
"""List of price_ids that this minimum amount applies to.
1201+
1202+
For plan/plan phase minimums, this can be a subset of prices.
1203+
"""
1204+
1205+
minimum_amount: str
1206+
"""Minimum amount applied"""
1207+
1208+
1209+
class MatrixWithAllocationPrice(BaseModel):
1210+
id: str
1211+
1212+
billable_metric: Optional[MatrixWithAllocationPriceBillableMetric] = None
1213+
1214+
cadence: Literal["one_time", "monthly", "quarterly", "annual"]
1215+
1216+
created_at: datetime
1217+
1218+
currency: str
1219+
1220+
discount: Optional[Discount] = None
1221+
1222+
external_price_id: Optional[str] = None
1223+
1224+
fixed_price_quantity: Optional[float] = None
1225+
1226+
item: MatrixWithAllocationPriceItem
1227+
1228+
matrix_with_allocation_config: MatrixWithAllocationPriceMatrixWithAllocationConfig
1229+
1230+
maximum: Optional[MatrixWithAllocationPriceMaximum] = None
1231+
1232+
maximum_amount: Optional[str] = None
1233+
1234+
minimum: Optional[MatrixWithAllocationPriceMinimum] = None
1235+
1236+
minimum_amount: Optional[str] = None
1237+
1238+
price_model_type: Literal["matrix_with_allocation"] = FieldInfo(alias="model_type")
1239+
1240+
name: str
1241+
1242+
plan_phase_order: Optional[int] = None
1243+
1244+
price_type: Literal["usage_price", "fixed_price"]
1245+
1246+
11351247
Price = Union[
11361248
UnitPrice,
11371249
PackagePrice,
@@ -1146,4 +1258,5 @@ class UnitWithPercentPrice(BaseModel):
11461258
TieredWithMinimumPrice,
11471259
PackageWithAllocationPrice,
11481260
UnitWithPercentPrice,
1261+
MatrixWithAllocationPrice,
11491262
]

0 commit comments

Comments
 (0)