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

vijay
  • 107
  • 1
  • 6
  • Possible duplicate of [Java - sending HTTP parameters via POST method easily](https://stackoverflow.com/questions/4205980/java-sending-http-parameters-via-post-method-easily) – Paul Roub Jun 30 '17 at 14:09

3 Answers3

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.

ᴇʟᴇvᴀтᴇ
  • 12,285
  • 4
  • 43
  • 66
0

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

Ywain
  • 16,854
  • 4
  • 51
  • 67
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");
vijay
  • 107
  • 1
  • 6