braintree / braintree_dotnet

Braintree .NET library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
136 stars 73 forks source link

More descriptive error message opportunity #89

Closed rossiter10 closed 5 years ago

rossiter10 commented 5 years ago

General information

Issue description

So in one of our client's account, they somehow ended up with a Subscription with a typo in First Bill Date. The year was 20106 instead of 2016. So what happened is we were trying to use the PaymentMethod.Find() call, and it was throwing this exception:

System.FormatException: String was not recognized as a valid DateTime.\r\n at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)\r\n at System.DateTime.Parse(String s, IFormatProvider provider, DateTimeStyles styles)\r\n at Braintree.NodeWrapper.GetDateTime(String path)\r\n at Braintree.Subscription..ctor(NodeWrapper node, IBraintreeGateway gateway)\r\n at Braintree.CreditCard..ctor(NodeWrapper node, IBraintreeGateway gateway)\r\n at Braintree.PaymentMethodParser.ParsePaymentMethod(NodeWrapper response, IBraintreeGateway gateway)\r\n at Braintree.PaymentMethodGateway.Find(String token)\r\n ...

So it looks like the PaymentMethod.Find() result also includes a list of associated Subscriptions, so I'm guessing the actual parsing error happened trying to load that associated Subscription with the typo in the First Bill Date.

I know this is probably rare, but thought I'd share anyway as a heads up that First Bill Date at least might not always parse correctly, maybe it needs a TryParse() or something? And maybe the PaymentMethod.FInd() method could throw a more descriptive exception message in this case?

crookedneighbor commented 5 years ago

I'll pass this on to our subscription team. I expect the solution is to clean up the bad data, not sure how it got in that state in the first place though.

rossiter10 commented 5 years ago

Thanks. Yeah, I have a related email chain going with support as well where I asked the same question about how the bad date got in there. Ticket is #2453965 FYI.

crookedneighbor commented 5 years ago

Talked with our subscription team, and we're going to add some validations for the future so that the year passed can't exceed 9999. For right now, you'll need your client (or whoever has the legal ownership of the Braintree account) to contact Braintree so we can update the year to the correct value.

Going to close this now, since there's nothing more actionable to do on the SDK side of things. Thanks for bringing it up, very helpful!