parsing+条纹iOS main.js
我真的很挣扎让Parse + Stripe在我的项目中工作。 在这一点上,我想要最简单的工作版本,使我能够收取用户。
我发现最接近的答案如下: 我find最简单的例子
当我使用上面的链接更正的代码,与我的秘密,我得到以下错误:
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
请帮助= **(这太令人沮丧了。
————-更新—————-
其他一些post也有类似的错误,看起来像Parse Cloud代码的最新版本是责怪1.6.0。 通过在控制台视图中使用以下命令行提示恢复到版本1.5.0:
parse jssdk 1.5.0
现在,不幸的是我仍然得到了以下错误(但是我认为这是由于我的云代码main.js文件。当我终于弄清楚如何完成云代码文件时,我会保持这个线程更新。
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工作的最基本的代码。
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代码:
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(正如其他人帮助我的那样),这也是唯一的工作。 希望这也可以帮助别人。
只是为了从上面更加明确一些:
cd
进入你的云代码目录并运行parse jssdk 1.5.0
并parse deploy
。