Search in sources :

Example 1 with BraintreeResponseListener

use of com.braintreepayments.api.interfaces.BraintreeResponseListener in project braintree_android by braintree.

the class DataCollector method collectDeviceData.

/**
 * Collect device information for fraud identification purposes. This should be used in conjunction
 * with a non-aggregate fraud id.
 *
 * @param fragment {@link BraintreeFragment}
 * @param merchantId The fraud merchant id from Braintree.
 * @param listener listener to be called with the device data String to send to Braintree.
 */
public static void collectDeviceData(final BraintreeFragment fragment, final String merchantId, final BraintreeResponseListener<String> listener) {
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            final JSONObject deviceData = new JSONObject();
            try {
                String clientMetadataId = getPayPalClientMetadataId(fragment.getApplicationContext());
                if (!TextUtils.isEmpty(clientMetadataId)) {
                    deviceData.put(CORRELATION_ID_KEY, clientMetadataId);
                }
            } catch (JSONException ignored) {
            }
            if (configuration.getKount().isEnabled()) {
                final String id;
                if (merchantId != null) {
                    id = merchantId;
                } else {
                    id = configuration.getKount().getKountMerchantId();
                }
                try {
                    final String deviceSessionId = UUIDHelper.getFormattedUUID();
                    startDeviceCollector(fragment, id, deviceSessionId, new BraintreeResponseListener<String>() {

                        @Override
                        public void onResponse(String sessionId) {
                            try {
                                deviceData.put(DEVICE_SESSION_ID_KEY, deviceSessionId);
                                deviceData.put(FRAUD_MERCHANT_ID_KEY, id);
                            } catch (JSONException ignored) {
                            }
                            listener.onResponse(deviceData.toString());
                        }
                    });
                } catch (ClassNotFoundException | NoClassDefFoundError | NumberFormatException ignored) {
                    listener.onResponse(deviceData.toString());
                }
            } else {
                listener.onResponse(deviceData.toString());
            }
        }
    });
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) BraintreeResponseListener(com.braintreepayments.api.interfaces.BraintreeResponseListener) Configuration(com.braintreepayments.api.models.Configuration) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException)

Aggregations

BraintreeResponseListener (com.braintreepayments.api.interfaces.BraintreeResponseListener)1 ConfigurationListener (com.braintreepayments.api.interfaces.ConfigurationListener)1 Configuration (com.braintreepayments.api.models.Configuration)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1