使用 Parse.com Stripe API 创建费用时出错

Error when creating charge with Parse.com Stripe API

我正在尝试使用 stripe 上的测试帐户创建费用。

这是我的解析云函数:

Parse.Cloud.define("charge", function(request, response) {
 var Stripe = require('stripe'); 
 Stripe.initialize('...');

 Stripe.Charges.create({
    amount: 1000, 
    currency: "usd",
    customer: "..."
   },{
   success: function(httpResponse) {
       response.success("Purchase made!");
    },
   error: function(httpResponse) {
      response.error("Uh oh, something went wrong");
   }
  });
 }); 

我已经将 customerID 硬编码到函数中只是为了测试。

当我从我的应用程序调用函数时,出现以下错误:

TypeError: Object [object Object] has no method '_each'

at request (stripe.js:58:11)

at post (stripe.js:117:12)

at Object.module.exports.Charges.create (stripe.js:157:16)

at main.js:19:18 (Code: 141, Version: 1.6.2)

有人能帮忙吗?

就其价值而言,您的代码看起来与我的可用云代码非常相似。但是,我在第一个 }) 之后没有分号。就在最后一个之后。 如果那不是错误,那么我不太确定如何解释您的错误,因为我看不到上述行的代码。祝你好运

@user3707419 我在尝试添加客户时遇到同样的错误。注释掉该行并添加以下内容:

 card: stripeToken //this is the token you generated

此外,如果这不起作用,您需要将解析云代码的版本还原为 1.5.0(您可能 运行 最新版本 1.6.0 不起作用。您的方式为此,请在您的控制台中输入以下内容:

parse jssdk 1.5.0

我在 1.5.0 版上的所有工作代码都位于此 post: Complete working Stripe + Parse.com working code on version 1.5.0

我们可能必须进一步恢复才能让客户:customer.id 工作我不确定。如果您找到不同的解决方案,请告诉我。希望这可以帮助。

只是让你知道真正的原因:Parse 删除了下划线库,stripe.js 内置到 parse 云代码中的依赖它。因此失败了。

Parse 1.6.X 不再支持模块,他们也从 API 文档中删除了它们。