gpt4 book ai didi

javascript - 如何将 Stripe 支付与 Google Apps 脚本集成

转载 作者:行者123 更新时间:2023-11-29 20:29:43 25 4
gpt4 key购买 nike

According to this answer , Gmail 不公开用于发送和接收付款的 API。因此,I am trying to use Stripe实现这一目标。

代码.js
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc');

(async () => {
const product = await stripe.products.create({
name: 'My SaaS Platform',
type: 'service',
});
})();

但是,GAS目前并不直接支持asyncrequire。是否有任何可能的解决方法,以便我可以使用 Stripe 在我的 GAS 应用程序中发送和接收付款?

如果那不可能,我应该从这里往哪个方向走?

最佳答案

这个答案怎么样?请将此视为几个答案之一。

问题和解决方法:

遗憾的是,Node.js 的模块不能直接用于 Google Apps Script。所以需要为Google Apps Script准备脚本。幸运的是,在the official document of the link在你的问题中,有几个样本。使用这个,转换成 Google Apps Script 的脚本怎么样?

示例脚本:

当您的问题中的脚本转换为 Google Apps 脚本时,它变成如下。

来自:

// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc');

(async () => {
const product = await stripe.products.create({
name: 'My SaaS Platform',
type: 'service',
});
})();

function myFunction() {
var url = "https://api.stripe.com/v1/products";
var params = {
method: "post",
headers: {Authorization: "Basic " + Utilities.base64Encode("sk_test_4eC39HqLyjWDarjtT1zdp7dc:")},
payload: {name: "My SaaS Platform", type: "service"}
};
var res = UrlFetchApp.fetch(url, params);
Logger.log(res.getContentText())
}
  • 在这种情况下,Node.js 和 Google Apps Script 的请求是相同的。

注意事项:

  • 在 Node.js 的示例脚本中,sk_test_4eC39HqLyjWDarjtT1zdp7dc 用于 key 。但在这种情况下,因为使用了基本授权,请使用 sk_test_4eC39HqLyjWDarjtT1zdp7dc: 添加 :

引用资料:

如果我误解了您的问题并且这不是您想要的方向,我深表歉意。

关于javascript - 如何将 Stripe 支付与 Google Apps 脚本集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58635015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com