Open dgregory-resnexus opened 3 hours ago
FYI the code snippet I provided is the redacted response I retrieved from my Stripe dashboard
Line 87. Most responses (the working ones) are actually being returned in seconds (int data type), but the forwarding API is responding in milliseconds (long data type), which is why adding seconds to UnixEpoch is failing (it's adding milliseconds instead of actual seconds).
Possible solution 1:
if (seconds > (long)int.MaxValue)
{
return UnixEpoch.AddMilliseconds(seconds);
}
else if (seconds >= 0)
{
return UnixEpoch.AddSeconds(seconds);
}
else
{
throw new JsonSerializationException(string.Format("Cannot convert value that is before Unix epoch of 00:00:00 UTC on 1 January 1970 to {0}.", objectType));
}
Possible solution 2 (avoids SDK fix): Fix the response from the API to return seconds instead of milliseconds
Describe the bug
When making a request to the /v1/forwarding/requests endpoint using v45.11 or v47.0 of the SDK, the response fails to be parsed.
It appears to me that it is the value of "created" (1731082862469) that is failing to parse. In a different successful request to a different endpoint, the value of "created" was 1731082744. The one that is failing appears to be a
long
data type and the one that is working appears to be anint
data type.To Reproduce
Make any request to the endpoint using the SDK. I used the suggested sample from the API docs
Expected behavior
Parse the response correctly
Code snippets
OS
Windows 11
.NET version
.NET 4.7.2
Library version
stripe-dotnet-v45.11
API version
2024-09-05
Additional context
System.ArgumentOutOfRangeException Value to add was out of range
Partial Stack Trace at System.DateTime.Add(Double value, Int32 scale) in System\DateTime.cs:line 860 at Stripe.Infrastructure.UnixDateTimeConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) in //src/Stripe.net/Infrastructure/JsonConverters/UnixDateTimeConverter.cs:line 87 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Populate(JsonReader reader, Object target) at Stripe.Infrastructure.StripeEntityConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) in //src/Stripe.net/Infrastructure/JsonConverters/StripeEntityConverter.cs:line 74