Search in sources :

Example 1 with BraintreeException

use of com.braintreepayments.api.exceptions.BraintreeException in project braintree_android by braintree.

the class PayPalUnitTest method requestBillingAgreement_postsExceptionWhenAmountIsIncluded.

@Test
public void requestBillingAgreement_postsExceptionWhenAmountIsIncluded() {
    BraintreeFragment fragment = mMockFragmentBuilder.build();
    PayPal.requestBillingAgreement(fragment, new PayPalRequest("1"));
    ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class);
    verify(fragment).postCallback(captor.capture());
    assertTrue(captor.getValue() instanceof BraintreeException);
    assertEquals("There must be no amount specified for the Billing Agreement flow", captor.getValue().getMessage());
}
Also used : BraintreeException(com.braintreepayments.api.exceptions.BraintreeException) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) BraintreeException(com.braintreepayments.api.exceptions.BraintreeException) JSONException(org.json.JSONException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with BraintreeException

use of com.braintreepayments.api.exceptions.BraintreeException in project braintree_android by braintree.

the class CardBuilderUnitTest method buildGraphQL_throwsAnExceptionWhenTheQueryCannotBeRead.

@Test
public void buildGraphQL_throwsAnExceptionWhenTheQueryCannotBeRead() throws InvalidArgumentException {
    Resources resources = mock(Resources.class);
    doThrow(new NotFoundException("Not found")).when(resources).openRawResource(anyInt());
    Context context = mock(Context.class);
    when(context.getResources()).thenReturn(resources);
    try {
        new CardBuilder().buildGraphQL(context, Authorization.fromString(TOKENIZATION_KEY));
        fail("Expected exception");
    } catch (BraintreeException e) {
        assertEquals("Unable to read GraphQL query", e.getMessage());
        assertEquals("Not found", e.getCause().getMessage());
    }
}
Also used : Context(android.content.Context) NotFoundException(android.content.res.Resources.NotFoundException) BraintreeException(com.braintreepayments.api.exceptions.BraintreeException) Resources(android.content.res.Resources) Test(org.junit.Test)

Example 3 with BraintreeException

use of com.braintreepayments.api.exceptions.BraintreeException in project braintree_android by braintree.

the class PayPal method requestOneTimePayment.

/**
 * Starts the Single Payment flow for PayPal with custom PayPal approval handler.
 *
 * @param fragment A {@link BraintreeFragment} used to process the request.
 * @param request A {@link PayPalRequest} used to customize the request. An amount MUST be specified.
 * @param handler A {@link PayPalApprovalHandler} for custom approval handling.
 */
public static void requestOneTimePayment(BraintreeFragment fragment, PayPalRequest request, PayPalApprovalHandler handler) {
    if (request.getAmount() != null) {
        fragment.sendAnalyticsEvent("paypal.one-time-payment.selected");
        if (request.shouldOfferCredit()) {
            fragment.sendAnalyticsEvent("paypal.single-payment.credit.offered");
        }
        requestOneTimePayment(fragment, request, false, handler);
    } else {
        fragment.postCallback(new BraintreeException("An amount must be specified for the Single Payment flow."));
    }
}
Also used : BraintreeException(com.braintreepayments.api.exceptions.BraintreeException)

Example 4 with BraintreeException

use of com.braintreepayments.api.exceptions.BraintreeException 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)

Example 5 with BraintreeException

use of com.braintreepayments.api.exceptions.BraintreeException in project braintree_android by braintree.

the class TokenizationClient method tokenizeGraphQL.

private static void tokenizeGraphQL(final BraintreeFragment fragment, final CardBuilder cardBuilder, final PaymentMethodNonceCallback callback) {
    fragment.sendAnalyticsEvent("card.graphql.tokenization.started");
    String payload;
    try {
        payload = cardBuilder.buildGraphQL(fragment.getApplicationContext(), fragment.getAuthorization());
    } catch (BraintreeException e) {
        callback.failure(e);
        return;
    }
    fragment.getGraphQLHttpClient().post(payload, new HttpResponseCallback() {

        @Override
        public void success(String responseBody) {
            try {
                callback.success(parsePaymentMethodNonces(responseBody, cardBuilder.getResponsePaymentMethodType()));
                fragment.sendAnalyticsEvent("card.graphql.tokenization.success");
            } catch (JSONException e) {
                callback.failure(e);
            }
        }

        @Override
        public void failure(Exception exception) {
            fragment.sendAnalyticsEvent("card.graphql.tokenization.failure");
            callback.failure(exception);
        }
    });
}
Also used : BraintreeException(com.braintreepayments.api.exceptions.BraintreeException) JSONException(org.json.JSONException) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) JSONException(org.json.JSONException) BraintreeException(com.braintreepayments.api.exceptions.BraintreeException)

Aggregations

BraintreeException (com.braintreepayments.api.exceptions.BraintreeException)12 JSONException (org.json.JSONException)4 Test (org.junit.Test)4 ConfigurationListener (com.braintreepayments.api.interfaces.ConfigurationListener)3 Configuration (com.braintreepayments.api.models.Configuration)3 PayPalRequest (com.braintreepayments.api.models.PayPalRequest)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Intent (android.content.Intent)2 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)2 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)2 Context (android.content.Context)1 Resources (android.content.res.Resources)1 NotFoundException (android.content.res.Resources.NotFoundException)1 Uri (android.net.Uri)1 BrowserSwitchException (com.braintreepayments.api.exceptions.BrowserSwitchException)1 ErrorWithResponse (com.braintreepayments.api.exceptions.ErrorWithResponse)1 AndroidPayConfiguration (com.braintreepayments.api.models.AndroidPayConfiguration)1 MetadataBuilder (com.braintreepayments.api.models.MetadataBuilder)1 PayPalConfiguration (com.braintreepayments.api.models.PayPalConfiguration)1 PayPalPaymentResource (com.braintreepayments.api.models.PayPalPaymentResource)1