Search in sources :

Example 1 with ThreeDSecureAuthenticationResponse

use of com.braintreepayments.api.models.ThreeDSecureAuthenticationResponse in project braintree_android by braintree.

the class ThreeDSecureTest method onActivityResult_postsUnrecoverableErrorsToListeners.

@Test(timeout = 2000)
public void onActivityResult_postsUnrecoverableErrorsToListeners() throws InterruptedException {
    BraintreeFragment fragment = getMockFragmentWithConfiguration(mActivity, new TestConfigurationBuilder().build());
    fragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertEquals("Error!", error.getMessage());
            mCountDownLatch.countDown();
        }
    });
    ThreeDSecureAuthenticationResponse authResponse = ThreeDSecureAuthenticationResponse.fromException("Error!");
    Intent data = new Intent().putExtra(ThreeDSecureWebViewActivity.EXTRA_THREE_D_SECURE_RESULT, authResponse);
    ThreeDSecure.onActivityResult(fragment, Activity.RESULT_OK, data);
    mCountDownLatch.await();
}
Also used : ThreeDSecureAuthenticationResponse(com.braintreepayments.api.models.ThreeDSecureAuthenticationResponse) Intent(android.content.Intent) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) JSONException(org.json.JSONException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 2 with ThreeDSecureAuthenticationResponse

use of com.braintreepayments.api.models.ThreeDSecureAuthenticationResponse in project braintree_android by braintree.

the class ThreeDSecure method onActivityResult.

protected static void onActivityResult(BraintreeFragment fragment, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        ThreeDSecureAuthenticationResponse authenticationResponse;
        Uri resultUri = data.getData();
        if (resultUri != null) {
            authenticationResponse = ThreeDSecureAuthenticationResponse.fromJson(resultUri.getQueryParameter("auth_response"));
        } else {
            authenticationResponse = data.getParcelableExtra(ThreeDSecureWebViewActivity.EXTRA_THREE_D_SECURE_RESULT);
        }
        if (authenticationResponse.isSuccess()) {
            fragment.postCallback(authenticationResponse.getCardNonce());
        } else if (authenticationResponse.getException() != null) {
            fragment.postCallback(new BraintreeException(authenticationResponse.getException()));
        } else {
            fragment.postCallback(new ErrorWithResponse(422, authenticationResponse.getErrors()));
        }
    }
}
Also used : ThreeDSecureAuthenticationResponse(com.braintreepayments.api.models.ThreeDSecureAuthenticationResponse) ErrorWithResponse(com.braintreepayments.api.exceptions.ErrorWithResponse) BraintreeException(com.braintreepayments.api.exceptions.BraintreeException) Uri(android.net.Uri)

Aggregations

ThreeDSecureAuthenticationResponse (com.braintreepayments.api.models.ThreeDSecureAuthenticationResponse)2 Intent (android.content.Intent)1 Uri (android.net.Uri)1 BraintreeException (com.braintreepayments.api.exceptions.BraintreeException)1 ErrorWithResponse (com.braintreepayments.api.exceptions.ErrorWithResponse)1 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)1 BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)1 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)1 JSONException (org.json.JSONException)1 Test (org.junit.Test)1