braintree / braintree_dotnet

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

Make the Target property behave same in Success or Failure scenarios. #43

Closed sjwaight closed 7 years ago

sjwaight commented 7 years ago

At present you can't rely on the Target property of the Result to always be populated. Ideally this property should always be populated and be consistent.

If this is a design decision that won't change then the documentation and samples should be updated to clearly note this behaviour.

I first need to test for Success or Failure and then depending on scenario treat the Result object differently.

As an example:

var brainTreeResponse = gateway.Transaction.Sale(btRequest); // On success = Transaction Object | on failure = null. var transactionTarget = brainTreeResponse.Target; // On success = null | on failure = Transaction Object. var transactionProperty = brainTreeResponse.Transaction;

sjwaight commented 7 years ago

If you want to see how to handle this currently here is the work-around.

https://gist.github.com/sjwaight/d96710be17033437cbc0295921ca1096

danakatz commented 7 years ago

Hi @sjwaight, thanks for the feedback!

This is the intended behavior (and in fact your workaround nearly matches the README example), but you're right that this could be communicated more clearly. We'll work on including this flow more explicitly in our developer documentation.