Search code examples
androidandroid-fragmentsbraintreeonactivityresultstart-activity

onActivityResult: resultCode always returns 2


I am trying to integrate BrainTree into my app, but I'm having some issues with startActivityForResult() and onActivityResult(). I have already properly retrieved a clientToken but for some reason I'm always receiving a resultCode of 2 in onActivityResult. In addition I also get this in my Logs:

I/art: Rejecting re-init on previously-failed class java.lang.Class

Any idea what's going on? Here's some snippets of my code in case it helps:

This is the onClick method in my fragment.

void onPaymentClick() {
   PaymentRequest paymentRequest = new PaymentRequest().clientToken("<client_token>");
        getActivity().startActivityForResult(paymentRequest.getIntent(storeOrderActivity), 1);
    }
}

And this is the onActivityResult code in my activity. (PostOrder is the the function that's supposed to run once Braintree sends a nonce back to me, but this doesn't even run since I get a resultCode of 2)

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 1) {
        if (resultCode == Activity.RESULT_OK) {
            PaymentMethodNonce paymentMethodNonce = data.getParcelableExtra(
                    BraintreePaymentActivity.EXTRA_PAYMENT_METHOD_NONCE
            );
            PostOrder.postOrder(this, fabCartAdapter.getCart(), paymentMethodNonce.getNonce());
        }
    }
}

Solution

  • The resultCode==2 is reserved for BRAINTREE_RESULT_DEVELOPER_ERROR:

    The payment method flow halted due to a resolvable error (authentication, authorization, SDK upgrade required). The reason for the error will be returned in a future release.

    Probably you need to double check if the SDK is set it up correctly.