我已经在Wix网站中集成了条带以进行条带重复付款,但是当我发送请求时,它显示错误:“接收到未知参数源”! 这是我的帖子请求正文:
{
"customer": "cus_Fzo88vAVFgZpAu",
"items": {
"0": {
"plan": "prod_FznbhQKMCL2NCw"
}
},
"source": "tok_1FToWRDTT6jCg8kd1lxdqukE"
}
这是我的后端功能:
//stripe.jsw
import { fetch } from 'wix-fetch';
export async function subscription(token, item) {
const cart = item;
const apiKey = "sk_test_JHQ5ZDHh7iLrEvUAkHdw7ART001pdYVfam";
const response = await fetch("https://api.stripe.com/v1/subscriptions", {
method: 'post',
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Bearer " + apiKey
},
body: encodeBody(token, cart)
});
if (response.status >= 200 && response.status < 300) {
// transaction successful - get charge ID
const ret = await response.json();
return { "chargeId": ret.id };
}
// transaction failed - return error messages and codes
let res = await response.json();
let err = res.error.message;
let code = res.error.code;
let type = res.error.type;
return { "error": err, "code": code, "type": type };
}
function encodeBody(token, cart) {
let encoded = "";
for (let [k, v] of Object.entries(cart)) {
encoded = encoded.concat(k, "=", encodeURI(v), "&");
}
encoded = encoded.concat("source=", encodeURI(token));
return encoded;
}