Skip to content

Commit 9e6c001

Browse files
feat(api): api update
1 parent 9504b00 commit 9e6c001

File tree

16 files changed

+797
-9
lines changed

16 files changed

+797
-9
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 118
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-79664fa0b4ea00c978ae2516087d0ee591b0ef92ca8db29557a0424bde520e10.yml
3-
openapi_spec_hash: 1ff6eee9184312a3a0fd21eb589132f9
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-d1abf71a1a70a43bdcc4da7104dabcbd67aa7e2d3e6cf21e33f50904b6997bb2.yml
3+
openapi_spec_hash: 28b0b31a997588cf3692458889321e1b
44
config_hash: dd4343ce95871032ef6e0735a4ca038c

src/Orb.Tests/Services/Customers/Credits/Ledger/LedgerServiceTest.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Threading.Tasks;
4+
using Orb.Models.Customers.Credits.Ledger.LedgerCreateEntryParamsProperties.BodyProperties.IncrementProperties.FilterProperties;
45
using BodyProperties = Orb.Models.Customers.Credits.Ledger.LedgerCreateEntryParamsProperties.BodyProperties;
6+
using FilterProperties = Orb.Models.Customers.Credits.Ledger.LedgerCreateEntryByExternalIDParamsProperties.BodyProperties.IncrementProperties.FilterProperties;
57

68
namespace Orb.Tests.Services.Customers.Credits.Ledger;
79

