【问题标题】:Creating Stripe Express Connect Account, Getting 'unsupported_content_type' when POST to endpoint for account ID创建 Stripe Express Connect 帐户,当 POST 到端点以获取帐户 ID 时获取“unsupported_content_type”
【发布时间】:2017-12-16 04:21:55
【问题描述】:

在创建连接快速帐户结束时,我无法向条带令牌端点发送“POST”请求。目前,我的应用程序(ios)正在打开 OAuth 链接(其中包含到我的服务器(Firebase 函数)的重定向 uri)到由条带制作的快速帐户创建网页。用户完成帐户设置后,我会在后端收到授权码,然后使用授权码和 client_secret_key 向“https://connect.stripe.com/oauth/token”发送 POST 请求。我正在使用 XMLHttpRequest npm 在 firebase 函数中发送 POST 请求并像这样设置我的参数

var params = "client_secret=" + CLIENT_SECRET + "&code=" + AUTHORIZATION_CODE + "&grant_type=authorization_code"

我的请求头是这样的

  request.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

但我在发送 POST 请求后返回此错误 "error": { "type": "invalid_request_error", "code": "unsupported_content_type", "message": "Invalid request: unsupported Content-Type text/plain;charset=UTF-8. If error persists and you need assistance, please contact support@stripe.com." }

我认为我正确地将请求标头内容类型设置为“application/x-www-form-urlencoded”,但仍然返回错误,好像内容类型是“Text/plain”一样。

这是完整的后端代码

exports.CreateUsersPayoutAccount = functions.https.onRequest((req, res) =>{
  const userID = req.query.state
  const AUTHORIZATION_CODE = req.query.code

  console.log(userID)
  console.log(AUTHORIZATION_CODE)
  //console.log(req);

  var request = new XMLHttpRequest()
  request.addEventListener('load', getStripeConnectUserID)
  var params = "client_secret=" + CLIENT_SECRET + "&code=" + AUTHORIZATION_CODE + "&grant_type=authorization_code"

  //var params = JSON.stringify({client_secret : CLIENT_SECRET, code : AUTHORIZATION_CODE, grant_type : "authorization_code"})
  console.log(params);
  request.open("POST", "https://connect.stripe.com/oauth/token", true)
  request.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
  //request.setRequestHeader("Content-length", params.length)
  request.send(params)


})

如果有人能指出我正确的方向,我将不胜感激,因为我对编写后端 HTTP 调用有点陌生。

【问题讨论】:

    标签: node.js firebase stripe-payments backend stripe-connect


    【解决方案1】:
    1. 在后端云功能中,不要尝试从那里发送 POST 请求,而是将身份验证代码写入 firebase 数据库中的某个位置。
    2. 回到 Xcode 中有一个侦听器函数,如果该数据库点发生更改,该函数就会执行。然后该函数应读取更改(身份验证代码)并简单地使用 Alamofire 发送一个简单的 swifty POST 请求。

    我理解为什么您将 uri 直接指向您的特定云功能(因为它是一个 http 触发器),但不是发送 uri 以便条带可以将用户重定向回特定应用程序页面的目的,是在您的情况下,用户仍然会被引导回应用程序???

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-30
      • 2021-11-09
      • 1970-01-01
      • 1970-01-01
      • 2020-09-30
      • 2021-06-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多