I have a bottomNavigationActivity, and a few fragments (e.g. homeFragment, settingsFragment).
In homeFragment, I have a recycler view. When selected a row, it will request for a client token and it will display a braintree dropin UI,
In homeRecyclerAdapter:
view.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
...
clientToken = response.body().getClientToken();
DropInRequest dropInRequest = new DropInRequest()
.clientToken(clientToken);
// Display Drop in
Context context = view.getContext();
Intent intent = dropInRequest.getIntent(context);
context.startActivity(intent);
}
It's able to display the braintree drop in, however, once it's dismiss or a payment method is selected, how do I get the event?
I've managed to get the event if I'm using a activity to display this drop in instead of using a recycler adapter, this is achieved using "startActivityForResult(dropInRequest.getIntent(getBaseContext()), 10)" and "onActivityResult":
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 10) {
if (resultCode == Activity.RESULT_OK) {
DropInResult result = data.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
// use the result to update your UI and send the payment method nonce to your server
// Run postNonceToServer code
Log.d(TAG, "RESULT_OK");
} else if (resultCode == Activity.RESULT_CANCELED) {
// the user canceled
Log.d(TAG, "RESULT_CANCELED");
} else {
// handle errors here, an exception may be available in
Exception error = (Exception) data.getSerializableExtra(DropInActivity.EXTRA_ERROR);
Log.d(TAG, "EXTRA_ERROR");
}
}
}