0

I'm trying to set up stripe connect (https://stripe.com/docs/connect/standalone-accounts) on my application, but I'm failing to set up the link between the platform and the standalone account. It provides a curl code to execute, and examples in ruby, python, PHP and node; but no java.

The curl call is as follows:

curl https://connect.stripe.com/oauth/token \ -d client_secret=sk_test_IgHHUgcqKmxA8Yyai9ocqpZR \ -d code=AUTHORIZATION_CODE \ -d grant_type=authorization_code

It looks pretty simple, but I have no idea how this works. I have been looking around trying to figure out how to make this call in java, and so far I haven't been able to.

Finally i got the correct code to run the curl command ,but it gives bunch of result.but i want only paricular id in it.how can i get that?

       `URL url = new URL("https://connect.stripe.com/oauth/token");
        Map<String,Object> params = new LinkedHashMap<>();
        params.put("client_secret",API_KEY);
        params.put("code", code);
        params.put("grant_type", "authorization_code");
        StringBuilder postData = new StringBuilder();
        for (Map.Entry<String,Object> param : params.entrySet()) {
            if (postData.length() != 0) postData.append('&');
            postData.append(URLEncoder.encode(param.getKey(), "UTF-8"));
            postData.append('=');
        postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
        }
        byte[] postDataBytes = postData.toString().getBytes("UTF-8");
        HttpURLConnection conn = (HttpURLConnection)url.openConnection();
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
        conn.setDoOutput(true);
        conn.getOutputStream().write(postDataBytes);

        Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
        StringBuilder sb = new StringBuilder();
        for (int c; (c = in.read()) >= 0;)
            sb.append((char)c);
        String response = sb.toString();`

and i got response={ "access_token": "xxxxxxxxxxxxxxxxx", "livemode": false, "refresh_token": "xxxxxxxxxxxxxxxxxxxxxxxt", "token_type": "bearer", "stripe_publishable_key": "xxxxxxxxxxxxxxxxxxxxxxxx", "stripe_user_id": "xxxxxxxxxxxxxxxxxxxxxxxxx", "scope": "express" }

how can i get only the stripe_user_id in java

1

3 Answers 3

0

The -d parameters in curl are for POST data (see the curl man page). POST is the method for sending form data (e.g. when you submit a web form). Rather than putting the parameters on the end of the URL, like you would in a GET request, the parameters are encoded and sent inside the "body" of the request.

Take a look at this answer or this one for various ways you can send POST data with requests from Java.

Alternatively, you could execute the curl process from Java. See this example.

Sign up to request clarification or add additional context in comments.

Comments

0

There are various ways to establish connections to outbound servers. Here is an example of a Stripe OAuth integration, using Apache HttpComponents.

Comments

0

I got an answer for that one using JSONObject,

JSONObject jObject  = new JSONObject(response);
 String stripe_user_id=(String) jObject.get("stripe_user_id");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.