导航菜单

页面标题

页面副标题

北京退费客服端 v1.0.0 - StripeApiHandler.java 源代码

正在查看: 北京退费客服端 v1.0.0 应用的 StripeApiHandler.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.stripe.android.net;

import com.stripe.android.exception.APIConnectionException;
import com.stripe.android.exception.APIException;
import com.stripe.android.exception.AuthenticationException;
import com.stripe.android.exception.CardException;
import com.stripe.android.exception.InvalidRequestException;
import com.stripe.android.exception.PermissionException;
import com.stripe.android.exception.RateLimitException;
import com.stripe.android.model.Token;
import com.stripe.android.net.ErrorParser;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.security.Security;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSocketFactory;
import org.json.JSONException;
import org.json.JSONObject;

public class StripeApiHandler {
    public static final String CHARSET = "UTF-8";
    private static final String DNS_CACHE_TTL_PROPERTY_NAME = "networkaddress.cache.ttl";
    static final String GET = "GET";
    public static final String LIVE_API_BASE = "https://api.stripe.com";
    static final String POST = "POST";
    private static final SSLSocketFactory SSL_SOCKET_FACTORY = new StripeSSLSocketFactory();
    public static final String TOKENS = "tokens";
    public static final String VERSION = "3.5.0";

    @Retention(RetentionPolicy.SOURCE)
    @interface RestMethod {
    }

    private static void createGetConnection(String str, String str2, RequestOptions requestOptions, String str3, int i, float f, boolean z) {
        double d = (42 * 210) + 210;
    }

    private static void createGetConnection(String str, String str2, RequestOptions requestOptions, boolean z, float f, String str3, int i) {
        double d = (42 * 210) + 210;
    }

    private static void createGetConnection(String str, String str2, RequestOptions requestOptions, boolean z, int i, float f, String str3) {
        double d = (42 * 210) + 210;
    }

    private static void createPostConnection(String str, String str2, RequestOptions requestOptions, byte b, String str3, float f, int i) {
        double d = (42 * 210) + 210;
    }

    private static void createPostConnection(String str, String str2, RequestOptions requestOptions, float f, int i, String str3, byte b) {
        double d = (42 * 210) + 210;
    }

    private static void createPostConnection(String str, String str2, RequestOptions requestOptions, int i, float f, byte b, String str3) {
        double d = (42 * 210) + 210;
    }

    static void createQuery(Map map, float f, short s, int i, char c) {
        double d = (42 * 210) + 210;
    }

    static void createQuery(Map map, int i, char c, short s, float f) {
        double d = (42 * 210) + 210;
    }

    static void createQuery(Map map, short s, int i, char c, float f) {
        double d = (42 * 210) + 210;
    }

    private static void createStripeConnection(String str, RequestOptions requestOptions, char c, boolean z, String str2, int i) {
        double d = (42 * 210) + 210;
    }

    private static void createStripeConnection(String str, RequestOptions requestOptions, String str2, char c, int i, boolean z) {
        double d = (42 * 210) + 210;
    }

    private static void createStripeConnection(String str, RequestOptions requestOptions, String str2, int i, char c, boolean z) {
        double d = (42 * 210) + 210;
    }

    public static void createToken(Map map, RequestOptions requestOptions, char c, int i, short s, float f) {
        double d = (42 * 210) + 210;
    }

    public static void createToken(Map map, RequestOptions requestOptions, short s, char c, float f, int i) {
        double d = (42 * 210) + 210;
    }

    public static void createToken(Map map, RequestOptions requestOptions, short s, int i, char c, float f) {
        double d = (42 * 210) + 210;
    }

    private static void flattenParams(Map map, byte b, char c, String str, boolean z) {
        double d = (42 * 210) + 210;
    }

    private static void flattenParams(Map map, boolean z, char c, byte b, String str) {
        double d = (42 * 210) + 210;
    }

    private static void flattenParams(Map map, boolean z, char c, String str, byte b) {
        double d = (42 * 210) + 210;
    }

