我真的很难让 Parse + Stripe 在我的项目中工作。在这一点上,我想要最简单的工作版本,让我可以向用户收费。
我发现最接近答案的是: Simplest Example I've Found
当我使用上面链接中更正后的代码时,我收到以下错误消息:
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
请帮忙=**(这太令人沮丧了。
------------更新----------------
其他一些帖子也有类似的错误,看起来应该归咎于最新版本的 Parse Cloud 代码:1.6.0。在控制台 View 中使用以下命令行提示恢复到版本 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 时才有效(正如其他人帮助我所做的那样)。希望这对其他人也有帮助。
关于ios - 解析 + Stripe iOS main.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32544979/