使用Swift& Parse解析云代码Stripe:TypeError:Object [object Object]没有方法'_each'

时间:2015-09-09 05:36:53

标签: swift parse-platform stripe-payments cloud-code

我正在尝试使用带有条带的云代码,但我从云代码文件中收到错误:

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!")

这是云代码.js文件:

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

我使用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")
                        }
                    })

                }

            }
        })

感谢任何帮助!

2 个答案:

答案 0 :(得分:4)

所以这是确认的修复, 只需在控制台中输入

即可
jssdk 1.5.0

它恢复你的SDK 1.5.0版本,工作正常,在最新版本的sdk中搞砸了,文档也被破坏了。

答案 1 :(得分:2)

我今天更新了我的Cloud Code版本后遇到了同样的问题。如果您找到了解决方案,请在此处发布,绝对需要它。