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());
}
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());
}
}
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."));
}
}
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()));
}
}
}
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);
}
});
}
Aggregations