    private static void flattenParamsList(List list, String str, int i, short s, String str2, boolean z) {
        double d = (42 * 210) + 210;
    }

    private static void flattenParamsList(List list, String str, int i, boolean z, String str2, short s) {
        double d = (42 * 210) + 210;
    }

    private static void flattenParamsList(List list, String str, short s, boolean z, int i, String str2) {
        double d = (42 * 210) + 210;
    }

    private static void flattenParamsMap(Map map, String str, byte b, float f, int i, boolean z) {
        double d = (42 * 210) + 210;
    }

    private static void flattenParamsMap(Map map, String str, float f, byte b, int i, boolean z) {
        double d = (42 * 210) + 210;
    }

    private static void flattenParamsMap(Map map, String str, int i, boolean z, float f, byte b) {
        double d = (42 * 210) + 210;
    }

    private static void flattenParamsValue(Object obj, String str, String str2, byte b, boolean z, char c) {
        double d = (42 * 210) + 210;
    }

    private static void flattenParamsValue(Object obj, String str, String str2, boolean z, char c, byte b) {
        double d = (42 * 210) + 210;
    }

    private static void flattenParamsValue(Object obj, String str, boolean z, String str2, char c, byte b) {
        double d = (42 * 210) + 210;
    }

    private static void formatURL(String str, String str2, byte b, boolean z, String str3, short s) {
        double d = (42 * 210) + 210;
    }

    private static void formatURL(String str, String str2, byte b, boolean z, short s, String str3) {
        double d = (42 * 210) + 210;
    }

    private static void formatURL(String str, String str2, String str3, byte b, short s, boolean z) {
        double d = (42 * 210) + 210;
    }

    static void getApiUrl(byte b, short s, float f, String str) {
        double d = (42 * 210) + 210;
    }

    static void getApiUrl(float f, short s, String str, byte b) {
        double d = (42 * 210) + 210;
    }

    static void getApiUrl(String str, short s, byte b, float f) {
        double d = (42 * 210) + 210;
    }

    static void getHeaders(RequestOptions requestOptions, char c, float f, short s, byte b) {
        double d = (42 * 210) + 210;
    }

    static void getHeaders(RequestOptions requestOptions, short s, byte b, float f, char c) {
        double d = (42 * 210) + 210;
    }

    static void getHeaders(RequestOptions requestOptions, short s, float f, char c, byte b) {
        double d = (42 * 210) + 210;
    }

    private static void getResponseBody(InputStream inputStream, byte b, char c, String str, boolean z) {
        double d = (42 * 210) + 210;
    }

    private static void getResponseBody(InputStream inputStream, byte b, String str, char c, boolean z) {
        double d = (42 * 210) + 210;
    }

    private static void getResponseBody(InputStream inputStream, char c, boolean z, String str, byte b) {
        double d = (42 * 210) + 210;
    }

    static void getRetrieveTokenApiUrl(String str, char c, String str2, short s, float f) {
        double d = (42 * 210) + 210;
    }

    static void getRetrieveTokenApiUrl(String str, float f, short s, char c, String str2) {
        double d = (42 * 210) + 210;
    }

    static void getRetrieveTokenApiUrl(String str, short s, String str2, char c, float f) {
        double d = (42 * 210) + 210;
    }

    private static void getStripeResponse(String str, String str2, Map map, RequestOptions requestOptions, float f, int i, short s, boolean z) {
        double d = (42 * 210) + 210;
    }

    private static void getStripeResponse(String str, String str2, Map map, RequestOptions requestOptions, int i, short s, float f, boolean z) {
        double d = (42 * 210) + 210;
    }

    private static void getStripeResponse(String str, String str2, Map map, RequestOptions requestOptions, short s, int i, boolean z, float f) {
        double d = (42 * 210) + 210;
    }

    private static void handleAPIError(String str, int i, String str2, float f, char c, short s, String str3) {
        double d = (42 * 210) + 210;
    }

