All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.stripe.net.ApiRequestParams Maven / Gradle / Ivy

There is a newer version: 28.1.0-beta.3
Show newest version
package com.stripe.net;

import java.util.Map;

/**
 * Super class to all api request params objects. It exposes a convenient method converting the
 * typed parameter into the legacy support of untyped {@code Map} param.
 */
public abstract class ApiRequestParams {
  /**
   * Param key for an `extraParams` map. Any param/sub-param specifying a field intended to support
   * extra params from users should have the annotation
   * {@code @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY)}. Logic to handle this is in {@link
   * ApiRequestParamsConverter}.
   */
  public static final String EXTRA_PARAMS_KEY = "_stripe_java_extra_param_key";

  /** Converter mapping typed API request parameters into an untyped map. */
  private static final ApiRequestParamsConverter PARAMS_CONVERTER = new ApiRequestParamsConverter();

  /**
   * Interface implemented by all enum parameter to get the actual string value that Stripe API
   * expects. Internally, it used in custom serialization {@link ApiRequestParamsConverter}
   * converting empty string enum to null.
   */
  public interface EnumParam {
    String getValue();
  }

  /**
   * Convert `this` api request params to an untyped map. The conversion is specific to api request
   * params object. Please see documentation in {@link
   * ApiRequestParamsConverter#convert(ApiRequestParams)}.
   */
  public Map toMap() {
    return PARAMS_CONVERTER.convert(this);
  }

  /**
   * Convert `params` api request params to an untyped map. The conversion is specific to api
   * request params object. Please see documentation in {@link
   * ApiRequestParamsConverter#convert(ApiRequestParams)}.
   */
  public static Map paramsToMap(ApiRequestParams params) {
    if (params == null) {
      return null;
    }
    return params.toMap();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy