#Akshay-serialization

1 messages · Page 1 of 1 (latest)

vital plank
#

So this is for any payment method with a postal code?

cloud gyro
#

yes

vital plank
#

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.

cloud gyro
#

I think that would be the case

#

basically try to deserialize the BillingAddress JSON to a C# BillingAddress

vital plank
#

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?

cloud gyro
#

Can you try to deserialize this JSON:

{
    city: "San Francisco"
    country: "US"
    line1: "test address"
    line2: null
    postal_code: "12345"
    state: "CA"
}
vital plank
#

How are you currently doing that in your code?

cloud gyro
#

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

vital plank
#

How are you sending it to your server?

#

And how specifically are you deserializing?

cloud gyro
#

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

vital plank
#

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.

cloud gyro
#

ok let me share some code

vital plank
#
          ""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);```
cloud gyro
#

ok but you defined the json string incorrectly

vital plank
#

It looks like it is expecting the C# name of the property rather than what is output elsewhere

#

how so?

cloud gyro
#

it's postal_code

vital plank
#

That deserializes properly for me

#

Right. Stripe's json calls it postal_code but it looks like here it wants PostalCode

cloud gyro
#

yep

vital plank
#

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);```
cloud gyro
#

The Stripe Address object has the [JsonProperty("postal_code")] to fix this mismatch but it doesn't end up working

vital plank
#

Do the other properties work like that for you? For me none of them worked in that form

cloud gyro
#

Nothing else uses the [JsonProperty] tag

vital plank
#

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?

cloud gyro
#

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
        });
}
vital plank
#

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)

cloud gyro
#

Yeah that would make sense

vital plank
#

Is it viable for you to use that?

cloud gyro
#

How did you choose to use Newtonsoft's deserializer?

vital plank
#

As how did Stripe choose?

cloud gyro
#

No how can I choose that

#

Is it in Startup.cs?

#

Actually it might make more sense to ask another of our devs who has context on our specific service setup

#

I'll switch to using the Newtonsoft deserializer

vital plank
#

That might. It is a package you can get through NuGet or however else you manage packages in your setup

#

Sounds good, glad we could clear that up. Thanks for sticking with me there