@@ -31,6 +33,15 @@ public async Task CreateEntry_Works()
3133
Description = "description",
3234
EffectiveDate = DateTime.Parse("2019-12-27T18:11:19.117Z"),
3335
ExpiryDate = DateTime.Parse("2019-12-27T18:11:19.117Z"),
36+
Filters =
37+
[
38+
new()
39+
{
40+
Field = Field.ItemID,
41+
Operator = Operator.Includes,
42+
Values = ["string"],
43+
},
44+
],
3445
InvoiceSettings = new()
3546
{
3647
AutoCollection = true,
@@ -65,6 +76,15 @@ public async Task CreateEntryByExternalID_Works()
6576
Description = "description",
6677
EffectiveDate = DateTime.Parse("2019-12-27T18:11:19.117Z"),
6778
ExpiryDate = DateTime.Parse("2019-12-27T18:11:19.117Z"),
79+
Filters =
80+
[
81+
new()
82+
{
83+
Field = FilterProperties::Field.ItemID,
84+
Operator = FilterProperties::Operator.Includes,
85+
Values = ["string"],
86+
},
87+
],
6888
InvoiceSettings = new()
6989
{
7090
AutoCollection = true,

src/Orb.Tests/Services/Plans/PlanServiceTest.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Orb.Models;
44
using Orb.Models.CustomExpirationProperties;
55
using Orb.Models.NewAllocationPriceProperties;
6+
using Orb.Models.NewAllocationPriceProperties.FilterProperties;
67
using Orb.Models.UnitConversionRateConfigProperties;
78
using NewBillingCycleConfigurationProperties = Orb.Models.NewBillingCycleConfigurationProperties;
89
using NewPlanUnitPriceProperties = Orb.Models.NewPlanUnitPriceProperties;
@@ -34,6 +35,15 @@ public async Task Create_Works()
3435
DurationUnit = DurationUnit.Day,
3536
},
3637
ExpiresAtEndOfCadence = true,
38+
Filters =
39+
[
40+
new()
41+
{
42+
Field = Field.ItemID,
43+
Operator = Operator.Includes,
44+
Values = ["string"],
45+
},
46+
],
3747
},
3848
PlanPhaseOrder = 0,
3949
Price1 = new(

src/Orb/Core/ModelBase.cs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
using Orb.Models.Customers.CustomerProperties.AccountingSyncConfigurationProperties.AccountingProviderProperties;
1414
using Orb.Models.Customers.NewAvalaraTaxConfigurationProperties;
1515
using Orb.Models.Events.Backfills.BackfillCreateResponseProperties;
16-
using Orb.Models.Invoices.InvoiceCreateParamsProperties.LineItemProperties;
1716
using Orb.Models.Items.ItemProperties.ExternalConnectionProperties;
18-
using Orb.Models.NewAllocationPriceProperties;
17+
using Orb.Models.NewFloatingBulkPriceProperties;
1918
using Orb.Models.Plans.PlanProperties.TrialConfigProperties;
2019
using Orb.Models.Subscriptions.SubscriptionCancelParamsProperties;
2120
using Orb.Models.Subscriptions.SubscriptionCreateParamsProperties;
@@ -69,6 +68,7 @@
6968
using InvoiceProperties = Orb.Models.InvoiceProperties;
7069
using LedgerListByExternalIDParamsProperties = Orb.Models.Customers.Credits.Ledger.LedgerListByExternalIDParamsProperties;
7170
using LedgerListParamsProperties = Orb.Models.Customers.Credits.Ledger.LedgerListParamsProperties;
71+
using LineItemProperties = Orb.Models.Invoices.InvoiceCreateParamsProperties.LineItemProperties;
7272
using MatrixProperties = Orb.Models.PriceProperties.MatrixProperties;
7373
using MatrixSubLineItemProperties = Orb.Models.MatrixSubLineItemProperties;
7474
using MatrixWithAllocationProperties = Orb.Models.PriceProperties.MatrixWithAllocationProperties;
@@ -82,9 +82,9 @@
8282
using MonetaryPercentageDiscountAdjustmentProperties = Orb.Models.MonetaryPercentageDiscountAdjustmentProperties;
8383
using MonetaryUsageDiscountAdjustmentProperties = Orb.Models.MonetaryUsageDiscountAdjustmentProperties;
8484
using MutatedSubscriptionProperties = Orb.Models.SubscriptionChanges.MutatedSubscriptionProperties;
85+
using NewAllocationPriceProperties = Orb.Models.NewAllocationPriceProperties;
8586
using NewAmountDiscountProperties = Orb.Models.NewAmountDiscountProperties;
8687
using NewBillingCycleConfigurationProperties = Orb.Models.NewBillingCycleConfigurationProperties;
87-
using NewFloatingBulkPriceProperties = Orb.Models.NewFloatingBulkPriceProperties;
8888
using NewFloatingBulkWithProrationPriceProperties = Orb.Models.NewFloatingBulkWithProrationPriceProperties;
8989
using NewFloatingCumulativeGroupedBulkPriceProperties = Orb.Models.NewFloatingCumulativeGroupedBulkPriceProperties;
9090
using NewFloatingGroupedAllocationPriceProperties = Orb.Models.NewFloatingGroupedAllocationPriceProperties;
@@ -349,7 +349,15 @@ public abstract record class ModelBase
349349
string,
350350
global::Orb.Models.MonetaryUsageDiscountAdjustmentProperties.FilterProperties.Operator
351351
>(),
352-
new ApiEnumConverter<string, Cadence>(),
352+
new ApiEnumConverter<string, NewAllocationPriceProperties::Cadence>(),
353+
new ApiEnumConverter<
354+
string,
355+
global::Orb.Models.NewAllocationPriceProperties.FilterProperties.Field
356+
>(),
357+
new ApiEnumConverter<
358+
string,
359+
global::Orb.Models.NewAllocationPriceProperties.FilterProperties.Operator
360+
>(),
353361
new ApiEnumConverter<string, NewAmountDiscountProperties::AdjustmentType>(),
354362
new ApiEnumConverter<bool, NewAmountDiscountProperties::AppliesToAll>(),
355363
new ApiEnumConverter<
@@ -362,8 +370,8 @@ public abstract record class ModelBase
362370
>(),
363371
new ApiEnumConverter<string, NewAmountDiscountProperties::PriceType>(),
364372
new ApiEnumConverter<string, NewBillingCycleConfigurationProperties::DurationUnit>(),
365-
new ApiEnumConverter<string, NewFloatingBulkPriceProperties::Cadence>(),
366-
new ApiEnumConverter<string, NewFloatingBulkPriceProperties::ModelType>(),
373+
new ApiEnumConverter<string, Cadence>(),
374+
new ApiEnumConverter<string, ModelType>(),
367375
new ApiEnumConverter<string, NewFloatingBulkWithProrationPriceProperties::Cadence>(),
368376
new ApiEnumConverter<string, NewFloatingBulkWithProrationPriceProperties::ModelType>(),
369377
new ApiEnumConverter<
@@ -1168,7 +1176,23 @@ public abstract record class ModelBase
11681176
new ApiEnumConverter<string, VoidLedgerEntryProperties::EntryType>(),
11691177
new ApiEnumConverter<string, LedgerListParamsProperties::EntryStatus>(),
11701178
new ApiEnumConverter<string, LedgerListParamsProperties::EntryType>(),
1179+
new ApiEnumConverter<
1180+
string,
1181+
global::Orb.Models.Customers.Credits.Ledger.LedgerCreateEntryParamsProperties.BodyProperties.IncrementProperties.FilterProperties.Field
1182+
>(),
1183+
new ApiEnumConverter<
1184+
string,
1185+
global::Orb.Models.Customers.Credits.Ledger.LedgerCreateEntryParamsProperties.BodyProperties.IncrementProperties.FilterProperties.Operator
1186+
>(),
11711187
new ApiEnumConverter<string, VoidProperties::VoidReason>(),
1188+
new ApiEnumConverter<
1189+
string,
1190+
global::Orb.Models.Customers.Credits.Ledger.LedgerCreateEntryByExternalIDParamsProperties.BodyProperties.IncrementProperties.FilterProperties.Field
1191+
>(),
1192+
new ApiEnumConverter<
1193+
string,
1194+
global::Orb.Models.Customers.Credits.Ledger.LedgerCreateEntryByExternalIDParamsProperties.BodyProperties.IncrementProperties.FilterProperties.Operator
1195+
>(),
11721196
new ApiEnumConverter<
11731197
string,
11741198
global::Orb.Models.Customers.Credits.Ledger.LedgerCreateEntryByExternalIDParamsProperties.BodyProperties.VoidProperties.VoidReason
@@ -1226,7 +1250,7 @@ public abstract record class ModelBase
12261250
global::Orb.Models.Invoices.InvoiceFetchUpcomingResponseProperties.PaymentAttemptProperties.PaymentProvider
12271251
>(),
12281252
new ApiEnumConverter<string, InvoiceFetchUpcomingResponseProperties::Status>(),
1229-
new ApiEnumConverter<string, ModelType>(),
1253+
new ApiEnumConverter<string, LineItemProperties::ModelType>(),
12301254
new ApiEnumConverter<string, InvoiceListParamsProperties::DateType>(),
12311255
new ApiEnumConverter<string, InvoiceListParamsProperties::Status>(),
12321256
new ApiEnumConverter<string, ExternalConnectionName>(),

src/Orb/Models/Customers/Credits/Ledger/LedgerCreateEntryByExternalIDParamsProperties/BodyProperties/Increment.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,28 @@ public string? Description
159159
}
160160
}
161161