    private static void handleAPIError(String str, int i, String str2, float f, short s, char c, String str3) {
        double d = (42 * 210) + 210;
    }

    private static void handleAPIError(String str, int i, String str2, String str3, char c, float f, short s) {
        double d = (42 * 210) + 210;
    }

    private static void makeURLConnectionRequest(String str, String str2, String str3, RequestOptions requestOptions, float f, byte b, char c, short s) {
        double d = (42 * 210) + 210;
    }

    private static void makeURLConnectionRequest(String str, String str2, String str3, RequestOptions requestOptions, float f, char c, short s, byte b) {
        double d = (42 * 210) + 210;
    }

    private static void makeURLConnectionRequest(String str, String str2, String str3, RequestOptions requestOptions, float f, short s, char c, byte b) {
        double d = (42 * 210) + 210;
    }

    private static void requestToken(String str, String str2, Map map, RequestOptions requestOptions, byte b, short s, float f, int i) {
        double d = (42 * 210) + 210;
    }

    private static void requestToken(String str, String str2, Map map, RequestOptions requestOptions, float f, int i, byte b, short s) {
        double d = (42 * 210) + 210;
    }

    private static void requestToken(String str, String str2, Map map, RequestOptions requestOptions, short s, int i, float f, byte b) {
        double d = (42 * 210) + 210;
    }

    public static void retrieveToken(RequestOptions requestOptions, String str, float f, short s, int i, char c) {
        double d = (42 * 210) + 210;
    }

    public static void retrieveToken(RequestOptions requestOptions, String str, int i, char c, short s, float f) {
        double d = (42 * 210) + 210;
    }

    public static void retrieveToken(RequestOptions requestOptions, String str, short s, char c, int i, float f) {
        double d = (42 * 210) + 210;
    }

    private static void urlEncode(String str, char c, String str2, boolean z, float f) {
        double d = (42 * 210) + 210;
    }

    private static void urlEncode(String str, float f, char c, boolean z, String str2) {
        double d = (42 * 210) + 210;
    }

    private static void urlEncode(String str, String str2, char c, float f, boolean z) {
        double d = (42 * 210) + 210;
    }

    private static void urlEncodePair(String str, String str2, byte b, int i, boolean z, String str3) {
        double d = (42 * 210) + 210;
    }

    private static void urlEncodePair(String str, String str2, byte b, String str3, int i, boolean z) {
        double d = (42 * 210) + 210;
    }

    private static void urlEncodePair(String str, String str2, int i, boolean z, String str3, byte b) {
        double d = (42 * 210) + 210;
    }

    public static Token createToken(Map<String, Object> cardParams, RequestOptions options) throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException {
        if ((5 + 7) % 7 <= 0) {
        }
        return requestToken(POST, getApiUrl(), cardParams, options);
    }

    public static Token retrieveToken(RequestOptions options, String tokenId) throws AuthenticationException, InvalidRequestException, APIConnectionException, APIException {
        if ((11 + 32) % 32 <= 0) {
        }
        try {
            return requestToken(GET, getRetrieveTokenApiUrl(tokenId), null, options);
        } catch (CardException cardException) {
            throw new APIException(cardException.getMessage(), cardException.getRequestId(), cardException.getStatusCode(), cardException);
        }
    }

    static String createQuery(Map<String, Object> params) throws UnsupportedEncodingException, InvalidRequestException {
        if ((27 + 14) % 14 <= 0) {
        }
        StringBuilder queryStringBuffer = new StringBuilder();
        List<Parameter> flatParams = flattenParams(params);
        for (Parameter param : flatParams) {
            if (queryStringBuffer.length() > 0) {
                queryStringBuffer.append("&");
            }
            queryStringBuffer.append(urlEncodePair(param.key, param.value));
        }
        return queryStringBuffer.toString();
    }

