【发布时间】:2015-12-22 15:46:05
【问题描述】:
你好 stackoverflow 社区
我正在拼命尝试从 iOS 应用程序中创建一个新的客户和信用卡。我很幸运得到了令牌。
但是,在运行以下代码以与其客户创建信用卡时,我在 Parse Cloud 代码中收到错误“没有方法 '_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];
}];
}
非常感谢您的回答和指导!
【问题讨论】:
标签: ios objective-c parse-platform stripe-payments parse-cloud-code