diff --git a/.fern/metadata.json b/.fern/metadata.json index 40d236e..1b36de9 100644 --- a/.fern/metadata.json +++ b/.fern/metadata.json @@ -6,13 +6,9 @@ "namespace": "SchematicHQ.Client", "client-class-name": "SchematicApi", "exported-client-class-name": "Schematic", - "extra-dependencies": { - "moq": "4.20.70", - "Moq.Contrib.HttpClient": "1.4.0" - }, "generate-mock-server-tests": false }, - "originGitCommit": "efe71642022d9d3303fd78c648e5b2539192230e", + "originGitCommit": "470e0f433ab9bb0e88784674fa2e1efce62ebd9b", "originGitCommitIsDirty": false, "invokedBy": "ci", "requestedVersion": "1.4.6", diff --git a/.fern/replay.lock b/.fern/replay.lock new file mode 100644 index 0000000..73507e5 --- /dev/null +++ b/.fern/replay.lock @@ -0,0 +1,10 @@ +# DO NOT EDIT MANUALLY - Managed by Fern Replay +version: "1.0" +generations: + - commit_sha: fa035322b88a5a8f406e152352e04fe728fc3dfa + tree_hash: 8e35af79a31647053fb5f06492d08476c6e663f8 + timestamp: 2026-05-25T11:19:40.509Z + cli_version: unknown + generator_versions: {} +current_generation: fa035322b88a5a8f406e152352e04fe728fc3dfa +patches: [] diff --git a/.fernignore b/.fernignore index ba92116..d364963 100644 --- a/.fernignore +++ b/.fernignore @@ -32,3 +32,6 @@ src/SchematicHQ.Client/SchematicHQ.Client.Custom.props src/SchematicHQ.Client/Webhooks/WebhookUtils/ src/SchematicHQ.Client/OpenFeature/ src/SchematicHQ.Client/generate-schema-hash.sh +.fern/replay.lock +.fern/replay.yml +.gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..74928d6 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +.fern/replay.lock linguist-generated=true diff --git a/reference.md b/reference.md index 118d345..99644e2 100644 --- a/reference.md +++ b/reference.md @@ -1300,6 +1300,46 @@ await client.Billing.UpsertPaymentMethodAsync( + + + + +
client.Billing.DeletePaymentMethodByExternalIdAsync(billingId) -> WithRawResponseTask<DeletePaymentMethodByExternalIdResponse> +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Billing.DeletePaymentMethodByExternalIdAsync("billing_id"); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**billingId:** `string` — billing_id + +
+
+
+
+ +
@@ -2672,6 +2712,155 @@ await client.Credits.ListGrantsForCreditAsync( + + + + +
client.Credits.AcquireCreditLeaseAsync(AcquireCreditLeaseRequestBody { ... }) -> WithRawResponseTask<AcquireCreditLeaseResponse> +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Credits.AcquireCreditLeaseAsync( + new AcquireCreditLeaseRequestBody + { + CompanyId = "company_id", + CreditTypeId = "credit_type_id", + RequestedAmount = 1.1, + } +); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**request:** `AcquireCreditLeaseRequestBody` + +
+
+
+
+ + +
+
+
+ +
client.Credits.ExtendCreditLeaseAsync(leaseId, ExtendCreditLeaseRequestBody { ... }) -> WithRawResponseTask<ExtendCreditLeaseResponse> +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Credits.ExtendCreditLeaseAsync( + "lease_id", + new ExtendCreditLeaseRequestBody { AdditionalAmount = 1.1 } +); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**leaseId:** `string` — lease_id + +
+
+ +
+
+ +**request:** `ExtendCreditLeaseRequestBody` + +
+
+
+
+ + +
+
+
+ +
client.Credits.ReleaseCreditLeaseAsync(leaseId, Dictionary<string, object?> { ... }) -> WithRawResponseTask<ReleaseCreditLeaseResponse> +
+
+ +#### 🔌 Usage + +
+
+ +
+
+ +```csharp +await client.Credits.ReleaseCreditLeaseAsync( + "lease_id", + new Dictionary() { { "key", "value" } } +); +``` +
+
+
+
+ +#### ⚙️ Parameters + +
+
+ +
+
+ +**leaseId:** `string` — lease_id + +
+
+ +
+
+ +**request:** `Dictionary` + +
+
+
+
+ +
diff --git a/src/SchematicHQ.Client/Billing/BillingClient.cs b/src/SchematicHQ.Client/Billing/BillingClient.cs index 5619c56..3afc2c4 100644 --- a/src/SchematicHQ.Client/Billing/BillingClient.cs +++ b/src/SchematicHQ.Client/Billing/BillingClient.cs @@ -1043,6 +1043,100 @@ private async Task> UpsertPaymentMe } } + private async Task< + WithRawResponse + > DeletePaymentMethodByExternalIdAsyncCore( + string billingId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Delete, + Path = string.Format( + "billing/payment-methods/{0}", + ValueConvert.ToPathParameterString(billingId) + ), + Headers = _headers, + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + var responseData = JsonUtils.Deserialize( + responseBody + )!; + return new WithRawResponse() + { + Data = responseData, + RawResponse = new RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }, + }; + } + catch (JsonException e) + { + throw new SchematicApiException( + "Failed to deserialize response", + response.StatusCode, + responseBody, + e + ); + } + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 400: + throw new BadRequestError(JsonUtils.Deserialize(responseBody)); + case 401: + throw new UnauthorizedError(JsonUtils.Deserialize(responseBody)); + case 403: + throw new ForbiddenError(JsonUtils.Deserialize(responseBody)); + case 404: + throw new NotFoundError(JsonUtils.Deserialize(responseBody)); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody) + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody + ); + } + } + private async Task> ListBillingPricesAsyncCore( ListBillingPricesRequest request, RequestOptions? options = null, @@ -2180,6 +2274,20 @@ public WithRawResponseTask UpsertPaymentMethodAsync ); } + /// + /// await client.Billing.DeletePaymentMethodByExternalIdAsync("billing_id"); + /// + public WithRawResponseTask DeletePaymentMethodByExternalIdAsync( + string billingId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + DeletePaymentMethodByExternalIdAsyncCore(billingId, options, cancellationToken) + ); + } + /// /// await client.Billing.ListBillingPricesAsync( /// new ListBillingPricesRequest diff --git a/src/SchematicHQ.Client/Billing/IBillingClient.cs b/src/SchematicHQ.Client/Billing/IBillingClient.cs index 88fe43f..debcd01 100644 --- a/src/SchematicHQ.Client/Billing/IBillingClient.cs +++ b/src/SchematicHQ.Client/Billing/IBillingClient.cs @@ -68,6 +68,12 @@ WithRawResponseTask UpsertPaymentMethodAsync( CancellationToken cancellationToken = default ); + WithRawResponseTask DeletePaymentMethodByExternalIdAsync( + string billingId, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); + WithRawResponseTask ListBillingPricesAsync( ListBillingPricesRequest request, RequestOptions? options = null, diff --git a/src/SchematicHQ.Client/Billing/Types/DeletePaymentMethodByExternalIdResponse.cs b/src/SchematicHQ.Client/Billing/Types/DeletePaymentMethodByExternalIdResponse.cs new file mode 100644 index 0000000..b8dd7cb --- /dev/null +++ b/src/SchematicHQ.Client/Billing/Types/DeletePaymentMethodByExternalIdResponse.cs @@ -0,0 +1,34 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record DeletePaymentMethodByExternalIdResponse : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("data")] + public required DeleteResponse Data { get; set; } + + /// + /// Input parameters + /// + [JsonPropertyName("params")] + public Dictionary Params { get; set; } = new Dictionary(); + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Credits/CreditsClient.cs b/src/SchematicHQ.Client/Credits/CreditsClient.cs index 98e821e..fa40dd5 100644 --- a/src/SchematicHQ.Client/Credits/CreditsClient.cs +++ b/src/SchematicHQ.Client/Credits/CreditsClient.cs @@ -1804,6 +1804,281 @@ private async Task> ListGrantsForCr } } + private async Task> AcquireCreditLeaseAsyncCore( + AcquireCreditLeaseRequestBody request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Post, + Path = "billing/credits/lease", + Body = request, + Headers = _headers, + ContentType = "application/json", + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + var responseData = JsonUtils.Deserialize(responseBody)!; + return new WithRawResponse() + { + Data = responseData, + RawResponse = new RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }, + }; + } + catch (JsonException e) + { + throw new SchematicApiException( + "Failed to deserialize response", + response.StatusCode, + responseBody, + e + ); + } + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 400: + throw new BadRequestError(JsonUtils.Deserialize(responseBody)); + case 401: + throw new UnauthorizedError(JsonUtils.Deserialize(responseBody)); + case 403: + throw new ForbiddenError(JsonUtils.Deserialize(responseBody)); + case 404: + throw new NotFoundError(JsonUtils.Deserialize(responseBody)); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody) + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody + ); + } + } + + private async Task> ExtendCreditLeaseAsyncCore( + string leaseId, + ExtendCreditLeaseRequestBody request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Put, + Path = string.Format( + "billing/credits/lease/{0}/extend", + ValueConvert.ToPathParameterString(leaseId) + ), + Body = request, + Headers = _headers, + ContentType = "application/json", + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + var responseData = JsonUtils.Deserialize(responseBody)!; + return new WithRawResponse() + { + Data = responseData, + RawResponse = new RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }, + }; + } + catch (JsonException e) + { + throw new SchematicApiException( + "Failed to deserialize response", + response.StatusCode, + responseBody, + e + ); + } + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 400: + throw new BadRequestError(JsonUtils.Deserialize(responseBody)); + case 401: + throw new UnauthorizedError(JsonUtils.Deserialize(responseBody)); + case 403: + throw new ForbiddenError(JsonUtils.Deserialize(responseBody)); + case 404: + throw new NotFoundError(JsonUtils.Deserialize(responseBody)); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody) + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody + ); + } + } + + private async Task> ReleaseCreditLeaseAsyncCore( + string leaseId, + Dictionary request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var _headers = await new SchematicHQ.Client.Core.HeadersBuilder.Builder() + .Add(_client.Options.Headers) + .Add(_client.Options.AdditionalHeaders) + .Add(options?.AdditionalHeaders) + .BuildAsync() + .ConfigureAwait(false); + var response = await _client + .SendRequestAsync( + new JsonRequest + { + Method = HttpMethod.Put, + Path = string.Format( + "billing/credits/lease/{0}/release", + ValueConvert.ToPathParameterString(leaseId) + ), + Body = request, + Headers = _headers, + ContentType = "application/json", + Options = options, + }, + cancellationToken + ) + .ConfigureAwait(false); + if (response.StatusCode is >= 200 and < 400) + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + var responseData = JsonUtils.Deserialize(responseBody)!; + return new WithRawResponse() + { + Data = responseData, + RawResponse = new RawResponse() + { + StatusCode = response.Raw.StatusCode, + Url = response.Raw.RequestMessage?.RequestUri ?? new Uri("about:blank"), + Headers = ResponseHeaders.FromHttpResponseMessage(response.Raw), + }, + }; + } + catch (JsonException e) + { + throw new SchematicApiException( + "Failed to deserialize response", + response.StatusCode, + responseBody, + e + ); + } + } + { + var responseBody = await response + .Raw.Content.ReadAsStringAsync(cancellationToken) + .ConfigureAwait(false); + try + { + switch (response.StatusCode) + { + case 400: + throw new BadRequestError(JsonUtils.Deserialize(responseBody)); + case 401: + throw new UnauthorizedError(JsonUtils.Deserialize(responseBody)); + case 403: + throw new ForbiddenError(JsonUtils.Deserialize(responseBody)); + case 404: + throw new NotFoundError(JsonUtils.Deserialize(responseBody)); + case 500: + throw new InternalServerError( + JsonUtils.Deserialize(responseBody) + ); + } + } + catch (JsonException) + { + // unable to map error response, throwing generic error + } + throw new SchematicApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + responseBody + ); + } + } + private async Task< WithRawResponse > GetEnrichedCreditLedgerAsyncCore( @@ -3170,6 +3445,63 @@ public WithRawResponseTask ListGrantsForCreditAsync ); } + /// + /// await client.Credits.AcquireCreditLeaseAsync( + /// new AcquireCreditLeaseRequestBody + /// { + /// CompanyId = "company_id", + /// CreditTypeId = "credit_type_id", + /// RequestedAmount = 1.1, + /// } + /// ); + /// + public WithRawResponseTask AcquireCreditLeaseAsync( + AcquireCreditLeaseRequestBody request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + AcquireCreditLeaseAsyncCore(request, options, cancellationToken) + ); + } + + /// + /// await client.Credits.ExtendCreditLeaseAsync( + /// "lease_id", + /// new ExtendCreditLeaseRequestBody { AdditionalAmount = 1.1 } + /// ); + /// + public WithRawResponseTask ExtendCreditLeaseAsync( + string leaseId, + ExtendCreditLeaseRequestBody request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + ExtendCreditLeaseAsyncCore(leaseId, request, options, cancellationToken) + ); + } + + /// + /// await client.Credits.ReleaseCreditLeaseAsync( + /// "lease_id", + /// new Dictionary<string, object?>() { { "key", "value" } } + /// ); + /// + public WithRawResponseTask ReleaseCreditLeaseAsync( + string leaseId, + Dictionary request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + return new WithRawResponseTask( + ReleaseCreditLeaseAsyncCore(leaseId, request, options, cancellationToken) + ); + } + /// /// await client.Credits.GetEnrichedCreditLedgerAsync( /// new GetEnrichedCreditLedgerRequest diff --git a/src/SchematicHQ.Client/Credits/ICreditsClient.cs b/src/SchematicHQ.Client/Credits/ICreditsClient.cs index de80009..1c5dd3e 100644 --- a/src/SchematicHQ.Client/Credits/ICreditsClient.cs +++ b/src/SchematicHQ.Client/Credits/ICreditsClient.cs @@ -119,6 +119,26 @@ WithRawResponseTask ListGrantsForCreditAsync( CancellationToken cancellationToken = default ); + WithRawResponseTask AcquireCreditLeaseAsync( + AcquireCreditLeaseRequestBody request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); + + WithRawResponseTask ExtendCreditLeaseAsync( + string leaseId, + ExtendCreditLeaseRequestBody request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); + + WithRawResponseTask ReleaseCreditLeaseAsync( + string leaseId, + Dictionary request, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ); + WithRawResponseTask GetEnrichedCreditLedgerAsync( GetEnrichedCreditLedgerRequest request, RequestOptions? options = null, diff --git a/src/SchematicHQ.Client/Credits/Requests/AcquireCreditLeaseRequestBody.cs b/src/SchematicHQ.Client/Credits/Requests/AcquireCreditLeaseRequestBody.cs new file mode 100644 index 0000000..03e2294 --- /dev/null +++ b/src/SchematicHQ.Client/Credits/Requests/AcquireCreditLeaseRequestBody.cs @@ -0,0 +1,26 @@ +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record AcquireCreditLeaseRequestBody +{ + [JsonPropertyName("company_id")] + public required string CompanyId { get; set; } + + [JsonPropertyName("credit_type_id")] + public required string CreditTypeId { get; set; } + + [JsonPropertyName("expires_at")] + public DateTime? ExpiresAt { get; set; } + + [JsonPropertyName("requested_amount")] + public required double RequestedAmount { get; set; } + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Credits/Requests/ExtendCreditLeaseRequestBody.cs b/src/SchematicHQ.Client/Credits/Requests/ExtendCreditLeaseRequestBody.cs new file mode 100644 index 0000000..14f793e --- /dev/null +++ b/src/SchematicHQ.Client/Credits/Requests/ExtendCreditLeaseRequestBody.cs @@ -0,0 +1,20 @@ +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record ExtendCreditLeaseRequestBody +{ + [JsonPropertyName("additional_amount")] + public required double AdditionalAmount { get; set; } + + [JsonPropertyName("expires_at")] + public DateTime? ExpiresAt { get; set; } + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Credits/Types/AcquireCreditLeaseResponse.cs b/src/SchematicHQ.Client/Credits/Types/AcquireCreditLeaseResponse.cs new file mode 100644 index 0000000..3394c8b --- /dev/null +++ b/src/SchematicHQ.Client/Credits/Types/AcquireCreditLeaseResponse.cs @@ -0,0 +1,34 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record AcquireCreditLeaseResponse : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("data")] + public required CreditLeaseResponseData Data { get; set; } + + /// + /// Input parameters + /// + [JsonPropertyName("params")] + public Dictionary Params { get; set; } = new Dictionary(); + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Credits/Types/ExtendCreditLeaseResponse.cs b/src/SchematicHQ.Client/Credits/Types/ExtendCreditLeaseResponse.cs new file mode 100644 index 0000000..9163c70 --- /dev/null +++ b/src/SchematicHQ.Client/Credits/Types/ExtendCreditLeaseResponse.cs @@ -0,0 +1,34 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record ExtendCreditLeaseResponse : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("data")] + public required CreditLeaseResponseData Data { get; set; } + + /// + /// Input parameters + /// + [JsonPropertyName("params")] + public Dictionary Params { get; set; } = new Dictionary(); + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Credits/Types/ReleaseCreditLeaseResponse.cs b/src/SchematicHQ.Client/Credits/Types/ReleaseCreditLeaseResponse.cs new file mode 100644 index 0000000..7daa644 --- /dev/null +++ b/src/SchematicHQ.Client/Credits/Types/ReleaseCreditLeaseResponse.cs @@ -0,0 +1,34 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record ReleaseCreditLeaseResponse : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("data")] + public required CreditLeaseResponseData Data { get; set; } + + /// + /// Input parameters + /// + [JsonPropertyName("params")] + public Dictionary Params { get; set; } = new Dictionary(); + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/SchematicHQ.Client.csproj b/src/SchematicHQ.Client/SchematicHQ.Client.csproj index ca5dfdf..4353802 100644 --- a/src/SchematicHQ.Client/SchematicHQ.Client.csproj +++ b/src/SchematicHQ.Client/SchematicHQ.Client.csproj @@ -41,8 +41,6 @@ - - diff --git a/src/SchematicHQ.Client/Types/BillingProductPlanResponseData.cs b/src/SchematicHQ.Client/Types/BillingProductPlanResponseData.cs index 653070f..5385efe 100644 --- a/src/SchematicHQ.Client/Types/BillingProductPlanResponseData.cs +++ b/src/SchematicHQ.Client/Types/BillingProductPlanResponseData.cs @@ -17,6 +17,9 @@ public record BillingProductPlanResponseData : IJsonOnDeserialized [JsonPropertyName("billing_product_id")] public required string BillingProductId { get; set; } + [JsonPropertyName("billing_strategy")] + public required BillingStrategy BillingStrategy { get; set; } + [JsonPropertyName("charge_type")] public required ChargeType ChargeType { get; set; } diff --git a/src/SchematicHQ.Client/Types/BillingStrategy.cs b/src/SchematicHQ.Client/Types/BillingStrategy.cs new file mode 100644 index 0000000..1faae9b --- /dev/null +++ b/src/SchematicHQ.Client/Types/BillingStrategy.cs @@ -0,0 +1,119 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[JsonConverter(typeof(BillingStrategy.BillingStrategySerializer))] +[Serializable] +public readonly record struct BillingStrategy : IStringEnum +{ + public static readonly BillingStrategy SchematicManaged = new(Values.SchematicManaged); + + public static readonly BillingStrategy ProviderManaged = new(Values.ProviderManaged); + + public static readonly BillingStrategy NoBilling = new(Values.NoBilling); + + public BillingStrategy(string value) + { + Value = value; + } + + /// + /// The string value of the enum. + /// + public string Value { get; } + + /// + /// Create a string enum with the given value. + /// + public static BillingStrategy FromCustom(string value) + { + return new BillingStrategy(value); + } + + public bool Equals(string? other) + { + return Value.Equals(other); + } + + /// + /// Returns the string value of the enum. + /// + public override string ToString() + { + return Value; + } + + public static bool operator ==(BillingStrategy value1, string value2) => + value1.Value.Equals(value2); + + public static bool operator !=(BillingStrategy value1, string value2) => + !value1.Value.Equals(value2); + + public static explicit operator string(BillingStrategy value) => value.Value; + + public static explicit operator BillingStrategy(string value) => new(value); + + internal class BillingStrategySerializer : JsonConverter + { + public override BillingStrategy Read( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) + { + var stringValue = + reader.GetString() + ?? throw new global::System.Exception( + "The JSON value could not be read as a string." + ); + return new BillingStrategy(stringValue); + } + + public override void Write( + Utf8JsonWriter writer, + BillingStrategy value, + JsonSerializerOptions options + ) + { + writer.WriteStringValue(value.Value); + } + + public override BillingStrategy ReadAsPropertyName( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options + ) + { + var stringValue = + reader.GetString() + ?? throw new global::System.Exception( + "The JSON property name could not be read as a string." + ); + return new BillingStrategy(stringValue); + } + + public override void WriteAsPropertyName( + Utf8JsonWriter writer, + BillingStrategy value, + JsonSerializerOptions options + ) + { + writer.WritePropertyName(value.Value); + } + } + + /// + /// Constant strings for enum values + /// + [Serializable] + public static class Values + { + public const string SchematicManaged = "schematic_managed"; + + public const string ProviderManaged = "provider_managed"; + + public const string NoBilling = "no_billing"; + } +} diff --git a/src/SchematicHQ.Client/Types/ChargeType.cs b/src/SchematicHQ.Client/Types/ChargeType.cs index 3da3562..4585cbf 100644 --- a/src/SchematicHQ.Client/Types/ChargeType.cs +++ b/src/SchematicHQ.Client/Types/ChargeType.cs @@ -10,6 +10,8 @@ namespace SchematicHQ.Client; { public static readonly ChargeType Free = new(Values.Free); + public static readonly ChargeType None = new(Values.None); + public static readonly ChargeType OneTime = new(Values.OneTime); public static readonly ChargeType Recurring = new(Values.Recurring); @@ -111,6 +113,8 @@ public static class Values { public const string Free = "free"; + public const string None = "none"; + public const string OneTime = "one_time"; public const string Recurring = "recurring"; diff --git a/src/SchematicHQ.Client/Types/CompanyPlanDetailResponseData.cs b/src/SchematicHQ.Client/Types/CompanyPlanDetailResponseData.cs index 230de98..c023496 100644 --- a/src/SchematicHQ.Client/Types/CompanyPlanDetailResponseData.cs +++ b/src/SchematicHQ.Client/Types/CompanyPlanDetailResponseData.cs @@ -23,6 +23,9 @@ public record CompanyPlanDetailResponseData : IJsonOnDeserialized [JsonPropertyName("billing_product")] public BillingProductDetailResponseData? BillingProduct { get; set; } + [JsonPropertyName("billing_strategy")] + public required BillingStrategy BillingStrategy { get; set; } + [JsonPropertyName("charge_type")] public required ChargeType ChargeType { get; set; } @@ -96,6 +99,9 @@ public record CompanyPlanDetailResponseData : IJsonOnDeserialized [JsonPropertyName("is_default")] public required bool IsDefault { get; set; } + /// + /// Deprecated: Use BillingStrategy instead + /// [JsonPropertyName("is_free")] public required bool IsFree { get; set; } diff --git a/src/SchematicHQ.Client/Types/CreditLeaseResponseData.cs b/src/SchematicHQ.Client/Types/CreditLeaseResponseData.cs new file mode 100644 index 0000000..40e57d8 --- /dev/null +++ b/src/SchematicHQ.Client/Types/CreditLeaseResponseData.cs @@ -0,0 +1,49 @@ +using global::System.Text.Json; +using global::System.Text.Json.Serialization; +using SchematicHQ.Client.Core; + +namespace SchematicHQ.Client; + +[Serializable] +public record CreditLeaseResponseData : IJsonOnDeserialized +{ + [JsonExtensionData] + private readonly IDictionary _extensionData = + new Dictionary(); + + [JsonPropertyName("company_id")] + public required string CompanyId { get; set; } + + [JsonPropertyName("created_at")] + public required DateTime CreatedAt { get; set; } + + [JsonPropertyName("credit_type_id")] + public required string CreditTypeId { get; set; } + + [JsonPropertyName("expires_at")] + public required DateTime ExpiresAt { get; set; } + + [JsonPropertyName("granted_amount")] + public required double GrantedAmount { get; set; } + + [JsonPropertyName("id")] + public required string Id { get; set; } + + [JsonPropertyName("released_at")] + public DateTime? ReleasedAt { get; set; } + + [JsonPropertyName("updated_at")] + public required DateTime UpdatedAt { get; set; } + + [JsonIgnore] + public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); + + void IJsonOnDeserialized.OnDeserialized() => + AdditionalProperties.CopyFromExtensionData(_extensionData); + + /// + public override string ToString() + { + return JsonUtils.Serialize(this); + } +} diff --git a/src/SchematicHQ.Client/Types/EventBodyTrack.cs b/src/SchematicHQ.Client/Types/EventBodyTrack.cs index 4f5ae79..9efdb24 100644 --- a/src/SchematicHQ.Client/Types/EventBodyTrack.cs +++ b/src/SchematicHQ.Client/Types/EventBodyTrack.cs @@ -23,6 +23,12 @@ public record EventBodyTrack : IJsonOnDeserialized [JsonPropertyName("event")] public required string Event { get; set; } + /// + /// Credit lease ID this track event is redeeming against + /// + [JsonPropertyName("lease_id")] + public string? LeaseId { get; set; } + /// /// Optionally specify the quantity of the event /// diff --git a/src/SchematicHQ.Client/Types/FeatureView.cs b/src/SchematicHQ.Client/Types/FeatureView.cs index 6735c61..750c553 100644 --- a/src/SchematicHQ.Client/Types/FeatureView.cs +++ b/src/SchematicHQ.Client/Types/FeatureView.cs @@ -65,6 +65,9 @@ public record FeatureView : IJsonOnDeserialized [JsonPropertyName("updated_at")] public required DateTime UpdatedAt { get; set; } + [JsonPropertyName("usage_limit_trait_id")] + public string? UsageLimitTraitId { get; set; } + [JsonIgnore] public ReadOnlyAdditionalProperties AdditionalProperties { get; private set; } = new(); diff --git a/src/SchematicHQ.Client/Types/PlanDetailResponseData.cs b/src/SchematicHQ.Client/Types/PlanDetailResponseData.cs index a98e957..a32e3f3 100644 --- a/src/SchematicHQ.Client/Types/PlanDetailResponseData.cs +++ b/src/SchematicHQ.Client/Types/PlanDetailResponseData.cs @@ -23,6 +23,9 @@ public record PlanDetailResponseData : IJsonOnDeserialized [JsonPropertyName("billing_product")] public BillingProductDetailResponseData? BillingProduct { get; set; } + [JsonPropertyName("billing_strategy")] + public required BillingStrategy BillingStrategy { get; set; } + [JsonPropertyName("charge_type")] public required ChargeType ChargeType { get; set; } @@ -70,6 +73,9 @@ public record PlanDetailResponseData : IJsonOnDeserialized [JsonPropertyName("is_default")] public required bool IsDefault { get; set; } + /// + /// Deprecated: Use BillingStrategy instead + /// [JsonPropertyName("is_free")] public required bool IsFree { get; set; } diff --git a/src/SchematicHQ.Client/Types/PlanGroupPlanDetailResponseData.cs b/src/SchematicHQ.Client/Types/PlanGroupPlanDetailResponseData.cs index f06ad9e..da75c46 100644 --- a/src/SchematicHQ.Client/Types/PlanGroupPlanDetailResponseData.cs +++ b/src/SchematicHQ.Client/Types/PlanGroupPlanDetailResponseData.cs @@ -23,6 +23,9 @@ public record PlanGroupPlanDetailResponseData : IJsonOnDeserialized [JsonPropertyName("billing_product")] public BillingProductDetailResponseData? BillingProduct { get; set; } + [JsonPropertyName("billing_strategy")] + public required BillingStrategy BillingStrategy { get; set; } + [JsonPropertyName("charge_type")] public required ChargeType ChargeType { get; set; } @@ -83,6 +86,9 @@ public record PlanGroupPlanDetailResponseData : IJsonOnDeserialized [JsonPropertyName("is_default")] public required bool IsDefault { get; set; } + /// + /// Deprecated: Use BillingStrategy instead + /// [JsonPropertyName("is_free")] public required bool IsFree { get; set; } diff --git a/src/SchematicHQ.Client/Types/PlanViewPublicResponseData.cs b/src/SchematicHQ.Client/Types/PlanViewPublicResponseData.cs index 4c1be96..3da70da 100644 --- a/src/SchematicHQ.Client/Types/PlanViewPublicResponseData.cs +++ b/src/SchematicHQ.Client/Types/PlanViewPublicResponseData.cs @@ -23,6 +23,9 @@ public record PlanViewPublicResponseData : IJsonOnDeserialized [JsonPropertyName("billing_product")] public BillingProductDetailResponseData? BillingProduct { get; set; } + [JsonPropertyName("billing_strategy")] + public required BillingStrategy BillingStrategy { get; set; } + [JsonPropertyName("charge_type")] public required ChargeType ChargeType { get; set; } @@ -87,6 +90,9 @@ public record PlanViewPublicResponseData : IJsonOnDeserialized [JsonPropertyName("is_default")] public required bool IsDefault { get; set; } + /// + /// Deprecated: Use BillingStrategy instead + /// [JsonPropertyName("is_free")] public required bool IsFree { get; set; } diff --git a/src/SchematicHQ.Client/Types/UpsertBillingProductRequestBody.cs b/src/SchematicHQ.Client/Types/UpsertBillingProductRequestBody.cs index 959ef90..058739c 100644 --- a/src/SchematicHQ.Client/Types/UpsertBillingProductRequestBody.cs +++ b/src/SchematicHQ.Client/Types/UpsertBillingProductRequestBody.cs @@ -14,6 +14,9 @@ public record UpsertBillingProductRequestBody : IJsonOnDeserialized [JsonPropertyName("billing_product_id")] public string? BillingProductId { get; set; } + [JsonPropertyName("billing_strategy")] + public BillingStrategy? BillingStrategy { get; set; } + [JsonPropertyName("charge_type")] public required ChargeType ChargeType { get; set; }