如何将Stripe付款与Google Apps脚本集成

问题描述 投票:2回答:1

According to this answer,Gmail不公开用于发送和接收付款的API。因此,I am trying to use Stripe完成该任务。

Code.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应用中发送和接收付款?

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

javascript google-apps-script stripe-payments
1个回答
2
投票

这个答案怎么样?请认为这只是几个答案之一。

问题和解决方法:

[遗憾的是,Node.js的模块不能直接用于Google Apps脚本。因此,需要为Google Apps脚本准备脚本。幸运的是,您的问题中的the official document of the link有几个样本。使用此方法,如何转换为Google Apps脚本的脚本?

示例脚本:

将问题中的脚本转换为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脚本的请求是相同的。

注意:

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

参考:

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

© www.soinside.com 2019 - 2024. All rights reserved.