我正在尝试使用带条带的云代码,但从云代码文件中得到一个错误:
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!")
下面是cloud code.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")
}
})
}
}
})
感谢您的帮助!
最佳答案
这是确认的修复方法,
把这个输入控制台
jssdk 1.5.0
它将恢复您的SDK版本1.5.0,它工作正常,最新版本的SDK中有一些问题,文档也会被破坏。
关于swift - 使用Swift&Stripe解析云代码:TypeError:Object [object Object]没有方法'_each',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32471622/