Skip to content

Commit 713ee01

Browse files
feat(api): api update
1 parent fc01a56 commit 713ee01

File tree

4 files changed

+165
-12
lines changed

4 files changed

+165
-12
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-ef726ad139fa29757029206ee08150434fc6c52005fec6d42c7d2bcd3aa7ab47.yml
3-
openapi_spec_hash: e622beb7c26f9b0dd641bd5c92735a5b
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-faf1f7c723d2762f09e9690ef2ceda58cb0a6ddacf1a79c3754871b90e7db0dc.yml
3+
openapi_spec_hash: 22269f85fae1ec920bdb0b32435a7aa8
44
config_hash: dd4343ce95871032ef6e0735a4ca038c

src/Orb/Models/Invoices/InvoiceUpdateParams.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
namespace Orb.Models.Invoices;
1010

1111
/// <summary>
12-
/// This endpoint allows you to update the `metadata`, `net_terms`, and `due_date`
13-
/// properties on an invoice. If you pass null for the metadata value, it will clear
14-
/// any existing metadata for that invoice.
12+
/// This endpoint allows you to update the `metadata`, `net_terms`, `due_date`, and
13+
/// `invoice_date` properties on an invoice. If you pass null for the metadata value,
14+
/// it will clear any existing metadata for that invoice.
1515
///
16-
/// `metadata` can be modified regardless of invoice state. `net_terms` and `due_date`
17-
/// can only be modified if the invoice is in a `draft` state.
16+
/// `metadata` can be modified regardless of invoice state. `net_terms`, `due_date`,
17+
/// and `invoice_date` can only be modified if the invoice is in a `draft` state.
18+
/// `invoice_date` can only be modified for non-subscription invoices.
1819
/// </summary>
1920
public sealed record class InvoiceUpdateParams : ParamsBase
2021
{
@@ -44,6 +45,27 @@ public DueDate? DueDate
4445
}
4546
}
4647

