使用Stripe Android和Firebase创建连接的用户。

huangapple go评论85阅读模式
英文:

Making Connected User with stripe android + firebase

问题

以下是翻译好的部分:

我对于后端服务器和Node.js的工作非常陌生。我正在尝试在我的应用程序中设置Stripe,并且现在正在尝试使用Stripe创建一个连接的账户。我正在按照这个链接的指南进行操作:https://stripe.com/docs/connect/collect-then-transfer-guide,但是我不理解足够多以使其工作。我该如何从服务器获取信息或通过发送信息来创建账户。

这是我目前的代码:

        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}!`));

注册页面会打开,可以输入测试信息,但是在提交后实际上没有在Stripe仪表板中创建账户。任何帮助将不胜感激。

英文:

I'm very new to working with backend server stuff and nodejs. I'm trying to set up Stripe with my app and now trying to create a Connected account with stripe. Was following this https://stripe.com/docs/connect/collect-then-transfer-guide but I don't understand enough to make it work. 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. Any help would be much appreciated

enter image description here

答案1

得分: 0

完成Express帐户注册后,Stripe会将您的客户重定向到您在Connect OAuth URL上指定的重定向URI(类似于您的URL:https://www.example.com/connect-onboard-redirect)。

您应该重定向到您自己的实际页面。重定向URL将附加查询参数,其中包含授权码,例如:https://www.example.com/connect-onboard-redirect?code=ac_1234

这里的ac_1234是OAuth授权码。

您需要解析该授权码并将其发送到您的后端,然后完成OAuth连接,以实际将该Express帐户连接到您的平台:https://stripe.com/docs/connect/oauth-express-accounts#token-request

英文:

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).

You should redirect to a real page of yours here. The redirect URL will append query params containing the authorization code e.g. https://www.example.com/connect-onboard-redirect?code=ac_1234

where ac_1234 is the OAuth authorization code.

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

答案2

得分: 0

// 创建一个请求队列
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!!!<<<");
                // 处理响应数据
            }
        }, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        Log.d(">>>>>>ERRRRRRROR", error.toString());
        // 处理错误状态
    }
});

// 将请求添加到队列
queue.add(stringRequest);

希望这对刚开始学习 Node.js 的其他人有所帮助 使用Stripe Android和Firebase创建连接的用户。

英文:

Got the last piece of my puzzle. Didn't know how to communicate with nodejs and use the GET method. I used volley with this piece of code

RequestQueue queue = Volley.newRequestQueue(getContext());
StringRequest stringRequest = new StringRequest(Request.Method.GET, &quot;http://10.0.2.2:4242&quot; + &quot;/connect/oauth&quot;,
new Response.Listener&lt;String&gt;() {
@Override
public void onResponse(String response) {
Log.d(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;CONNECTED?&quot;, &quot;&gt;&gt;&gt;CONNECTED!!!&lt;&lt;&lt;&quot;);
// enjoy your response
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;ERRRRRRROR&quot;, error.toString());
// enjoy your error status
}
});
queue.add(stringRequest);

Hope that helps anyone else starting to learn nodejs 使用Stripe Android和Firebase创建连接的用户。

huangapple
  • 本文由 发表于 2020年9月9日 00:56:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/63798403.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定