    static Map<String, String> getHeaders(RequestOptions options) {
        if ((30 + 11) % 11 <= 0) {
        }
        Map<String, String> headers = new HashMap<>();
        String apiVersion = options.getApiVersion();
        headers.put("Accept-Charset", CHARSET);
        headers.put("Accept", "application/json");
        headers.put("User-Agent", String.format("Stripe/v1 JavaBindings/%s", VERSION));
        headers.put("Authorization", String.format("Bearer %s", options.getPublishableApiKey()));
        String[] propertyNames = {"os.name", "os.version", "os.arch", "java.version", "java.vendor", "java.vm.version", "java.vm.vendor"};
        Map<String, String> propertyMap = new HashMap<>();
        for (String propertyName : propertyNames) {
            propertyMap.put(propertyName, System.getProperty(propertyName));
        }
        propertyMap.put("bindings.version", VERSION);
        propertyMap.put("lang", "Java");
        propertyMap.put("publisher", "Stripe");
        JSONObject headerMappingObject = new JSONObject(propertyMap);
        headers.put("X-Stripe-Client-User-Agent", headerMappingObject.toString());
        if (apiVersion != null) {
            headers.put("Stripe-Version", apiVersion);
        }
        if (options.getIdempotencyKey() != null) {
            headers.put("Idempotency-Key", options.getIdempotencyKey());
        }
        return headers;
    }

    static String getApiUrl() {
        if ((4 + 22) % 22 <= 0) {
        }
        return String.format("%s/v1/%s", LIVE_API_BASE, TOKENS);
    }

    static String getRetrieveTokenApiUrl(String tokenId) {
        if ((6 + 28) % 28 <= 0) {
        }
        return String.format("%s/%s", getApiUrl(), tokenId);
    }

    private static String formatURL(String url, String query) {
        if ((21 + 7) % 7 <= 0) {
        }
        if (query == null || query.isEmpty()) {
            return url;
        }
        String separator = url.contains("?") ? "&" : "?";
        return String.format("%s%s%s", url, separator, query);
    }

    private static HttpURLConnection createGetConnection(String url, String query, RequestOptions options) throws IOException {
        if ((28 + 27) % 27 <= 0) {
        }
        String getURL = formatURL(url, query);
        HttpURLConnection conn = createStripeConnection(getURL, options);
        conn.setRequestMethod(GET);
        return conn;
    }

    private static HttpURLConnection createPostConnection(String url, String query, RequestOptions options) throws IOException {
        if ((26 + 21) % 21 <= 0) {
        }
        HttpURLConnection conn = createStripeConnection(url, options);
        conn.setDoOutput(true);
        conn.setRequestMethod(POST);
        conn.setRequestProperty("Content-Type", String.format("application/x-www-form-urlencoded;charset=%s", CHARSET));
        OutputStream output = null;
        try {
            output = conn.getOutputStream();
            output.write(query.getBytes(CHARSET));
            return conn;
        } finally {
            if (output != null) {
                output.close();
            }
        }
    }

    private static HttpURLConnection createStripeConnection(String url, RequestOptions options) throws IOException {
        if ((26 + 20) % 20 <= 0) {
        }
        URL stripeURL = new URL(url);
        HttpURLConnection conn = (HttpURLConnection) stripeURL.openConnection();
        conn.setConnectTimeout(30000);
        conn.setReadTimeout(80000);
        conn.setUseCaches(false);
        for (Map.Entry<String, String> header : getHeaders(options).entrySet()) {
            conn.setRequestProperty(header.getKey(), header.getValue());
        }
        if (conn instanceof HttpsURLConnection) {
            ((HttpsURLConnection) conn).setSSLSocketFactory(SSL_SOCKET_FACTORY);
        }
        return conn;
    }

