【问题标题】:I am getting Received Unknown Parameter Source Error on Wix stripe recurring payment我收到关于 Wix 条纹定期付款的未知参数源错误
【发布时间】:2020-02-12 02:26:34
【问题描述】:

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

}

【问题讨论】:

  • 对不起,我的代码格式正确,这是 StackOverflow 故障!

标签: javascript node.js stripe-payments


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2019-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-03
    • 2023-02-03
    • 2019-10-19
    • 2021-05-11
    相关资源
    最近更新 更多