Flutter 使用flatter创建支付意图时从条带接收无效请求错误

Flutter 使用flatter创建支付意图时从条带接收无效请求错误,flutter,dart,stripe-payments,payment,Flutter,Dart,Stripe Payments,Payment,我正在将Stripe集成到我的Flitter应用程序中,希望使用http POST请求创建支付意图。但我经常收到这个错误。尝试了很多东西 { "error": { "code": "parameter_unknown", "doc_url": "https://stripe.com/docs/error-codes/parameter-unknown", "m

我正在将Stripe集成到我的Flitter应用程序中,希望使用http POST请求创建支付意图。但我经常收到这个错误。尝试了很多东西

{
  "error": {
    "code": "parameter_unknown",
    "doc_url": "https://stripe.com/docs/error-codes/parameter-unknown",
    "message": "Received unknown parameter: {\"amount\":2,\"currency\":\"usd\"}",
    "param": "{\"amount\":2,\"currency\":\"usd\"}",
    "type": "invalid_request_error"
  }
}
我的api函数是:

Future<Map<String, dynamic>> createPaymentIntent(int amount) async {
    try {
      var url = "https://api.stripe.com/v1/payment_intents";

      var body = json.encode({
        "amount": amount,
        "currency": 'usd'
      });

      var headers = {
        'Content-type': 'application/x-www-form-urlencoded',
        'Accept': 'application/json',
        'authorization': 'Bearer '+stripeSecret
      };

      await http.post(url, body: json.encode(body), headers: headers, encoding: Encoding.getByName("utf-8")).then((response) {
        if(response.statusCode == 200){
          print(response.body);
          return json.decode(response.body);
        }
        else{
          return response.reasonPhrase;
        }
      });

    } catch (e) {
      return e.message;
    }
  }
Future createPaymentIntent(整数金额)异步{
试一试{
变量url=”https://api.stripe.com/v1/payment_intents";
var body=json.encode({
“金额”:金额,
“货币”:“美元”
});
变量头={
“内容类型”:“应用程序/x-www-form-urlencoded”,
“接受”:“应用程序/json”,
“授权”:“持票人”+stripeSecret
};
等待http.post(url,body:json.encode(body),headers:headers,encoding:encoding.getByName(“utf-8”)。然后((响应){
如果(response.statusCode==200){
打印(响应.正文);
返回json.decode(response.body);
}
否则{
返回response.reason短语;
}
});
}捕获(e){
返回e.message;
}
}

注意:
'Content-type':'application/x-www-form-urlencoded'
是必需的。

您正在向条带API发送JSON编码的正文,但条带API需要:

我们的API具有可预测的面向资源的URL,接受表单编码的请求体,返回JSON编码的响应,并使用标准HTTP响应代码、身份验证和谓词


那么,我如何才能在颤振中做到这一点呢?我已经提到,
“Content-type”:“application/x-www-form-urlencoded”
是必需的。请看这里: