-
Notifications
You must be signed in to change notification settings - Fork 572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cards are not being deserialized properly #1676
Comments
Hi @Excelzn. I just tried running the test suite for Stripe.net 26.0.0 with .NET Core 3 preview 6 and didn't see any issues. Can you share the exact code you're using to get the |
Absolutely. Here is the code: var _service = new CardService();
var card = await _service.GetAsync("STRIPE CUSTOMER ID", "STRIPE CARD ID"); I am inspecting the values in the debugger in JetBrains Rider. I also looked in VS 2019. The specific fields I am looking at are the Brand, ExpMonth, ExpYear, and Last4 fields. |
🤔 I've tried that exact code with Stripe.net 26.0.0 and .NET Core 3 preview 6, and the Here's the exact project I used: https://gist.github.com/ob-stripe/f2f90e42f0fdd5afb062e07436605489. Can you try it and tell me the results? The output should be: {
"id": "card_1EntZj2eZvKYlo2CV1sarcbm",
"object": "card",
"account": null,
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"available_payout_methods": null,
"brand": "Visa",
"country": "US",
"currency": null,
"customer": "cus_FIUWEyqQlxmOEj",
"cvc_check": null,
"default_for_currency": false,
"dynamic_last4": null,
"exp_month": 6,
"exp_year": 2020,
"fingerprint": "Xt5EWLLDS7FJjR1c",
"funding": "credit",
"last4": "4242",
"metadata": {},
"name": null,
"recipient": null,
"three_d_secure": null,
"tokenization_method": null,
"description": null,
"iin": null,
"issuer": null
} |
Apologies for the delay in responding. I tried your test project and it does work fine. One thing I noticed is that the cards I have are using IDs that begin with var card = await _service.CreateAsync(userId, new CardCreateOptions
{
SourceToken = token
}); Which according to the docs should add it as a card rather than a source. |
@Excelzn The type of the payment source (card vs. source) is decided when you collect the card information in your frontend code:
(The word "source" is a bit overloaded here, so this is a bit confusing!) You can technically use the Similarly, you can use In short, you need to fix your integration to use the correct service class: I'm leaving this issue open because I think we can improve the library to make this less confusing, for instance by raising an exception if we know we're deserializing into the wrong model class, and/or by adding a |
I confirm this, it is not working on any platform !! Problem is with the JSON Structure, Json retrieved from server is... {
"data": [
{
"id": "src_.....",
"card": {
"last4": "1233"
}
}
]
} If you notice, all the properties of Card are inside Structure of Stripe Card is wrong... public class Card {
public string Id {get;set;}
public string Last4 {get;set;}
} Instead it should be... public class Card {
public string Id {get;set;}
public CardDetails Card {get;set;}
}
public class CardDetails {
public string Last4 {get;set;}
} |
@ackava Please read my comment above (#1676 (comment)). Source objects with |
@ob-stripe If that is the case, |
@ackava That should be the case already. Using AFAIK the only case where an object would be deserialized to the wrong model class is if you use Have you observed a case where |
@ob-stripe here is my code, Yes, I am using var cs = new CardService(client);
var cards = cs.List(custome.StripeCustomerID);
string json = cards.StripeResponse.Content;
var js = JObject.Parse(json);
var data = js["data"] as JArray;
var first = data[0];
var card = first["card"];
return new CardInfo {
ExpirationMonth = card["exp_month"].Value<int>(),
ExpirationYear = card["exp_year"].Value<int>(),
CardNumber = card["last4"].ToString(),
CardType = card["brand"].ToString()
}; |
@ackava Thanks. This is indeed a bug in the library where the |
Sorry for the delay here. This should be fixed in the latest major version, 30.0.0. Calling |
Using: Stripe.net 26.0.0 on .NET Core 3 preview 5
I know this is a preview build of .NET Core, but since every other piece of the library works fine, I am not sure if the issue is related to Stripe or .NET Core 3.
When using the CardService class to retrieve cards from the API, they are not being deserialized correctly. Every value on the Card ends up being null. This happens both when using the List methods and when using the Get methods. The StripeResponse.ObjectJson property does have all the values that should be there, but the object itself does not. Current workaround is to just deserialize it myself using the ObjectJson property.
The text was updated successfully, but these errors were encountered: