/** * Collect device information for fraud identification purposes. * * @param fragment {@link BraintreeFragment} * @param listener to be called with the device data String to send to Braintree. */ public static void collectDeviceData(BraintreeFragment fragment, BraintreeResponseListener<String> listener) { collectDeviceData(fragment, null, listener); }
/** * @deprecated Use {@link #collectDeviceData(BraintreeFragment, String, BraintreeResponseListener)} instead. */ @Deprecated public static String collectDeviceData(BraintreeFragment fragment, String merchantId) { JSONObject deviceData = new JSONObject(); try { String deviceSessionId = UUIDHelper.getFormattedUUID(); startDeviceCollector(fragment, merchantId, deviceSessionId, null); deviceData.put(DEVICE_SESSION_ID_KEY, deviceSessionId); deviceData.put(FRAUD_MERCHANT_ID_KEY, merchantId); } catch (ClassNotFoundException | NoClassDefFoundError | NumberFormatException | JSONException ignored) {} try { String clientMetadataId = getPayPalClientMetadataId(fragment.getApplicationContext()); if (!TextUtils.isEmpty(clientMetadataId)) { deviceData.put(CORRELATION_ID_KEY, clientMetadataId); } } catch (JSONException ignored) {} return deviceData.toString(); }
@Override public void success(PaymentMethodNonce paymentMethodNonce) { DataCollector.collectRiskData(fragment, paymentMethodNonce); fragment.postCallback(paymentMethodNonce); fragment.sendAnalyticsEvent("card.nonce-received"); }
/** * Collect PayPal device information for fraud identification purposes. * * @param fragment {@link BraintreeFragment} * @param listener listener to be called with the device data String to send to Braintree. */ public static void collectPayPalDeviceData(final BraintreeFragment fragment, final BraintreeResponseListener<String> listener) { final JSONObject deviceData = new JSONObject(); try { String clientMetadataId = getPayPalClientMetadataId(fragment.getApplicationContext()); if (!TextUtils.isEmpty(clientMetadataId)) { deviceData.put(CORRELATION_ID_KEY, clientMetadataId); } } catch (JSONException ignored) {} listener.onResponse(deviceData.toString()); }
@Test public void getDeviceCollectorEnvironment_returnsCorrectEnvironment() { assertEquals(com.kount.api.DataCollector.ENVIRONMENT_PRODUCTION, DataCollector.getDeviceCollectorEnvironment("production")); assertEquals(com.kount.api.DataCollector.ENVIRONMENT_TEST, DataCollector.getDeviceCollectorEnvironment("sandbox")); }
@Test public void collectPayPalDeviceData() throws JSONException, InterruptedException { final BraintreeFragment fragment = new MockFragmentBuilder().build(); final CountDownLatch latch = new CountDownLatch(1); DataCollector.collectPayPalDeviceData(fragment, new BraintreeResponseListener<String>() { @Override public void onResponse(String s) { try { JSONObject json = new JSONObject(s); assertNotNull(json.getString("correlation_id")); } catch (JSONException e) { fail(); } latch.countDown(); } }); latch.await(); } }
@Test public void getPayPalClientMetadataId_returnsClientMetadataId() { String clientMetadataId = DataCollector.getPayPalClientMetadataId(RuntimeEnvironment.application); assertFalse(TextUtils.isEmpty(clientMetadataId)); }
@Override public void onConfigurationFetched(Configuration configuration) { final com.kount.api.DataCollector dataCollector = com.kount.api.DataCollector.getInstance(); dataCollector.setContext(fragment.getApplicationContext()); dataCollector.setMerchantID(Integer.parseInt(merchantId)); dataCollector.setLocationCollectorConfig(com.kount.api.DataCollector.LocationConfig.COLLECT); dataCollector.setEnvironment(getDeviceCollectorEnvironment(configuration.getEnvironment())); dataCollector.collectForSession(deviceSessionId, new com.kount.api.DataCollector.CompletionHandler() { @Override public void completed(String sessionID) { fragment.sendAnalyticsEvent("data-collector.kount.succeeded"); if (listener != null) { listener.onResponse(sessionID); } } @Override public void failed(String sessionID, final com.kount.api.DataCollector.Error error) { fragment.sendAnalyticsEvent("data-collector.kount.failed"); if (listener != null) { listener.onResponse(sessionID); } } }); } });
/** * @deprecated Use {@link #collectDeviceData(BraintreeFragment)} instead. */ @Deprecated public static String collectDeviceData(Context context, BraintreeFragment fragment) { return collectDeviceData(fragment); }
String clientMetadataId = getPayPalClientMetadataId(fragment.getApplicationContext()); if (!TextUtils.isEmpty(clientMetadataId)) { deviceData.put(CORRELATION_ID_KEY, clientMetadataId);
/** * @deprecated Use {@link #collectDeviceData(BraintreeFragment, BraintreeResponseListener)} instead. */ @Deprecated public static String collectDeviceData(BraintreeFragment fragment) { return collectDeviceData(fragment, BRAINTREE_MERCHANT_ID); }
/** * @deprecated Use {@link #collectDeviceData(BraintreeFragment, String)} instead. */ @Deprecated public static String collectDeviceData(Context context, BraintreeFragment fragment, String merchantId) { return collectDeviceData(fragment, merchantId); }
@Override public void onConfigurationFetched(Configuration configuration) { if (getIntent().getBooleanExtra(MainActivity.EXTRA_COLLECT_DEVICE_DATA, false)) { DataCollector.collectDeviceData(mBraintreeFragment, new BraintreeResponseListener<String>() { @Override public void onResponse(String deviceData) { mDeviceData = deviceData; } }); } }
@Test public void collectDeviceData() throws JSONException { BraintreeFragment fragment = new MockFragmentBuilder().build(); String deviceData = DataCollector.collectDeviceData(fragment); JSONObject json = new JSONObject(deviceData); assertFalse(TextUtils.isEmpty(json.getString("device_session_id"))); assertEquals("600000", json.getString("fraud_merchant_id")); assertNotNull(json.getString("correlation_id")); }
@Test public void collectDeviceData_usesDirectMerchantId() throws JSONException { BraintreeFragment fragment = new MockFragmentBuilder().build(); String deviceData = DataCollector.collectDeviceData(fragment, "100"); JSONObject json = new JSONObject(deviceData); assertFalse(TextUtils.isEmpty(json.getString("device_session_id"))); assertEquals("100", json.getString("fraud_merchant_id")); }
@Test(timeout = 1000) public void collectDeviceData_doesNotCollectKountDataIfKountDisabledInConfiguration() throws InterruptedException { BraintreeFragment fragment = getFragmentWithConfiguration(mActivity, new TestConfigurationBuilder().build()); DataCollector.collectDeviceData(fragment, new BraintreeResponseListener<String>() { @Override public void onResponse(String deviceData) { try { JSONObject json = new JSONObject(deviceData); assertNull(Json.optString(json, "device_session_id", null)); assertNull(Json.optString(json, "fraud_merchant_id", null)); assertNotNull(json.getString("correlation_id")); } catch (JSONException e) { fail(e.getMessage()); } mCountDownLatch.countDown(); } }); mCountDownLatch.await(); } }
@Override public void onConfigurationFetched(Configuration configuration) { mConfiguration = configuration; mCardForm.cardRequired(true) .expirationRequired(true) .cvvRequired(configuration.isCvvChallengePresent()) .postalCodeRequired(configuration.isPostalCodeChallengePresent()) .mobileNumberRequired(false) .actionLabel(getString(R.string.purchase)) .setup(this); if (getIntent().getBooleanExtra(MainActivity.EXTRA_COLLECT_DEVICE_DATA, false)) { DataCollector.collectDeviceData(mBraintreeFragment, new BraintreeResponseListener<String>() { @Override public void onResponse(String deviceData) { mDeviceData = deviceData; } }); } }
@Test(timeout = 10000) public void collectDeviceData_withListener() throws InterruptedException { String configuration = new TestConfigurationBuilder() .kount(new TestKountConfigurationBuilder() .kountMerchantId("500000")) .build(); BraintreeFragment fragment = getFragmentWithConfiguration(mActivity, configuration); DataCollector.collectDeviceData(fragment, new BraintreeResponseListener<String>() { @Override public void onResponse(String deviceData) { try { JSONObject json = new JSONObject(deviceData); assertFalse(TextUtils.isEmpty(json.getString("device_session_id"))); assertEquals("500000", json.getString("fraud_merchant_id")); assertNotNull(json.getString("correlation_id")); } catch (JSONException e) { fail(e.getMessage()); } mCountDownLatch.countDown(); } }); mCountDownLatch.await(); }
@Test(timeout = 10000) public void collectDeviceData_withListener_usesDirectMerchantId() throws InterruptedException { String configuration = new TestConfigurationBuilder() .kount(new TestKountConfigurationBuilder() .kountMerchantId("600000")) .build(); BraintreeFragment fragment = getFragmentWithConfiguration(mActivity, configuration); DataCollector.collectDeviceData(fragment, "600001", new BraintreeResponseListener<String>() { @Override public void onResponse(String deviceData) { try { JSONObject json = new JSONObject(deviceData); assertFalse(TextUtils.isEmpty(json.getString("device_session_id"))); assertEquals("600001", json.getString("fraud_merchant_id")); assertNotNull(json.getString("correlation_id")); } catch (JSONException e) { fail(e.getMessage()); } mCountDownLatch.countDown(); } }); mCountDownLatch.await(); }
com.kount.api.DataCollector.getInstance(); DataCollector.collectDeviceData(fragment, new BraintreeResponseListener<String>() { @Override public void onResponse(String s) {