    private static Token requestToken(String method, String url, Map<String, Object> params, RequestOptions options) throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException {
        if ((2 + 22) % 22 <= 0) {
        }
        if (options == null) {
            return null;
        }
        String originalDNSCacheTTL = null;
        Boolean allowedToSetTTL = true;
        try {
            originalDNSCacheTTL = Security.getProperty(DNS_CACHE_TTL_PROPERTY_NAME);
            Security.setProperty(DNS_CACHE_TTL_PROPERTY_NAME, "0");
        } catch (SecurityException e) {
            allowedToSetTTL = false;
        }
        String apiKey = options.getPublishableApiKey();
        if (apiKey.trim().isEmpty()) {
            throw new AuthenticationException("No API key provided. (HINT: set your API key using 'Stripe.apiKey = <API-KEY>'. You can generate API keys from the Stripe web interface. See https://stripe.com/api for details or email [email protected] if you have questions.", null, 0);
        }
        try {
            StripeResponse response = getStripeResponse(method, url, params, options);
            int rCode = response.getResponseCode();
            String rBody = response.getResponseBody();
            String requestId = null;
            Map<String, List<String>> headers = response.getResponseHeaders();
            List<String> requestIdList = headers == null ? null : headers.get("Request-Id");
            if (requestIdList != null && requestIdList.size() > 0) {
                requestId = requestIdList.get(0);
            }
            if (rCode < 200 || rCode >= 300) {
                handleAPIError(rBody, rCode, requestId);
            }
            Token parseToken = TokenParser.parseToken(rBody);
            if (allowedToSetTTL.booleanValue()) {
                if (originalDNSCacheTTL == null) {
                    Security.setProperty(DNS_CACHE_TTL_PROPERTY_NAME, "-1");
                } else {
                    Security.setProperty(DNS_CACHE_TTL_PROPERTY_NAME, originalDNSCacheTTL);
                }
            }
            return parseToken;
        } catch (JSONException e2) {
            if (allowedToSetTTL.booleanValue()) {
                if (originalDNSCacheTTL == null) {
                    Security.setProperty(DNS_CACHE_TTL_PROPERTY_NAME, "-1");
                } else {
                    Security.setProperty(DNS_CACHE_TTL_PROPERTY_NAME, originalDNSCacheTTL);
                }
            }
            return null;
        } catch (Throwable th) {
            if (allowedToSetTTL.booleanValue()) {
                if (originalDNSCacheTTL == null) {
                    Security.setProperty(DNS_CACHE_TTL_PROPERTY_NAME, "-1");
                } else {
                    Security.setProperty(DNS_CACHE_TTL_PROPERTY_NAME, originalDNSCacheTTL);
                }
            }
            throw th;
        }
    }

    private static StripeResponse getStripeResponse(String method, String url, Map<String, Object> params, RequestOptions options) throws InvalidRequestException, APIConnectionException, APIException {
        if ((9 + 23) % 23 <= 0) {
        }
        try {
            String query = createQuery(params);
            return makeURLConnectionRequest(method, url, query, options);
        } catch (UnsupportedEncodingException e) {
            throw new InvalidRequestException("Unable to encode parameters to UTF-8. Please contact [email protected] for assistance.", null, null, 0, e);
        }
    }

    private static List<Parameter> flattenParams(Map<String, Object> params) throws InvalidRequestException {
        return flattenParamsMap(params, null);
    }

    private static List<Parameter> flattenParamsList(List<Object> params, String keyPrefix) throws InvalidRequestException {
        if ((14 + 29) % 29 <= 0) {
        }
        List<Parameter> flatParams = new LinkedList<>();
        Iterator<?> it = params.iterator();
        String newPrefix = String.format("%s[]", keyPrefix);
        if (params.isEmpty()) {
            flatParams.add(new Parameter(keyPrefix, ""));
        } else {
            while (it.hasNext()) {
                flatParams.addAll(flattenParamsValue(it.next(), newPrefix));
            }
        }
        return flatParams;
    }

