簡體   English   中英

我收到關於 Wix 條帶定期付款的未知參數源錯誤

[英]I am getting Received Unknown Parameter Source Error on Wix stripe recurring payment

我已經在 Wix 網站中集成了條帶以進行條帶定期付款,但是當我發送請求時,它顯示錯誤:“收到未知參數來源”:! 這是我的帖子請求正文:

{
  "customer": "cus_Fzo88vAVFgZpAu",
  "items": {
    "0": {
      "plan": "prod_FznbhQKMCL2NCw"
    }
  },
  "source": "tok_1FToWRDTT6jCg8kd1lxdqukE"
}

這是我的后端 function:

//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;

}

根據訂閱 API ,問題似乎是“源”不是可接受的參數。 相反,您需要在創建客戶時傳遞您的源代碼,即令牌。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM