你好stackoverflow社区
我拼命地想用iOS应用程序在Stripe中创建一个新的客户和信用卡。我很幸运得到了令牌。
然而,当运行以下代码与客户创建信用卡时,我在Parse Cloud code中得到错误“has no method'_each'”:
E2015-09-24T21:19:45.502Z]v10 Ran cloud function saveCardInformation with:
Input: {"cardToken":"tok_16oh81JJfrimOSDHs6YSw4v5","objectId":"asdfdf"}
Result: TypeError: Object [object Object] has no method '_each'
at request (stripe.js:58:11)
at post (stripe.js:117:12)
at Object.module.exports.Customers.create (stripe.js:239:16)
at main.js:62:22
我执行以下Parse云代码:
//Parse Cloud code for creating new Stripe Customer and new Credit Card
var Stripe = require('stripe');
Stripe.initialize('mykey');
Parse.Cloud.define("saveCardInformation", function(request, response) {
Stripe.Customers.create({
source: request.params.cardToken,
},{
success: function(httpResponse) {
response.success("Customer successfully created!");
},
error: function(httpResponse) {
response.error(httpResponse.message);
}
});
在相应的iOS应用程序中,我有以下代码:
STPCard *stpcard = [[STPCard alloc] init];
stpcard.number = @"4568785465487897";
stpcard.expMonth = 5;
stpcard.expYear = 2017;
stpcard.cvc = @"255";
NSLog(@"card created");
[[STPAPIClient sharedClient] createTokenWithCard:stpcard
completion:^(STPToken *token, NSError *error) {
if (error) {
NSLog(@"error, no token created");
} else {
NSLog(@"Token from callback recieved");
[self createBackendChargeWithToken:token];
}
}];
到目前为止,它仍然有效。
以下方法会产生问题
- (void)createBackendChargeWithToken:(STPToken *)token
{
NSDictionary *productInfo = @{@"cardToken": token.tokenId,
@"objectId": @"asdfdf"};
[PFCloud callFunctionInBackground:@"saveCardInformation"
withParameters:productInfo
block:^(id object, NSError *error) {
if (error) {
NSLog(@"error,");
return ;
}
[[[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"Success",
@"Success")
message:nil
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK","OK"
otherButtonTitles:nil] show];
}];
}
非常感谢您的回答和指导!