我在Wix条纹定期付款中收到收到的未知参数源错误

时间:2019-10-15 11:55:07

标签: javascript node.js stripe-payments

我已经在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;

}

1 个答案:

答案 0 :(得分:0)

根据Subscription API,问题似乎是“源”不是可接受的参数。相反,在创建客户时,您需要传递令牌的来源。