Error when creating charge with Parse.com Stripe API

随声附和 提交于 2019-12-13 19:23:20

问题


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.

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?


回答1:


@user3707419 I get the same error when trying to add a customer. 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:

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

We may have to revert back even further to get customer: customer.id working I'm not sure. Let me know if you figure a different solution out. Hope this helps.




回答2:


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




回答3:


Just so you know the real reason: Parse removed underscore lib , stripe.js thats built into parse cloud code relied on it. Hence failure like this.

Parse 1.6.X no longer supports modules, they removed them from API doc as well.



来源:https://stackoverflow.com/questions/32573109/error-when-creating-charge-with-parse-com-stripe-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!