【发布时间】:2021-02-13 23:24:51
【问题描述】:
我正在将 Stripe 集成到我的 Flutter 应用程序中,想要使用提及 here 的 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;
}
}
注意:'Content-type': 'application/x-www-form-urlencoded' 是必需的。
【问题讨论】:
标签: flutter dart stripe-payments payment