简体   繁体   中英

Store credit card with Stripe and Parse. has no method each error

Hello stackoverflow community

Im desperately trying to create a new customer and credit card in Stripe out of an iOS app. Im luckily getting the token.

However, when running the following code for creating a credit card with its customer, I get the error "has no method '_each'" in Parse Cloud Code:

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

I execute the following Parse cloud code:

//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);
  }
});

In the corresponding iOS app, I have the following code:

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];
                                   }
}];

Up to here it works.

The following method is causing troubles

- (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];
                              }];
}

Thank you very much for an answer and guidance!

Revert your cloud code version to 1.5.0 or earlier.

Explained here : Parse + Stripe iOS main.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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