解析 + 条纹 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 ----------------
其他一些帖子也有类似的错误,看起来应该归咎于最新版本的 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.
这篇关于解析 + 条纹 iOS main.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!