-
Notifications
You must be signed in to change notification settings - Fork 238
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
VenmoListener NPE Fix #848
Changes from 5 commits
a4f8056
a7d8117
2def0c6
0721b43
c457018
dc02b8e
475ff15
033bfb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.text.TextUtils; | ||
import android.util.Log; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
@@ -33,6 +34,8 @@ public class VenmoClient { | |
static final String EXTRA_USERNAME = "com.braintreepayments.api.EXTRA_USER_NAME"; | ||
static final String EXTRA_RESOURCE_ID = "com.braintreepayments.api.EXTRA_RESOURCE_ID"; | ||
|
||
static final String LOGGING_TAG = "Braintree"; | ||
|
||
private final BraintreeClient braintreeClient; | ||
private final VenmoApi venmoApi; | ||
private final VenmoSharedPrefsWriter sharedPrefsWriter; | ||
|
@@ -132,7 +135,7 @@ public void tokenizeVenmoAccount(@NonNull final FragmentActivity activity, @NonN | |
@Override | ||
public void onResult(@Nullable Exception error) { | ||
if (error != null) { | ||
listener.onVenmoFailure(error); | ||
deliverVenmoFailure(error); | ||
} | ||
} | ||
}); | ||
|
@@ -254,19 +257,19 @@ public void onResult(@Nullable VenmoAccountNonce nonce, @Nullable Exception erro | |
@Override | ||
public void onResult(@Nullable VenmoAccountNonce venmoAccountNonce, @Nullable Exception error) { | ||
if (venmoAccountNonce != null) { | ||
listener.onVenmoSuccess(venmoAccountNonce); | ||
deliverVenmoSuccess(venmoAccountNonce); | ||
} else if (error != null) { | ||
listener.onVenmoFailure(error); | ||
deliverVenmoFailure(error); | ||
} | ||
} | ||
}); | ||
} else { | ||
braintreeClient.sendAnalyticsEvent("pay-with-venmo.app-switch.failure"); | ||
listener.onVenmoSuccess(nonce); | ||
deliverVenmoSuccess(nonce); | ||
} | ||
} else { | ||
braintreeClient.sendAnalyticsEvent("pay-with-venmo.app-switch.failure"); | ||
listener.onVenmoFailure(error); | ||
deliverVenmoFailure(error); | ||
} | ||
} | ||
}); | ||
|
@@ -279,21 +282,21 @@ public void onResult(@Nullable VenmoAccountNonce venmoAccountNonce, @Nullable Ex | |
@Override | ||
public void onResult(@Nullable VenmoAccountNonce venmoAccountNonce, @Nullable Exception error) { | ||
if (venmoAccountNonce != null) { | ||
listener.onVenmoSuccess(venmoAccountNonce); | ||
deliverVenmoSuccess(venmoAccountNonce); | ||
} else if (error != null) { | ||
listener.onVenmoFailure(error); | ||
deliverVenmoFailure(error); | ||
} | ||
} | ||
}); | ||
} else { | ||
String venmoUsername = venmoResult.getVenmoUsername(); | ||
VenmoAccountNonce venmoAccountNonce = new VenmoAccountNonce(nonce, venmoUsername, false); | ||
listener.onVenmoSuccess(venmoAccountNonce); | ||
deliverVenmoSuccess(venmoAccountNonce); | ||
} | ||
|
||
} | ||
} else if (authError != null) { | ||
listener.onVenmoFailure(authError); | ||
deliverVenmoFailure(authError); | ||
} | ||
} | ||
}); | ||
|
@@ -302,7 +305,23 @@ public void onResult(@Nullable VenmoAccountNonce venmoAccountNonce, @Nullable Ex | |
if (venmoResult.getError() instanceof UserCanceledException) { | ||
braintreeClient.sendAnalyticsEvent("pay-with-venmo.app-switch.canceled"); | ||
} | ||
listener.onVenmoFailure(venmoResult.getError()); | ||
deliverVenmoFailure(venmoResult.getError()); | ||
} | ||
} | ||
|
||
private void deliverVenmoSuccess(VenmoAccountNonce venmoAccountNonce) { | ||
if (listener != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to handle if the listener is null in either of these cases? Not sure of the best way to do that or even if that'd be helpful to a merchant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not really sure there is any way to handle when the listener is null aside from just not crashing - without the listener we can't deliver a result, and updating the method to throw an error would be a breaking change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 is there any way for us to output something to the console? Mainly thinking for merchants who do something weird to have anything to point them potentially towards what they may have done wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added warning logs here if the listeners are null |
||
listener.onVenmoSuccess(venmoAccountNonce); | ||
} else { | ||
Log.w(LOGGING_TAG, "Unable to deliver result to null listener"); | ||
} | ||
} | ||
|
||
private void deliverVenmoFailure(Exception error) { | ||
if (listener != null) { | ||
listener.onVenmoFailure(error); | ||
} else { | ||
Log.w(LOGGING_TAG, "Unable to deliver result to null listener"); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: take or leave. Also I could see us moving this constant to a
Core
file one day.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update and moved to a LoggingUtils class 👍