2

I am trying to use cloud code with stripe, but I am getting an error from the cloud code file:

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:7:18 (Code: 141, Version: 1.8.2)
Charge not working
Optional("Hello world!")

Here is the cloud code .js file:

var Stripe = require('stripe');
Stripe.initialize(MYKEY);

Parse.Cloud.define("charge", function(request, response) {


  Stripe.Charges.create({
    source: request.params.token,
    amount: request.params.amount,
    currency: "usd"
  },{
    success: function(httpResponse) {
        response.success("Purchase made!");
    },
    error: function(httpResponse) {
        response.error("Error: "+httpResponse.message+"\n"+
               "Params:\n"+
               request.params.token+","+
               request.params.amount+
               "\n"
              );
    }
  });
});


Parse.Cloud.define("hello", function(request, response) {
  response.success("Hello world!");
});

I am calling the cloud code from a view controller with Swift:

        let card = STPCard()
        card.number = stripeCreditCardInput.card?.number
        card.expMonth = (stripeCreditCardInput.card?.expMonth)!
        card.expYear = (stripeCreditCardInput.card?.expYear)!
        card.cvc = stripeCreditCardInput.card?.cvc

        STPAPIClient.sharedClient().createTokenWithCard(card, completion: { (token, stripeError) -> Void in
            if stripeError != nil {
                self.handleError(stripeError!)
            } else {
                print("Your token is: \(token!)")

                if let myToken = token?.tokenId {

                    let amount = 1000 * 3.5

                    PFCloud.callFunctionInBackground("hello", withParameters: nil) {
                        (response: AnyObject?, error: NSError?) -> Void in
                        let responseString = response as? String
                        print(responseString)
                    }

                    //let name = PFUser.currentUser()?.username as String!

                    PFCloud.callFunctionInBackground("charge", withParameters: ["token" : myToken, "amount": amount], block: { (success: AnyObject?, error: NSError?) -> Void in
                        if error != nil {
                            print("Charge not working")
                        }
                    })

                }

            }
        })

Any help is appreciated!

surfaspen
  • 391
  • 7
  • 17

2 Answers2

4

So here is the confirmed fix, just type this into the console

jssdk 1.5.0

it reverts your SDK version 1.5.0 which works fine, something is messed up in latest version of sdk and the documentation is broken also.

Ronak K
  • 1,567
  • 13
  • 23
2

I've got the same problem after updating my Cloud Code version today. If you find a fix, please post it here, need it desperately.

Florian
  • 226
  • 1
  • 9
  • 1
    I have the same problem... Also I noticed Parse's Stripe library link is broken... Anyone have any ideas? – Ibdakine Sep 13 '15 at 07:01
  • 1
    @lbdakine I temporarily fixed it by using an older version of cloud code. Version 1.3.5 works fine. – Florian Sep 13 '15 at 13:14
  • wow thank you for the quick reply @Florian. How do I revert to an old version of cloud code? – Ibdakine Sep 13 '15 at 16:30
  • I found it via Parse documentation. If anyone else is looking for this, here is is, just type this into the console: parse jssdk 1.5.0 to revert to 1.5.0. Thank you @Florian! – Ibdakine Sep 13 '15 at 17:58
  • @lbdakine nice find, at least I can upgrade to 1.5.0 then. You're welcome, I was lucky I had an old version of the cloud code as a copy – Florian Sep 13 '15 at 19:37
  • does your code charge a customer or just a token? For some reason, when I charge a customer with something like customer: customer.id I'm getting an error. I'm thinking it might have something to do with 1.5.0 but not sure. I haven't had time to revert back to versions less than 1.5.0. Let me know. Thanks! – Ibdakine Sep 15 '15 at 22:09