如何使用 webtask.io webhook 设置 Stripe Ideal

How to setup Stripe Ideal with webtask.io webhook

我已经尝试了 2 天来为 Stripe 中的理想支付设置一个 webhook。第一个 id 喜欢使用 Stripe 的内置测试方法对其进行测试,但到目前为止我什至无法获得良好的响应。

任何人都可以帮我举个例子来创建一个在 source.chargeable 时运行 webhook -> /charge 的源吗?我尝试了十几个示例,从 stripes 自己的文档到整个互联网。现在作为一个 webhook,我有这个(来自条纹文档):

module.exports = function(ctx, req, res) {
  var stripe = require("stripe")("sk_test_dfgfdgdf");

  const charge = stripe.charges.create({
    amount: 999,
    currency: 'usd',
    description: 'Example charge',
    source: ctx,
  })
};

有一个使用 Node(Express) 接收 webhook 的完整示例 here — that would be a good place to start, just plug in your API key and webhook secret, then run the app and enter your URL in https://dashboard.stripe.com/account/webhooks

获得事件并对其进行解析后,您需要检查事件类型。如果是source.chargeable,那么你可以调用API到make the charge。您很可能需要在提交原始订单时将有关原始订单的信息保存到本地数据库,因为您将在用户开始结帐流程后的某个时间异步接收 webhook。您可以查找已保存的订单以确定要在要使用的 charge/the Stripe 客户对象上设置的任何元数据等。但是现在一个简单的方法是这样的:

if(event.type == "source.chargeable"){
  const source = event.data.object;
  const charge = await stripe.charges.create({
    amount: source.amount,
    currency: source.currency,
    source: source.id,
  });
}