braintree / braintree_java

Braintree Java library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
158 stars 98 forks source link

Null Transaction even if gateway returns a successful results #51

Closed gilbert-n closed 7 years ago

gilbert-n commented 7 years ago

I am trying out this library (braintree-java, version 2.66), and I have noticed an issues/ problems earlier:

  1. My situation is:
  2. Assume that we have a gateway built using marchantId, private and public key
  3. Assume that we have a valid client nonce
  4. Here is my code, and my question follows:

TransactionRequest trRequest = new TransactionRequest().amount(10) .paymentMethodNonce(clientNonce).options().submitForSettlement(true).done(); Result result = gateway.transaction().sale(trRequest); if(result.isSuccess()){ Transaction transaction = result.getTransaction(); //From here I want to access other things from transaction //such as transactionId so that I can keep a record of this transaction just in case. }

I have tested this code and it seems to be working (I can see transactions updated in my sandbox account). However, the problem I am facing is that the transaction object in the if block is null. Am I doing something wrong here? My understanding is that if the result was successful then we would have a way to access the underlying transaction object, and it shouldn't be null.

Thank you.

mtmarsh3 commented 7 years ago

Hi @gilbert-n,

Could you try changing the following lines of code and see if it fixes the issue?

Result result = gateway.transaction().sale(trRequest); to Result<Transaction> result = gateway.transaction().sale(trRequest);

Transaction transaction = result.getTransaction(); to Transaction transaction = result.getTarget();

You can see an example of accessing Transaction objects though Result objects on this page. If the object is still null afterwards, I'd recommend reaching out to support at support@braintreepayments.com