简体   繁体   English

Parse + Stripe iOS main.js

[英]Parse + Stripe iOS main.js

I'm really struggling getting Parse + Stripe to work in my project. 我真的很难让Parse + Stripe在我的项目中工作。 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 few other posts had similar errors and it looks like the most recent version of Parse Cloud code is to blame: 1.6.0. 其他一些帖子也有类似的错误,看起来最新版本的Parse Cloud代码应该归咎于:1.6.0。 Revert to version 1.5.0 by using the following command line prompt in the console view: 在控制台视图中使用以下命令行提示符恢复到1.5.0版:

parse jssdk 1.5.0

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. 现在,不幸的是我仍然得到以下错误(但我认为这是由于我的云代码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}

Finally. 最后。 OK so here is the most basic code that WORKS for using Parse + Stripe. 好的,这里是使用Parse + Stripe的最基本的代码。

iOS Code 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);
                                                                              }

                                                                          }];
                                          }
                                      }];
}

And then the main.js code: 然后是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');

   });
   });

Now again, this ONLY WORKS if you REVERT YOUR CLOUD CODE to Version 1.5.0 (as other have helped me with). 再说一遍,如果你将你的云代码改为版本1.5.0(正如其他人帮助我的话),这只会起作用。 Hope this helps someone else also. 希望这也有助于其他人。

Just to be a little bit more explicit from above: 只是为了更明确一点:

cd into your cloud code directory and run parse jssdk 1.5.0 and parse deploy . cd进入您的云代码目录并运行parse jssdk 1.5.0parse deploy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM