简体   繁体   English

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

[英]Error when creating charge with Parse.com Stripe API

I'm trying to create a charge with a test account on stripe. 我正在尝试使用带区卷上的测试帐户来创建费用。

Here is my parse cloud function: 这是我的解析云函数:

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");
   }
  });
 }); 

I've hard coded the customerID into the function just for testing. 我已经将customerID硬编码到函数中以进行测试。

When I call the function from my app, I get the following error: 当我从应用程序调用该函数时,出现以下错误:

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)

Can anyone help? 有人可以帮忙吗?

@user3707419 I get the same error when trying to add a customer. @ user3707419尝试添加客户时遇到相同的错误。 Comment out that line and instead add the following: 注释掉该行,然后添加以下内容:

 card: stripeToken //this is the token you generated

Also, if that doesn't work, you need to revert you parse cloud code version to 1.5.0 (you are probably running the latest version 1.6.0 which does not work. The way you do this is type the following into your console: 另外,如果那行不通,则需要将解析云代码版本还原为1.5.0(您可能正在运行的最新版本1.6.0无效。您可以通过在控制台中键入以下内容来实现该功能) :

parse jssdk 1.5.0

All of my working code on version 1.5.0 is located at this post: Complete working Stripe + Parse.com working code on version 1.5.0 我在1.5.0版上的所有工作代码均位于此职位: 完整的Stripe + Parse.com在1.5.0版上的工作代码。

We may have to revert back even further to get customer: customer.id working I'm not sure. 为了获得客户,我们可能必须进一步退回去:customer.id尚无法确定。 Let me know if you figure a different solution out. 让我知道您是否找到其他解决方案。 Hope this helps. 希望这可以帮助。

For what it's worth, your code looks very similar to my cloud code that works. 就其价值而言,您的代码看起来与可以正常工作的我的云代码非常相似。 However, I do not have a semicolon after the first }). 但是,我在第一个})之后没有分号。 Just after the final one. 在最后一场比赛之后。 If that's not the error, then i'm not very sure how to interpret your errors because i cannot see the code at the mentioned lines. 如果那不是错误,那么我不太确定如何解释您的错误,因为我看不到上述行中的代码。 Best of luck 祝你好运

Just so you know the real reason: Parse removed underscore lib , stripe.js thats built into parse cloud code relied on it. 正是这样,您才知道真正的原因:解析删除了下划线lib,而内置于解析云代码中的stripe.js依赖于此。 Hence failure like this. 因此失败了。

Parse 1.6.X no longer supports modules, they removed them from API doc as well. Parse 1.6.X不再支持模块,他们也将其从API文档中删除。

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

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