@Test public void getHeaders_withOnlyRequiredOptions_doesNotAddEmptyOptions() { RequestOptions requestOptions = RequestOptions.builder("some_key").build(); Map<String, String> headerMap = StripeApiHandler.getHeaders(requestOptions); assertNotNull(headerMap); assertFalse(headerMap.containsKey("Idempotency-Key")); assertFalse(headerMap.containsKey("Stripe-Version")); assertFalse(headerMap.containsKey("Stripe-Account")); assertTrue(headerMap.containsKey("Authorization")); }
static Map<String, String> getHeaders(RequestOptions options) { Map<String, String> headers = new HashMap<>(); headers.put("Accept-Charset", CHARSET); headers.put("Accept", "application/json"); headers.put("User-Agent", String.format("Stripe/v1 AndroidBindings/%s", BuildConfig.VERSION_NAME)); if (options != null) { headers.put("Authorization", String.format(Locale.ENGLISH, "Bearer %s", options.getPublishableApiKey())); } Map<String, String> propertyMap = new HashMap<>(); final String systemPropertyName = "java.version"; propertyMap.put(systemPropertyName, System.getProperty(systemPropertyName)); propertyMap.put("os.name", "android"); propertyMap.put("os.version", String.valueOf(Build.VERSION.SDK_INT)); propertyMap.put("bindings.version", BuildConfig.VERSION_NAME); propertyMap.put("lang", "Java"); propertyMap.put("publisher", "Stripe"); JSONObject headerMappingObject = new JSONObject(propertyMap); headers.put("X-Stripe-Client-User-Agent", headerMappingObject.toString()); if (options != null && options.getApiVersion() != null) { headers.put("Stripe-Version", options.getApiVersion()); } if (options != null && options.getStripeAccount() != null) { headers.put("Stripe-Account", options.getStripeAccount()); } if (options != null && options.getIdempotencyKey() != null) { headers.put("Idempotency-Key", options.getIdempotencyKey()); } return headers; }
StripeApiHandler { static Map<String, String> getHeaders(RequestOptions options) { Map<String, String> headers = new HashMap<>(); headers.put("Accept-Charset", CHARSET); headers.put("Accept", "application/json"); headers.put("User-Agent", String.format("Stripe/v1 AndroidBindings/%s", BuildConfig.VERSION_NAME)); if (options != null) { headers.put("Authorization", String.format(Locale.ENGLISH, "Bearer %s", options.getPublishableApiKey())); } Map<String, String> propertyMap = new HashMap<>(); final String systemPropertyName = "java.version"; propertyMap.put(systemPropertyName, System.getProperty(systemPropertyName)); propertyMap.put("os.name", "android"); propertyMap.put("os.version", String.valueOf(Build.VERSION.SDK_INT)); propertyMap.put("bindings.version", BuildConfig.VERSION_NAME); propertyMap.put("lang", "Java"); propertyMap.put("publisher", "Stripe"); JSONObject headerMappingObject = new JSONObject(propertyMap); headers.put("X-Stripe-Client-User-Agent", headerMappingObject.toString()); if (options != null && options.getApiVersion() != null) { headers.put("Stripe-Version", options.getApiVersion()); } if (options != null && options.getStripeAccount() != null) { headers.put("Stripe-Account", options.getStripeAccount()); } if (options != null && options.getIdempotencyKey() != null) { headers.put("Idempotency-Key", options.getIdempotencyKey()); } return headers; } }
StripeApiHandler { static Map<String, String> getHeaders(RequestOptions options) { Map<String, String> headers = new HashMap<>(); headers.put("Accept-Charset", CHARSET); headers.put("Accept", "application/json"); headers.put("User-Agent", String.format("Stripe/v1 AndroidBindings/%s", BuildConfig.VERSION_NAME)); if (options != null) { headers.put("Authorization", String.format(Locale.ENGLISH, "Bearer %s", options.getPublishableApiKey())); } Map<String, String> propertyMap = new HashMap<>(); final String systemPropertyName = "java.version"; propertyMap.put(systemPropertyName, System.getProperty(systemPropertyName)); propertyMap.put("os.name", "android"); propertyMap.put("os.version", String.valueOf(Build.VERSION.SDK_INT)); propertyMap.put("bindings.version", BuildConfig.VERSION_NAME); propertyMap.put("lang", "Java"); propertyMap.put("publisher", "Stripe"); JSONObject headerMappingObject = new JSONObject(propertyMap); headers.put("X-Stripe-Client-User-Agent", headerMappingObject.toString()); if (options != null && options.getApiVersion() != null) { headers.put("Stripe-Version", options.getApiVersion()); } if (options != null && options.getStripeAccount() != null) { headers.put("Stripe-Account", options.getStripeAccount()); } if (options != null && options.getIdempotencyKey() != null) { headers.put("Idempotency-Key", options.getIdempotencyKey()); } return headers; }  }
StripeApiHandler { static Map<String, String> getHeaders(RequestOptions options) { Map<String, String> headers = new HashMap<>(); headers.put("Accept-Charset", CHARSET); headers.put("Accept", "application/json"); headers.put("User-Agent", String.format("Stripe/v1 AndroidBindings/%s", BuildConfig.VERSION_NAME)); if (options != null) { headers.put("Authorization", String.format(Locale.ENGLISH, "Bearer %s", options.getPublishableApiKey())); } Map<String, String> propertyMap = new HashMap<>(); final String systemPropertyName = "java.version"; propertyMap.put(systemPropertyName, System.getProperty(systemPropertyName)); propertyMap.put("os.name", "android"); propertyMap.put("os.version", String.valueOf(Build.VERSION.SDK_INT)); propertyMap.put("bindings.version", BuildConfig.VERSION_NAME); propertyMap.put("lang", "Java"); propertyMap.put("publisher", "Stripe"); JSONObject headerMappingObject = new JSONObject(propertyMap); headers.put("X-Stripe-Client-User-Agent", headerMappingObject.toString()); if (options != null && options.getApiVersion() != null) { headers.put("Stripe-Version", options.getApiVersion()); } if (options != null && options.getStripeAccount() != null) { headers.put("Stripe-Account", options.getStripeAccount()); } if (options != null && options.getIdempotencyKey() != null) { headers.put("Idempotency-Key", options.getIdempotencyKey()); } return headers; }   }
StripeApiHandler { static Map<String, String> getHeaders(RequestOptions options) { Map<String, String> headers = new HashMap<>(); headers.put("Accept-Charset", CHARSET); headers.put("Accept", "application/json"); headers.put("User-Agent", String.format("Stripe/v1 AndroidBindings/%s", BuildConfig.VERSION_NAME)); if (options != null) { headers.put("Authorization", String.format(Locale.ENGLISH, "Bearer %s", options.getPublishableApiKey())); } Map<String, String> propertyMap = new HashMap<>(); final String systemPropertyName = "java.version"; propertyMap.put(systemPropertyName, System.getProperty(systemPropertyName)); propertyMap.put("os.name", "android"); propertyMap.put("os.version", String.valueOf(Build.VERSION.SDK_INT)); propertyMap.put("bindings.version", BuildConfig.VERSION_NAME); propertyMap.put("lang", "Java"); propertyMap.put("publisher", "Stripe"); JSONObject headerMappingObject = new JSONObject(propertyMap); headers.put("X-Stripe-Client-User-Agent", headerMappingObject.toString()); if (options != null && options.getApiVersion() != null) { headers.put("Stripe-Version", options.getApiVersion()); } if (options != null && options.getStripeAccount() != null) { headers.put("Stripe-Account", options.getStripeAccount()); } if (options != null && options.getIdempotencyKey() != null) { headers.put("Idempotency-Key", options.getIdempotencyKey()); } return headers; }    }