base.put(Keys.QUERY, GraphQLQueryHelper.getQuery(context, R.raw.tokenize_credit_card_mutation)); } catch (Resources.NotFoundException | IOException e) { throw new BraintreeException("Unable to read GraphQL query", e);
@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()); } }
@Override public void startActivityForResult(Intent intent, int requestCode) { if (!isAdded()) { postCallback(new BraintreeException("BraintreeFragment is not attached to an Activity. Please ensure it " + "is attached and try again.")); } else { super.startActivityForResult(intent, requestCode); } }
fragment.postCallback(new BraintreeException("LocalPayment encountered an error, " + "return URL is invalid."));
@Override public void onConfigurationFetched(Configuration configuration) { if (!configuration.isPayPalEnabled()) { fragment.postCallback(new BraintreeException("PayPal is not enabled")); return; } if (!isManifestValid(fragment)) { fragment.sendAnalyticsEvent("paypal.invalid-manifest"); fragment.postCallback(new BraintreeException("BraintreeBrowserSwitchActivity missing, " + "incorrectly configured in AndroidManifest.xml or another app defines the same browser " + "switch url as this app. See " + "https://developers.braintreepayments.com/guides/client-sdk/android/v2#browser-switch " + "for the correct configuration")); return; } try { persistPayPalRequest(fragment.getApplicationContext(), paypalRequest); createPaymentResource(fragment, paypalRequest, isBillingAgreement, callback); } catch (JSONException | ErrorWithResponse | BraintreeException ex) { fragment.postCallback(ex); } } });
final BraintreeResponseListener<LocalPaymentRequest> listener) { if (request == null) { fragment.postCallback(new BraintreeException("A LocalPaymentRequest is required.")); return; } else if (request.getApprovalUrl() != null || request.getPaymentId() != null) { fragment.postCallback(new BraintreeException("LocalPaymentRequest is invalid, " + "appovalUrl and paymentId should not be set.")); return; } else if (request.getPaymentType() == null || request.getAmount() == null) { fragment.postCallback(new BraintreeException("LocalPaymentRequest is invalid, " + "paymentType and amount are required.")); return; } else if (listener == null) { fragment.postCallback(new BraintreeException("BraintreeResponseListener<LocalPaymentRequest> " + "is required.")); return;
fragment.postCallback(new BraintreeException("AndroidPayActivity was not found in the Android manifest, " + "or did not have a theme of R.style.bt_transparent_activity")); fragment.sendAnalyticsEvent("android-pay.failed"); fragment.postCallback(new BraintreeException("Cannot pass null cart to performMaskedWalletRequest")); fragment.sendAnalyticsEvent("android-pay.failed"); return;
public void onConfigurationFetched(Configuration configuration) { if (!configuration.isThreeDSecureEnabled()) { fragment.postCallback(new BraintreeException("Three D Secure is not enabled in the control panel")); return; fragment.postCallback(new BraintreeException("ThreeDSecureWebViewActivity is not declared in " + "AndroidManifest.xml")); return;
fragment.postCallback(new BraintreeException("A client token with a customer id must be used to delete a payment method nonce.")); return; fragment.postCallback(new BraintreeException("Payment Method Nonce deletion is not supported for API < 21")); return; "DeletePaymentMethodFromSingleUseToken"); } catch (Resources.NotFoundException | IOException | JSONException e) { fragment.postCallback(new BraintreeException("Unable to read GraphQL query"));
/** * Starts the Billing Agreement 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. * @param handler A {@link PayPalApprovalHandler} for custom approval handling. */ public static void requestBillingAgreement(BraintreeFragment fragment, PayPalRequest request, PayPalApprovalHandler handler) { if (request.getAmount() == null) { fragment.sendAnalyticsEvent("paypal.billing-agreement.selected"); if (request.shouldOfferCredit()) { fragment.sendAnalyticsEvent("paypal.billing-agreement.credit.offered"); } requestOneTimePayment(fragment, request, true, handler); } else { fragment.postCallback(new BraintreeException( "There must be no amount specified for the Billing Agreement flow")); } }
/** * 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.")); } }
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())); } } }
@Override public void onConfigurationFetched(Configuration configuration) { if (!configuration.isPayPalEnabled()) { fragment.postCallback(new BraintreeException("PayPal is not enabled")); return; } if (!isManifestValid(fragment)) { fragment.sendAnalyticsEvent("paypal.invalid-manifest"); fragment.postCallback(new BraintreeException("BraintreeBrowserSwitchActivity missing, " + "incorrectly configured in AndroidManifest.xml or another app defines the same browser " + "switch url as this app. See " + "https://developers.braintreepayments.com/guides/client-sdk/android/v2#browser-switch " + "for the correct configuration")); return; } if (configuration.getPayPal().shouldUseBillingAgreement() && !sFuturePaymentsOverride) { requestBillingAgreement(fragment, new PayPalRequest()); return; } fragment.sendAnalyticsEvent("paypal.future-payments.selected"); AuthorizationRequest request = getAuthorizationRequest(fragment); if (additionalScopes != null) { for (String scope : additionalScopes) { request.withScopeValue(scope); } } startPayPal(fragment, request, null); } });
@Override public void onConfigurationFetched(Configuration configuration) { if (!configuration.isThreeDSecureEnabled()) { fragment.postCallback(new BraintreeException("Three D Secure is not enabled in the control panel")); return; fragment.postCallback(new BraintreeException("ThreeDSecureWebViewActivity is not declared in " + "AndroidManifest.xml")); return;
@Test public void enroll_sendsAnalyticsEventOnFailure() throws JSONException { UnionPayCardBuilder unionPayCardBuilder = new UnionPayCardBuilder() .cardNumber("some-card-number"); BraintreeFragment braintreeFragment = new MockFragmentBuilder() .configuration(mConfigurationWithUnionPay) .errorResponse(new BraintreeException()) .build(); UnionPay.enroll(braintreeFragment, unionPayCardBuilder); verify(braintreeFragment).sendAnalyticsEvent("union-pay.enrollment-failed"); }