简体   繁体   English

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

[英]How to integrate Stripe payments with Google Apps Script

According to this answer , Gmail does not expose an API for sending and receiving payments.根据this answer , Gmail 不会公开 API 用于发送和接收付款。 Therefore, I am trying to use Stripe to accomplish that.因此,我正在尝试使用 Stripe来实现这一点。

Code.js 代码.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', }); })();

However, GAS does not directly support async and require at this time.但是,GAS 目前并不直接支持asyncrequire Is there any possible workaround so I can use Stripe to send and receive payments in my GAS app?是否有任何可能的解决方法,以便我可以使用 Stripe 在我的 GAS 应用程序中发送和接收付款?

If that's not possible, what direction should I go from here?如果那不可能,我应该从这里往哪个方向 go?

How about this answer?这个答案怎么样? Please think of this as just one of several answers.请认为这只是几个答案之一。

Issue and workaround:问题和解决方法:

Unfortunately, the module of Node.js cannot be directly used for Google Apps Script.遗憾的是,Node.js 模块不能直接用于 Google Apps Script。 So it is required to prepare the script for Google Apps Script.因此需要为 Google Apps Script 准备脚本。 Fortunately, at the official document of the link in your question, there are several samples.幸运的是,在您问题中链接的官方文档中,有几个示例。 Using this, how about converting to the script of Google Apps Script?使用这个,转换成 Google Apps Script 的脚本怎么样?

Sample script:示例脚本:

When your script in your question is converted to Google Apps Script, it becomes as follows.当您的问题中的脚本转换为 Google Apps 脚本时,它变为如下。

From:从:

// 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',
  });
})();

To

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())
}
  • In this case, both requests of Node.js and Google Apps Script are the same.在这种情况下,Node.js 和 Google Apps Script 的两个请求是相同的。

Note:笔记:

  • At the sample script of Node.js, sk_test_4eC39HqLyjWDarjtT1zdp7dc is used for the key.在 Node.js 的示例脚本中,密钥使用了sk_test_4eC39HqLyjWDarjtT1zdp7dc But in this case, because the basic authorization is used, please use sk_test_4eC39HqLyjWDarjtT1zdp7dc: by adding : .但在这种情况下,由于使用了基本授权,请使用sk_test_4eC39HqLyjWDarjtT1zdp7dc:添加:

References:参考:

If I misunderstood your question and this was not the direction you want, I apologize.如果我误解了您的问题并且这不是您想要的方向,我深表歉意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM