我正在使用Parse + Stripe。我的Parse Cloud Code版本是1.5.0,这是我在app端的源代码。
func performStripeOperation() {
STPAPIClient.sharedClient().createTokenWithCard(stripCard, completion: { (token: STPToken?, error: NSError?) -> Void in
if error == nil {
// credit card details are correct
print(token!.tokenId)
var myVal: String = token!.tokenId
NSLog("%@", token!)
PFCloud.callFunctionInBackground("pay", withParameters: ["token": myVal], block: {(result: AnyObject?, error: NSError?) -> Void in
if (error == nil) {
NSLog("from Cloud Code Res: %@", result as! String )
}
else {
NSLog("from Cloud Code: %@", error!)
}
})
} else {
print("Token error.")
// Handle Error here
NSLog("ERRRRR = %@", error!)
let alert = UIAlertController(title: "Please try again", message: "\(error!.localizedDescription)", preferredStyle: .Alert)
let actionOk = UIAlertAction(title: "Ok", style: .Default, handler: nil)
alert.addAction(actionOk)
self.presentViewController(alert, animated: true, completion: nil)
//let alert: UIAlertView = UIAlertView(title: "Please try again", message: "\(error!.localizedDescription)", delegate: nil, cancelButtonTitle: "OK", otherButtonTitles: "")
//alert.show()
}
})
}
并且对于main.js,我遵循了来自here
的源代码var Stripe = require('stripe');
Stripe.initialize('sk_test_******************');
Parse.Cloud.define("pay", function(request, response) {
var stripeToken = request.params.token;
var charge = Stripe.Charges.create({
amount: 1000, // in cents
currency: 'usd',
card: stripeToken
}).then(null, function(error) {
console.log('Charging with stripe failed. Error: ' + error);
}).then(function() {
// And we're done!
response.success('Success');
});
});
现在,我收到了这个错误
[Error]: TypeError: Object [object Object] has no method 'isString'
at request (stripe.js:49:25)
at post (stripe.js:117:12)
at Object.module.exports.Charges.create (stripe.js:157:16)
at main.js:27:29 (Code: 141, Version: 1.12.0)
2016-04-05 22:56:35.886 Muzicue[39049:832833] from Cloud Code: Error Domain=Parse Code=141 "TypeError: Object [object Object] has no method 'isString'
at request (stripe.js:49:25)
at post (stripe.js:117:12)
at Object.module.exports.Charges.create (stripe.js:157:16)
at main.js:27:29" UserInfo={code=141, temporary=0, error=TypeError: Object [object Object] has no method 'isString'
at request (stripe.js:49:25)
at post (stripe.js:117:12)
at Object.module.exports.Charges.create (stripe.js:157:16)
at main.js:27:29, NSLocalizedDescription=TypeError: Object [object Object] has no method 'isString'
at request (stripe.js:49:25)
at post (stripe.js:117:12)
at Object.module.exports.Charges.create (stripe.js:157:16)
at main.js:27:29}
知道我做错了吗?感谢...
答案 0 :(得分:0)
在我将main.js更改为此之后,它运行了。 response.success和response.error都需要实现。
var Stripe = require('stripe');
Stripe.initialize('sk_test_**********************');
Parse.Cloud.define("pay", function(request, response) {
Stripe.Charges.create({
// amount: request.params.amount,
amount: 1000,
currency: "usd",
card: request.params.token
}).then(
function(param) {
console.log('Made successful card charge with Stripe!');
response.success("Stripe charge succeeded.");
},
function(error) {
console.log('Charging with stripe failed. Error: ' + error);
response.error(error.message);
}
)
});