162+
/// <summary>
163+
/// Optional filter to specify which items this credit block applies to. If not
164+
/// specified, the block will apply to all items for the pricing unit.
165+
/// </summary>
166+
public List<Filter>? Filters
167+
{
168+
get
169+
{
170+
if (!this.Properties.TryGetValue("filters", out JsonElement element))
171+
return null;
172+
173+
return JsonSerializer.Deserialize<List<Filter>?>(element, ModelBase.SerializerOptions);
174+
}
175+
set
176+
{
177+
this.Properties["filters"] = JsonSerializer.SerializeToElement(
178+
value,
179+
ModelBase.SerializerOptions
180+
);
181+
}
182+
}
183+
162184
/// <summary>
163185
/// Passing `invoice_settings` automatically generates an invoice for the newly
164186
/// added credits. If `invoice_settings` is passed, you must specify per_unit_cost_basis,
@@ -241,6 +263,10 @@ public override void Validate()
241263
_ = this.Description;
242264
_ = this.EffectiveDate;
243265
_ = this.ExpiryDate;
266+
foreach (var item in this.Filters ?? [])
267+
{
268+
item.Validate();
269+
}
244270
this.InvoiceSettings?.Validate();
245271
if (this.Metadata != null)
246272
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
4+
using System.Text.Json;
5+
using System.Text.Json.Serialization;
6+
using Orb.Core;
7+
using Orb.Exceptions;
8+
using Orb.Models.Customers.Credits.Ledger.LedgerCreateEntryByExternalIDParamsProperties.BodyProperties.IncrementProperties.FilterProperties;
9+
10+
namespace Orb.Models.Customers.Credits.Ledger.LedgerCreateEntryByExternalIDParamsProperties.BodyProperties.IncrementProperties;
11+
12+
/// <summary>
13+
/// A PriceFilter that only allows item_id field for block filters.
14+
/// </summary>
15+
[JsonConverter(typeof(ModelConverter<Filter>))]
16+
public sealed record class Filter : ModelBase, IFromRaw<Filter>
17+
{
18+
/// <summary>
19+
/// The property of the price the block applies to. Only item_id is supported.
20+
/// </summary>
21+
public required ApiEnum<string, Field> Field
22+
{
23+
get
24+
{
25+
if (!this.Properties.TryGetValue("field", out JsonElement element))
26+
throw new OrbInvalidDataException(
27+
"'field' cannot be null",
28+
new ArgumentOutOfRangeException("field", "Missing required argument")
29+
);
30+
31+
return JsonSerializer.Deserialize<ApiEnum<string, Field>>(
32+
element,
33+
ModelBase.SerializerOptions
34+
);
35+
}
36+
set
37+
{
38+
this.Properties["field"] = JsonSerializer.SerializeToElement(
39+
value,
40+
ModelBase.SerializerOptions
41+
);
42+
}
43+
}
44+
45+
/// <summary>
46+
/// Should prices that match the filter be included or excluded.
47+
/// </summary>
48+
public required ApiEnum<string, Operator> Operator
49+
{
50+
get
51+
{
52+
if (!this.Properties.TryGetValue("operator", out JsonElement element))
53+
throw new OrbInvalidDataException(
54+
"'operator' cannot be null",
55+
new ArgumentOutOfRangeException("operator", "Missing required argument")
56+
);
57+
58+
return JsonSerializer.Deserialize<ApiEnum<string, Operator>>(
59+
element,
60+
ModelBase.SerializerOptions
61+
);
62+
}
63+
set
64+
{
65+
this.Properties["operator"] = JsonSerializer.SerializeToElement(
66+
value,
67+
ModelBase.SerializerOptions
68+
);
69+
}
70+
}
71+
72+
/// <summary>
73+
/// The IDs or values that match this filter.
74+
/// </summary>
75+
public required List<string> Values
76+
{
77+
get
78+
{
79+
if (!this.Properties.TryGetValue("values", out JsonElement element))
80+
throw new OrbInvalidDataException(
81+
"'values' cannot be null",
82+
new ArgumentOutOfRangeException("values", "Missing required argument")
83+
);
84+
85+
return JsonSerializer.Deserialize<List<string>>(element, ModelBase.SerializerOptions)
86+
?? throw new OrbInvalidDataException(
87+
"'values' cannot be null",
88+
new ArgumentNullException("values")
89+
);
90+
}
91+
set
92+
{
93+
this.Properties["values"] = JsonSerializer.SerializeToElement(
94+
value,
95+
ModelBase.SerializerOptions
96+
);
97+
}
98+
}
99+
100+
public override void Validate()
101+
{
102+
this.Field.Validate();
103+
this.Operator.Validate();
104+
foreach (var item in this.Values)
105+
{
106+
_ = item;
107+
}
108+
}
109+
110+
public Filter() { }
111+
112+
#pragma warning disable CS8618
113+
[SetsRequiredMembers]
114+
Filter(Dictionary<string, JsonElement> properties)
115+
{
116+
Properties = properties;
117+
}
118+
#pragma warning restore CS8618
119+
120+
public static Filter FromRawUnchecked(Dictionary<string, JsonElement> properties)
121+
{
122+
return new(properties);
123+
}
124+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Text.Json;
3+
using System.Text.Json.Serialization;
4+
using Orb.Exceptions;
5+
6+
namespace Orb.Models.Customers.Credits.Ledger.LedgerCreateEntryByExternalIDParamsProperties.BodyProperties.IncrementProperties.FilterProperties;
7+
8+
/// <summary>
9+
/// The property of the price the block applies to. Only item_id is supported.
10+
/// </summary>
11+
[JsonConverter(typeof(FieldConverter))]
12+
public enum Field
13+
{
14+
ItemID,
15+
}
16+
17+
sealed class FieldConverter : JsonConverter<Field>
18+
{
19+
public override Field Read(
20+
ref Utf8JsonReader reader,
21+
Type typeToConvert,
22+
JsonSerializerOptions options
23+
)
24+
{
25+
return JsonSerializer.Deserialize<string>(ref reader, options) switch
26+
{
27+
"item_id" => Field.ItemID,
28+
_ => (Field)(-1),
29+
};
30+
}
31+
32+
public override void Write(Utf8JsonWriter writer, Field value, JsonSerializerOptions options)
33+
{
34+
JsonSerializer.Serialize(
35+
writer,
36+
value switch
37+
{
38+
Field.ItemID => "item_id",
39+
_ => throw new OrbInvalidDataException(
40+
string.Format("Invalid value '{0}' in {1}", value, nameof(value))
41+
),
42+
},
43+
options
44+
);
45+
}
46+
}

0 commit comments

Comments
 (0)