@Override public void run() { listener.onConfigurationFetched(getConfiguration()); } });
@Override public void run() { mConfigurationListener.onConfigurationFetched(getConfiguration()); } });
@Override public boolean shouldRun() { return getConfiguration() != null && isAdded(); }
@Nullable protected BraintreeApiHttpClient getBraintreeApiHttpClient() { if (mBraintreeApiClient == null && getConfiguration() != null && getConfiguration().getBraintreeApiConfiguration().isEnabled()) { mBraintreeApiClient = new BraintreeApiHttpClient(getConfiguration().getBraintreeApiConfiguration().getUrl(), getConfiguration().getBraintreeApiConfiguration().getAccessToken()); } return mBraintreeApiClient; }
private void flushAnalyticsEvents() { if (getConfiguration() != null && getConfiguration().toJson() != null && getConfiguration().getAnalytics().isEnabled()) { Intent intent = new Intent(mContext, AnalyticsIntentService.class) .putExtra(AnalyticsIntentService.EXTRA_AUTHORIZATION, getAuthorization().toString()) .putExtra(AnalyticsIntentService.EXTRA_CONFIGURATION, getConfiguration().toJson()); try { getApplicationContext().startService(intent); } catch (RuntimeException e) { AnalyticsSender.send(getApplicationContext(), mAuthorization, getHttpClient(), getConfiguration().getAnalytics().getUrl(), false); } } }
private static void launchBrowserSwitch(BraintreeFragment fragment, ThreeDSecureLookup threeDSecureLookup) { String assetsBaseUrl = fragment.getConfiguration().getAssetsUrl() + THREE_D_SECURE_ASSETS_PATH; String returnUrl = String.format("%s/redirect.html?redirect_url=%s://x-callback-url/braintree/threedsecure?", assetsBaseUrl, fragment.getReturnUrlScheme()); Uri redirectUri = Uri.parse(assetsBaseUrl + "/index.html") .buildUpon() .appendQueryParameter("AcsUrl", threeDSecureLookup.getAcsUrl()) .appendQueryParameter("PaReq", threeDSecureLookup.getPareq()) .appendQueryParameter("MD", threeDSecureLookup.getMd()) .appendQueryParameter("TermUrl", threeDSecureLookup.getTermUrl()) .appendQueryParameter("ReturnUrl", returnUrl) .build(); fragment.browserSwitch(BraintreeRequestCodes.THREE_D_SECURE, redirectUri.toString()); } }
public BraintreeFragment build() { BraintreeFragment fragment = mock(BraintreeFragment.class); when(fragment.getApplicationContext()).thenReturn(mContext); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { ((ConfigurationListener) invocation.getArguments()[0]).onConfigurationFetched(mConfiguration); return null; } }).when(fragment).waitForConfiguration(any(ConfigurationListener.class)); when(fragment.getConfiguration()).thenReturn(mConfiguration); when(fragment.getHttpClient()).thenReturn(mock(BraintreeHttpClient.class)); when(fragment.getGraphQLHttpClient()).thenReturn(mock(BraintreeGraphQLHttpClient.class)); return fragment; } }
@Test public void sendEvent_doesNothingIfAnalyticsNotEnabled() throws InvalidArgumentException { AnalyticsDatabase db = AnalyticsDatabase.getInstance(mActivity); BraintreeFragment fragment = spy(BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY)); when(fragment.getConfiguration()).thenReturn((Configuration) basicConfig()); fragment.sendAnalyticsEvent("test.event"); assertEquals(0, db.getPendingRequests().size()); }
@VisibleForTesting @Deprecated static AuthorizationRequest getAuthorizationRequest(BraintreeFragment fragment) { return populateRequestData(fragment, new AuthorizationRequest(fragment.getApplicationContext())) .privacyUrl(fragment.getConfiguration().getPayPal().getPrivacyUrl()) .userAgreementUrl(fragment.getConfiguration().getPayPal().getUserAgreementUrl()) .withScopeValue(SCOPE_FUTURE_PAYMENTS) .withScopeValue(SCOPE_EMAIL) .withAdditionalPayloadAttribute(PAYLOAD_CLIENT_TOKEN_KEY, fragment.getAuthorization().toString()); }
String currencyCode = request.getCurrencyCode(); if (currencyCode == null) { currencyCode = fragment.getConfiguration().getPayPal().getCurrencyIsoCode(); String displayName = request.getDisplayName(); if (TextUtils.isEmpty(displayName)) { displayName = fragment.getConfiguration().getPayPal().getDisplayName();
@Override public void onConfigurationFetched(Configuration configuration) { if (mRequestProtocol.equals(REST)) { try { JSONObject configJson = new JSONObject(configuration.toJson()); configJson.remove("graphQL"); fragment.setConfiguration(Configuration.fromJson(configJson.toString())); } catch (JSONException ignored) {} assertFalse(fragment.getConfiguration().getGraphQL().isEnabled()); } else if (mRequestProtocol.equals(GRAPHQL)) { assertTrue(configuration.getGraphQL().isEnabled()); } latch.countDown(); } });
@Test public void sendEvent_addsEventToDatabase() throws InvalidArgumentException { Configuration configuration = new TestConfigurationBuilder().withAnalytics().buildConfiguration(); BraintreeFragment fragment = spy(BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY)); when(fragment.getConfiguration()).thenReturn(configuration); fragment.sendAnalyticsEvent("test.event"); verifyAnalyticsEvent(mActivity, "test.event"); }
@Test public void getConfiguration_returnsConfiguration() throws InvalidArgumentException, JSONException { Configuration configuration = Configuration.fromJson(stringFromFixture("configuration/configuration.json")); mockConfigurationManager(configuration); BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY); assertEquals(configuration, fragment.getConfiguration()); }
@VisibleForTesting protected void fetchConfiguration() { if (getConfiguration() != null || ConfigurationManager.isFetchingConfiguration() || mAuthorization == null || mHttpClient == null) { return;
@Test public void onCreate_restoresConfigurationAndHttpClients() throws Exception { Configuration configuration = new TestConfigurationBuilder() .graphQL() .buildConfiguration(); mockConfigurationManager(configuration); BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY); Bundle bundle = new Bundle(); fragment.onSaveInstanceState(bundle); setField("mConfiguration", fragment, null); fragment.mHttpClient = null; fragment.onCreate(bundle); assertNotNull(fragment.getConfiguration()); assertNotNull(fragment.mHttpClient); assertNotNull(fragment.mGraphQLHttpClient); assertEquals("client_api_url", getField("mBaseUrl", fragment.mHttpClient)); }
private static <T extends Request> T populateRequestData(BraintreeFragment fragment, T request) { PayPalConfiguration paypalConfiguration = fragment.getConfiguration().getPayPal(); String environment; switch (paypalConfiguration.getEnvironment()) { case "live": environment = EnvironmentManager.LIVE; break; case "offline": environment = EnvironmentManager.MOCK; break; default: environment = paypalConfiguration.getEnvironment(); break; } String clientId = paypalConfiguration.getClientId(); if (clientId == null && EnvironmentManager.MOCK.equals(environment)) { clientId = "FAKE-PAYPAL-CLIENT-ID"; } request.environment(environment) .clientId(clientId) .cancelUrl(fragment.getReturnUrlScheme(), "cancel") .successUrl(fragment.getReturnUrlScheme(), "success"); return request; }
@Override public void onResume() { super.onResume(); if (getActivity() instanceof BraintreeListener) { addListener((BraintreeListener) getActivity()); if (mNewActivityNeedsConfiguration && getConfiguration() != null) { mNewActivityNeedsConfiguration = false; postConfigurationCallback(); } } flushCallbacks(); if (mGoogleApiClient != null && !mGoogleApiClient.isConnected() && !mGoogleApiClient.isConnecting()) { mGoogleApiClient.connect(); } }
mGoogleApiClient = new GoogleApiClient.Builder(getActivity()) .addApi(Wallet.API, new Wallet.WalletOptions.Builder() .setEnvironment(GooglePayment.getEnvironment(getConfiguration().getAndroidPay())) .setTheme(WalletConstants.THEME_LIGHT) .build())