private boolean isPayPalInstalled(Context context) { try { Class.forName(PayPalOneTouchCore.class.getName()); return PayPalOneTouchCore.isWalletAppInstalled(context); } catch (ClassNotFoundException | NoClassDefFoundError ignored) { return false; } } }
public CheckoutRequest pairingId(Context context, String pairingId) { mPairingId = pairingId; clientMetadataId(PayPalOneTouchCore.getClientMetadataId(context, pairingId)); return this; }
public static FptiManager getFptiManager(Context context) { initService(context); return sFptiManager; }
initService(context); isWalletAppInstalled(context);
@Override protected void onResume() { super.onResume(); if (!mActionBarSetup) { setupActionBar(); mActionBarSetup = true; } SignatureVerificationOverrides.disableAppSwitchSignatureVerification( Settings.isPayPalSignatureVerificationDisabled(this)); PayPalOneTouchCore.useHardcodedConfig(this, Settings.useHardcodedPayPalConfiguration(this)); if (BuildConfig.DEBUG && ContextCompat.checkSelfPermission(this, WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{ WRITE_EXTERNAL_STORAGE }, 1); } else { handleAuthorizationState(); } }
@Override public void trackFpti(Context context, TrackingPoint trackingPoint, Protocol protocol) { String ecToken = Uri.parse(mApprovalUrl).getQueryParameter(mTokenQueryParamKey); Map<String, String> fptiDataBundle = new HashMap<>(); fptiDataBundle.put("fltk", ecToken); fptiDataBundle.put("clid", getClientId()); PayPalOneTouchCore.getFptiManager(context) .trackFpti(trackingPoint, getEnvironment(), fptiDataBundle, protocol); }
private static void initService(Context context) { if (sConfigManager == null || sFptiManager == null) { PayPalHttpClient httpClient = new PayPalHttpClient() .setBaseUrl(EnvironmentManager.LIVE_API_M_ENDPOINT); sConfigManager = new ConfigManager(getContextInspector(context), httpClient); sFptiManager = new FptiManager(getContextInspector(context), httpClient); } // always refresh configuration sConfigManager.refreshConfiguration(); }
@Override public void handleApproval(Request request, PayPalApprovalCallback paypalApprovalCallback) { PendingRequest pendingRequest = PayPalOneTouchCore.getStartIntent(fragment.getApplicationContext(), request); if (pendingRequest.isSuccess() && pendingRequest.getRequestTarget() == RequestTarget.wallet) { sendAnalyticsForPayPal(fragment, request, true, RequestTarget.wallet); fragment.startActivityForResult(pendingRequest.getIntent(), BraintreeRequestCodes.PAYPAL); } else if (pendingRequest.isSuccess() && pendingRequest.getRequestTarget() == RequestTarget.browser) { sendAnalyticsForPayPal(fragment, request, true, RequestTarget.browser); fragment.browserSwitch(BraintreeRequestCodes.PAYPAL, pendingRequest.getIntent()); } else { sendAnalyticsForPayPal(fragment, request, false, null); } } };
@Override protected void onResume() { super.onResume(); if (!mActionBarSetup) { setupActionBar(); mActionBarSetup = true; } SignatureVerificationOverrides.disableAppSwitchSignatureVerification( Settings.isPayPalSignatureVerificationDisabled(this)); PayPalOneTouchCore.useHardcodedConfig(this, Settings.useHardcodedPayPalConfiguration(this)); if (BuildConfig.DEBUG && ContextCompat.checkSelfPermission(this, WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{ WRITE_EXTERNAL_STORAGE }, 1); } else { handleAuthorizationState(); } }
@Override public void trackFpti(Context context, TrackingPoint trackingPoint, Protocol protocol) { Map<String, String> fptiDataBundle = new HashMap<>(); fptiDataBundle.put("clid", getClientId()); PayPalOneTouchCore.getFptiManager(context).trackFpti(trackingPoint, getEnvironment(), fptiDataBundle, protocol); }
@Override protected void onResume() { super.onResume(); mPayPalAppIndicator.setText(getString(R.string.paypal_wallet_available, PayPalOneTouchCore.isWalletAppInstalled(this))); }
/** * Collect device information for fraud identification purposes from PayPal only. * * @param context A valid {@link Context} * @return The client metadata id associated with the collected data. */ public static String getPayPalClientMetadataId(Context context) { try { return PayPalOneTouchCore.getClientMetadataId(context); } catch (NoClassDefFoundError ignored) {} try { return PayPalDataCollector.getClientMetadataId(context); } catch (NoClassDefFoundError ignored) {} return ""; }
public static void useHardcodedConfig(Context context, boolean useHardcodedConfig) { initService(context); sConfigManager.useHardcodedConfig(useHardcodedConfig); }
@Test public void createAnalyticsRequest_setsPropertiesCorrectly() throws JSONException { AnalyticsEvent analyticsEvent = new AnalyticsEvent(RuntimeEnvironment.application, "sessionId", "custom", "card.nonce-received"); assertEquals("android.custom.card.nonce-received", analyticsEvent.event); assertTrue(analyticsEvent.timestamp > 0); assertEquals("sessionId", analyticsEvent.metadata.getString("sessionId")); assertNotNull(analyticsEvent.metadata.getString("deviceNetworkType")); assertNotNull(analyticsEvent.metadata.getString("userInterfaceOrientation")); assertEquals(BuildConfig.VERSION_NAME, analyticsEvent.metadata.getString("merchantAppVersion")); assertEquals(PayPalOneTouchCore.isWalletAppInstalled(RuntimeEnvironment.application), analyticsEvent.metadata.getBoolean("paypalInstalled")); assertEquals(Venmo.isVenmoInstalled(RuntimeEnvironment.application), analyticsEvent.metadata.getBoolean("venmoInstalled")); } }
public AuthorizationRequest(Context context) { clientMetadataId(PayPalOneTouchCore.getClientMetadataId(context)); mMsgGuid = UUID.randomUUID().toString(); mEncryptionKey = mOtcCrypto.generateRandom256BitKey(); mAdditionalPayloadAttributes = new HashMap<>(); mScopes = new HashSet<>(); }
/** * Gets a {@link Result} from an {@link Intent} returned by either the PayPal Wallet app or * the browser. * * @param context * @param request the original {@link Request} that was used to get this {@link Result}. * @param data the {@link Intent} returned by either the PayPal Wallet app or the browser. * @return {@link Result} */ public static Result parseResponse(Context context, Request request, Intent data) { initService(context); if (data != null && data.getData() != null) { return BrowserSwitchHelper.parseBrowserSwitchResponse(sContextInspector, request, data.getData()); } else if (data != null && data.getExtras() != null && !data.getExtras().isEmpty()) { return AppSwitchHelper.parseAppSwitchResponse(sContextInspector, request, data); } else { request.trackFpti(context, TrackingPoint.Cancel, null); return new Result(); } }
assertEquals("sessionId", meta.getString("sessionId")); assertFalse(meta.getString("sessionId").contains("-")); assertEquals(PayPalOneTouchCore.isWalletAppInstalled(RuntimeEnvironment.application), meta.getBoolean("paypalInstalled")); assertEquals(Venmo.isVenmoInstalled(RuntimeEnvironment.application),
/** * @param context * @return {@code true} if the modern wallet app is installed (one that has either v1 or v2 touch * intents), {@code false} if the wallet app is older than the touch releases, or not present. */ public static boolean isWalletAppInstalled(Context context) { initService(context); for (OAuth2Recipe recipe : sConfigManager.getConfig().getOauth2Recipes()) { if (recipe.getTarget() == RequestTarget.wallet && recipe.isValidAppTarget(context)) { return true; } } return false; }