48+
/// <summary>
49+
/// The date of the invoice. Can only be modified for one-off draft invoices.
50+
/// </summary>
51+
public InvoiceDate? InvoiceDate
52+
{
53+
get
54+
{
55+
if (!this.BodyProperties.TryGetValue("invoice_date", out JsonElement element))
56+
return null;
57+
58+
return JsonSerializer.Deserialize<InvoiceDate?>(element, ModelBase.SerializerOptions);
59+
}
60+
set
61+
{
62+
this.BodyProperties["invoice_date"] = JsonSerializer.SerializeToElement(
63+
value,
64+
ModelBase.SerializerOptions
65+
);
66+
}
67+
}
68+
4769
/// <summary>
4870
/// User-specified key/value pairs for the resource. Individual keys can be removed
4971
/// by setting the value to `null`, and the entire metadata mapping can be cleared
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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.Exceptions;
7+
8+
namespace Orb.Models.Invoices.InvoiceUpdateParamsProperties;
9+
10+
/// <summary>
11+
/// The date of the invoice. Can only be modified for one-off draft invoices.
12+
/// </summary>
13+
[JsonConverter(typeof(InvoiceDateConverter))]
14+
public record class InvoiceDate
15+
{
16+
public object Value { get; private init; }
17+
18+
public InvoiceDate(DateOnly value)
19+
{
20+
Value = value;
21+
}
22+
23+
public InvoiceDate(DateTime value)
24+
{
25+
Value = value;
26+
}
27+
28+
InvoiceDate(UnknownVariant value)
29+
{
30+
Value = value;
31+
}
32+
33+
public static InvoiceDate CreateUnknownVariant(JsonElement value)
34+
{
35+
return new(new UnknownVariant(value));
36+
}
37+
38+
public bool TryPickDate([NotNullWhen(true)] out DateOnly? value)
39+
{
40+
value = this.Value as DateOnly?;
41+
return value != null;
42+
}
43+
44+
public bool TryPickDateTime([NotNullWhen(true)] out DateTime? value)
45+
{
46+
value = this.Value as DateTime?;
47+
return value != null;
48+
}
49+
50+
public void Switch(Action<DateOnly> @date, Action<DateTime> @dateTime)
51+
{
52+
switch (this.Value)
53+
{
54+
case DateOnly value:
55+
@date(value);
56+
break;
57+
case DateTime value:
58+
@dateTime(value);
59+
break;
60+
default:
61+
throw new OrbInvalidDataException("Data did not match any variant of InvoiceDate");
62+
}
63+
}
64+
65+
public T Match<T>(Func<DateOnly, T> @date, Func<DateTime, T> @dateTime)
66+
{
67+
return this.Value switch
68+
{
69+
DateOnly value => @date(value),
70+
DateTime value => @dateTime(value),
71+
_ => throw new OrbInvalidDataException("Data did not match any variant of InvoiceDate"),
72+
};
73+
}
74+
75+
public void Validate()
76+
{
77+
if (this.Value is UnknownVariant)
78+
{
79+
throw new OrbInvalidDataException("Data did not match any variant of InvoiceDate");
80+
}
81+
}
82+
83+
private record struct UnknownVariant(JsonElement value);
84+
}
85+
86+
sealed class InvoiceDateConverter : JsonConverter<InvoiceDate?>
87+
{
88+
public override InvoiceDate? Read(
89+
ref Utf8JsonReader reader,
90+
Type typeToConvert,
91+
JsonSerializerOptions options
92+
)
93+
{
94+
List<OrbInvalidDataException> exceptions = [];
95+
96+
try
97+
{
98+
return new InvoiceDate(JsonSerializer.Deserialize<DateOnly>(ref reader, options));
99+
}
100+
catch (Exception e) when (e is JsonException || e is OrbInvalidDataException)
101+
{
102+
exceptions.Add(
103+
new OrbInvalidDataException("Data does not match union variant 'DateOnly'", e)
104+
);
105+
}
106+
107+
try
108+
{
109+
return new InvoiceDate(JsonSerializer.Deserialize<DateTime>(ref reader, options));
110+
}
111+
catch (Exception e) when (e is JsonException || e is OrbInvalidDataException)
112+
{
113+
exceptions.Add(
114+
new OrbInvalidDataException("Data does not match union variant 'DateTime'", e)
115+
);
116+
}
117+
118+
throw new AggregateException(exceptions);
119+
}
120+
121+
public override void Write(
122+
Utf8JsonWriter writer,
123+
InvoiceDate? value,
124+
JsonSerializerOptions options
125+
)
126+
{
127+
object? variant = value?.Value;
128+
JsonSerializer.Serialize(writer, variant, options);
129+
}
130+
}

src/Orb/Services/Invoices/IInvoiceService.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ public interface IInvoiceService
1212
Task<Invoice> Create(InvoiceCreateParams parameters);
1313

1414
/// <summary>
15-
/// This endpoint allows you to update the `metadata`, `net_terms`, and `due_date`
16-
/// properties on an invoice. If you pass null for the metadata value, it will
17-
/// clear any existing metadata for that invoice.
15+
/// This endpoint allows you to update the `metadata`, `net_terms`, `due_date`,
16+
/// and `invoice_date` properties on an invoice. If you pass null for the metadata
17+
/// value, it will clear any existing metadata for that invoice.
1818
///
19-
/// `metadata` can be modified regardless of invoice state. `net_terms` and `due_date`
20-
/// can only be modified if the invoice is in a `draft` state.
19+
/// `metadata` can be modified regardless of invoice state. `net_terms`, `due_date`,
20+
/// and `invoice_date` can only be modified if the invoice is in a `draft` state.
21+
/// `invoice_date` can only be modified for non-subscription invoices.
2122
/// </summary>
2223
Task<Invoice> Update(InvoiceUpdateParams parameters);
2324

0 commit comments

Comments
 (0)