简体   繁体   English

使用 Stripe android + firebase 建立连接用户

[英]Making Connected User with stripe android + firebase

I'm very new to working with backend server stuff and nodejs.我对使用后端服务器的东西和 nodejs 很陌生。 I'm trying to set up Stripe with my app and now trying to create a Connected account with stripe.我正在尝试使用我的应用程序设置 Stripe,现在尝试使用 Stripe 创建一个 Connected 帐户。 Was following this https://stripe.com/docs/connect/collect-then-transfer-guide but I don't understand enough to make it work.正在关注此https://stripe.com/docs/connect/collect-then-transfer-guide但我不太了解以使其正常工作。 How do I get information from the server or send it through to make the account.我如何从服务器获取信息或发送它来创建帐户。

this is what I got so far这是我到目前为止所得到的


        binding.connectWithStripe.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String redirect = "https://www.example.com/connect-onboard-redirect";

                String url = "https://connect.stripe.com/express/oauth/authorize" +
                        "?client_id=" + "ca_Hdth53g5sheh4w4hwhw5h4weh5" +
                        "&state=" + 1234 +
                        "&redirect_uri=" + redirect;
                CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
                CustomTabsIntent customTabsIntent = builder.build();
                customTabsIntent.launchUrl(view.getContext(), Uri.parse(url));
            }
        });

const express = require('express');
const app = express();
app.use(express.json());
const { resolve } = require("path");

const stripe = require('stripe')('sk_test_xxxx');

app.get("/", (req, res) => {
  // Display landing page.
  const path = resolve("./index.html");
  res.sendFile(path);
});

app.get("/connect/oauth", async (req, res) => {
  const { code, state } = req.query;

  // Assert the state matches the state you provided in the OAuth link (optional).
  if(!stateMatches(state)) {
    return res.status(403).json({ error: 'Incorrect state parameter: ' + state });
  }

  // Send the authorization code to Stripe's API.
  stripe.oauth.token({
    grant_type: 'authorization_code',
    code
  }).then(
    (response) => {
      var connected_account_id = response.stripe_user_id;
      saveAccountId(connected_account_id);

      // Render some HTML or redirect to a different page.
      return res.status(200).json({success: true});
    },
    (err) => {
      if (err.type === 'StripeInvalidGrantError') {
        return res.status(400).json({error: 'Invalid authorization code: ' + code});
      } else {
        return res.status(500).json({error: 'An unknown error occurred.'});
      }
    }
  );
});

const stateMatches = (state_parameter) => {
  // Load the same state value that you randomly generated for your OAuth link.
  const saved_state = 'sv_53124';

  return saved_state == state_parameter;
}

const saveAccountId = (id) => {
  // Save the connected account ID from the response to your database.
  console.log('Connected account ID: ' + id);
}

app.listen(4242, () => console.log(`Node server listening on port ${4242}!`));

The sign up page opens and can enter the test info but after submiting it's not actually creating the account in Stripe dashboard.注册页面打开并可以输入测试信息,但提交后实际上并没有在 Stripe 仪表板中创建帐户。 Any help would be much appreciated任何帮助将非常感激

enter image description here在此处输入图片说明

After you complete the Express account sign up, Stripe redirects your customer to the redirect URI you specified on your Connect OAuth url (looks like yours is https://www.example.com/connect-onboard-redirect ).在您完成 Express 帐户注册后,Stripe 会将您的客户重定向到您在 Connect OAuth url 上指定的重定向 URI(看起来您的是https://www.example.com/connect-onboard-redirect )。

You should redirect to a real page of yours here.您应该在此处重定向到您的真实页面。 The redirect URL will append query params containing the authorization code eg https://www.example.com/connect-onboard-redirect?code=ac_1234重定向 URL 将附加包含授权代码的查询参数,例如https://www.example.com/connect-onboard-redirect?code=ac_1234

where ac_1234 is the OAuth authorization code.其中ac_1234是 OAuth 授权码。

You need to parse out that authorization code and send it to your backend and complete the OAuth connection to actually connect that Express account to your Platform: https://stripe.com/docs/connect/oauth-express-accounts#token-request您需要解析出该授权代码并将其发送到您的后端并完成 OAuth 连接以将该 Express 帐户实际连接到您的平台: https : //stripe.com/docs/connect/oauth-express-accounts#token-request

Got the last piece of my puzzle.得到了我的最后一块拼图。 Didn't know how to communicate with nodejs and use the GET method.不知道如何与 nodejs 通信并使用 GET 方法。 I used volley with this piece of code我在这段代码中使用了 volley

RequestQueue queue = Volley.newRequestQueue(getContext());

                StringRequest stringRequest = new StringRequest(Request.Method.GET, "http://10.0.2.2:4242" + "/connect/oauth",
                        new Response.Listener<String>() {
                            @Override
                            public void onResponse(String response) {
                                Log.d(">>>>>>>>CONNECTED?", ">>>CONNECTED!!!<<<");
                                // enjoy your response
                            }
                        }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.d(">>>>>>>>>>ERRRRRRROR", error.toString());
                        // enjoy your error status
                    }
                });

                queue.add(stringRequest);

Hope that helps anyone else starting to learn nodejs :)希望能帮助其他任何人开始学习 nodejs :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM