#Akshay-serialization
1 messages · Page 1 of 1 (latest)
yes
Would I be able to recreate this if I just retrieved a PaymentMethod?
Or rather, if you just retrieve a payment method, you don't see the postal code?
Trying to repro now.
I think that would be the case
basically try to deserialize the BillingAddress JSON to a C# BillingAddress
I can properly see the postal code on a PM I retrieved in my .NET app
var payment_method = payment_methods.Get("pm_123");
Console.WriteLine(payment_method.BillingDetails.Address.PostalCode);
Can you send me a snippet of what you are doing so I can try to reproduce?
And do you have a payment method ID (pm_123) that you have seen this on?
Can you try to deserialize this JSON:
{
city: "San Francisco"
country: "US"
line1: "test address"
line2: null
postal_code: "12345"
state: "CA"
}
How are you currently doing that in your code?
so on payment confirmation, I'm sending the paymentMethod.billingAddress to my server
And my server deserializes that into a Stripe.Address object
also for payment method: pm_1JxcUY2foflkLPWbAPrrYRRy
sending it through Axios
And idk about deserialization, i think it's just default C# deserialization
I'm not calling JsonConvert
I have a strongly typed object and so the JSON object gets converted to that
Are the rest of the properties deserializing for you properly?
And if you have the exact snippet you are working with, that would be helpful.
ok let me share some code
""City"": ""San Francisco"",
""Country"": ""US"",
""Line1"": ""test address"",
""Line2"": null,
""PostalCode"": ""12345"",
""State"": ""CA""
}";
var deserialized_details = JsonSerializer.Deserialize<Address>(jsonString);
Console.WriteLine(deserialized_details);```
ok but you defined the json string incorrectly
It looks like it is expecting the C# name of the property rather than what is output elsewhere
how so?
it's postal_code
That deserializes properly for me
Right. Stripe's json calls it postal_code but it looks like here it wants PostalCode
yep
For reference I serialized what I got back from our API to figure this out: ``` var payment_methods = new PaymentMethodService();
var payment_method = payment_methods.Get("pm_123");
Console.WriteLine(payment_method.BillingDetails.Address.PostalCode);
string address_json = JsonSerializer.Serialize(payment_method.BillingDetails.Address);
Console.WriteLine(address_json);```
The Stripe Address object has the [JsonProperty("postal_code")] to fix this mismatch but it doesn't end up working
Do the other properties work like that for you? For me none of them worked in that form
Nothing else uses the [JsonProperty] tag
In my version of the library they all do
Think I am using the latest? So in your version it is postal_code and only postal_code among them?
Oh sorry I see what you mean
Yes the other properties work
I have access to everything except postal code
So here's how a stripped down version of how I'm doing it in code:
public class PaymentConfirmationRequest
{
public Stripe.PaymentMethodBillingDetails BillingDetails { get; set; }
}
public async Task<IActionResult> PaymentConfirmation([FromBody] PaymentConfirmationRequest request)
{
Stripe.Address billingAddress = request.BillingAddress;
_orderService.CreateOrder(
new OrderServiceAddressDetails
{
CountryCode = billingAddress.Country,
ProvinceCode = billingAddress.State,
Zip = billingAddress.PostalCode,
City = billingAddress.City,
Address1 = billingAddress.Line1,
Address2 = billingAddress.Line2
});
}
Ah here we go, I got the right results when I used Newtonsoft.json's deserializer
(When I noticed the JsonProperty in dotnet-stripe was the Newtonsoft one)
Yeah that would make sense
Is it viable for you to use that?
How did you choose to use Newtonsoft's deserializer?
As how did Stripe choose?