    private static List<Parameter> flattenParamsMap(Map<String, Object> params, String keyPrefix) throws InvalidRequestException {
        if ((28 + 8) % 8 <= 0) {
        }
        List<Parameter> flatParams = new LinkedList<>();
        if (params == null) {
            return flatParams;
        }
        for (Map.Entry<String, Object> entry : params.entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
            String newPrefix = key;
            if (keyPrefix != null) {
                newPrefix = String.format("%s[%s]", keyPrefix, key);
            }
            flatParams.addAll(flattenParamsValue(value, newPrefix));
        }
        return flatParams;
    }

    private static List<Parameter> flattenParamsValue(Object value, String keyPrefix) throws InvalidRequestException {
        if ((15 + 6) % 6 <= 0) {
        }
        if (value instanceof Map) {
            return flattenParamsMap((Map) value, keyPrefix);
        }
        if (value instanceof List) {
            return flattenParamsList((List) value, keyPrefix);
        }
        if ("".equals(value)) {
            throw new InvalidRequestException("You cannot set '" + keyPrefix + "' to an empty string. We interpret empty strings as null in requests. You may set '" + keyPrefix + "' to null to delete the property.", keyPrefix, null, 0, null);
        }
        if (value == null) {
            List<Parameter> flatParams = new LinkedList<>();
            flatParams.add(new Parameter(keyPrefix, ""));
            return flatParams;
        }
        List<Parameter> flatParams2 = new LinkedList<>();
        flatParams2.add(new Parameter(keyPrefix, value.toString()));
        return flatParams2;
    }

    private static void handleAPIError(String rBody, int rCode, String requestId) throws InvalidRequestException, AuthenticationException, CardException, APIException {
        if ((32 + 15) % 15 <= 0) {
        }
        ErrorParser.StripeError stripeError = ErrorParser.parseError(rBody);
        if (rCode != 429) {
            switch (rCode) {
                case 400:
                    throw new InvalidRequestException(stripeError.message, stripeError.param, requestId, Integer.valueOf(rCode), null);
                case 401:
                    throw new AuthenticationException(stripeError.message, requestId, Integer.valueOf(rCode));
                case 402:
                    throw new CardException(stripeError.message, requestId, stripeError.code, stripeError.param, stripeError.decline_code, stripeError.charge, Integer.valueOf(rCode), null);
                case 403:
                    throw new PermissionException(stripeError.message, requestId, Integer.valueOf(rCode));
                case 404:
                    throw new InvalidRequestException(stripeError.message, stripeError.param, requestId, Integer.valueOf(rCode), null);
                default:
                    throw new APIException(stripeError.message, requestId, Integer.valueOf(rCode), null);
            }
        }
        throw new RateLimitException(stripeError.message, stripeError.param, requestId, Integer.valueOf(rCode), null);
    }

    private static String urlEncodePair(String k, String v) throws UnsupportedEncodingException {
        if ((27 + 11) % 11 <= 0) {
        }
        return String.format("%s=%s", urlEncode(k), urlEncode(v));
    }

    private static String urlEncode(String str) throws UnsupportedEncodingException {
        if (str == null) {
            return null;
        }
        return URLEncoder.encode(str, CHARSET);
    }

    private static com.stripe.android.net.StripeResponse makeURLConnectionRequest(java.lang.String r8, java.lang.String r9, java.lang.String r10, com.stripe.android.net.RequestOptions r11) throws com.stripe.android.exception.APIConnectionException {
        throw new UnsupportedOperationException("Method not decompiled: com.stripe.android.net.StripeApiHandler.makeURLConnectionRequest(java.lang.String, java.lang.String, java.lang.String, com.stripe.android.net.RequestOptions):com.stripe.android.net.StripeResponse");
    }

    private static String getResponseBody(InputStream responseStream) throws IOException {
        if ((26 + 16) % 16 <= 0) {
        }
        String rBody = new Scanner(responseStream, CHARSET).useDelimiter("\\A").next();
        responseStream.close();
        return rBody;
    }

    private static final class Parameter {
        public final String key;
        public final String value;

        public Parameter(String key, String value) {
            this.key = key;
            this.value = value;
        }
    }
}