Parse + Stripe iOS main.js [英] Parse + Stripe iOS main.js
问题描述
我真的很难让Parse + Stripe在我的项目中工作。此时,我想要最简单的工作版本,允许我向用户收费。
I'm really struggling getting Parse + Stripe to work in my project. At this point, I want the simplest working version that allows me to charge the user.
我找到的答案最接近的是:
我发现最简单的示例
The closest thing I've found to an answer is the following: Simplest Example I've Found
当我使用上面链接中的更正代码时,我得到以下错误:
When I use the corrected code from the link above, with my secret I get the following Error:
Input: {"token":"tok_16kNOcIPNR1PIJsTyhvwTFJ9"}
Result: 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:19:31
请帮助= **(这太令人沮丧了。
Please help =**( this is so frustrating.
-------------更新----------------
------------- UPDATE ----------------
A很少有其他帖子有类似的错误,看起来最新版本的Parse Cloud代码应该归咎于: 1.6.0。在控制台视图中使用以下命令行提示符恢复到1.5.0版:
A few other posts had similar errors and it looks like the most recent version of Parse Cloud code is to blame: 1.6.0. Revert to version 1.5.0 by using the following command line prompt in the console view:
parse jssdk 1.5.0
现在,不幸的是我仍然收到以下错误(但我认为这是由于我的云代码main.js文件现在。当我最终弄清楚如何完成云代码文件时,我将保持此线程更新。
Now, unfortunately I still get the following error (but I think this is due to my cloud code main.js file now. I'll keep this thread updated when I finally figure out how to complete the cloud code file.
Error Domain=Parse Code=141 "success/error was not called" UserInfo=0x1740e5700 {code=141, temporary=0, error=success/error was not called, NSLocalizedDescription=success/error was not called}
推荐答案
最后。好的,所以这里是使用Parse + Stripe的最基本的代码。
Finally. OK so here is the most basic code that WORKS for using Parse + Stripe.
iOS代码
- (IBAction)save:(id)sender {
STPCard *card = [[STPCard alloc] init];
card.number = self.paymentTextField.cardNumber;
card.expMonth = self.paymentTextField.expirationMonth;
card.expYear = self.paymentTextField.expirationYear;
card.cvc = self.paymentTextField.cvc;
NSLog(@"%@, %@", self.paymentTextField.cvc, self.paymentTextField.cardNumber);
[[STPAPIClient sharedClient] createTokenWithCard:card
completion:^(STPToken *token, NSError *error) {
if (error) {
NSLog(@"up here");
NSLog(@"error - %@", error);
} else {
//[self createBackendChargeWithToken:token];
NSLog(@"down here");
NSString *myVal = token.tokenId;
NSLog(@"%@",token);
[PFCloud callFunctionInBackground:@"hello" withParameters:@{@"token":myVal}
block:^(NSString *result, NSError *error) {
if (!error) {
NSLog(@"from Cloud Code Res: %@",result);
}
else
{
NSLog(@"from Cloud Code: %@",error);
}
}];
}
}];
}
然后是main.js代码:
And then the main.js code:
var Stripe = require('stripe');
Stripe.initialize('sk_test_********'); //replace *** with your key values
Parse.Cloud.define("hello", function(request, response) {
var stripeToken = request.params.token;
var charge = Stripe.Charges.create({
amount: 1000, // express dollars 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');
});
});
现在再次,如果你将你的云代码转换为版本1.5.0(如其他的那样),这只会起作用帮助我)。希望这也有助于其他人。
Now again, this ONLY WORKS if you REVERT YOUR CLOUD CODE to Version 1.5.0 (as other have helped me with). Hope this helps someone else also.
这篇关于Parse + Stripe iOS main.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!