0
votes

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!

1

1 Answers

3
votes

Revert your cloud code version to 1.5.0 or earlier.

Explained here : Parse + Stripe iOS main.js