Mow*_*zer 2 javascript google-apps-script stripe-payments
根据这个答案,Gmail 没有公开用于发送和接收付款的 API。因此,我正在尝试使用 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',
});
})();
Run Code Online (Sandbox Code Playgroud)
但是,GAS 目前并不直接支持async和require。是否有任何可能的解决方法,以便我可以使用 Stripe 在我的 GAS 应用程序中发送和接收付款?
如果那不可能,我应该从这里往哪个方向走?
这个答案怎么样?请将此视为几个答案之一。
不幸的是,Node.js 的模块不能直接用于 Google Apps Script。因此需要为 Google Apps Script 准备脚本。幸运的是,在您问题中链接的官方文档中,有几个示例。使用这个,如何转换为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',
});
})();
Run Code Online (Sandbox Code Playgroud)
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())
}
Run Code Online (Sandbox Code Playgroud)
sk_test_4eC39HqLyjWDarjtT1zdp7dc用于密钥。但在这种情况下,因为使用的是基本授权,所以请sk_test_4eC39HqLyjWDarjtT1zdp7dc:添加:.如果我误解了您的问题并且这不是您想要的方向,我深表歉意。
| 归档时间: |
|
| 查看次数: |
1280 次 |
| 最近记录: |