gpichler
gpichler

Reputation: 2381

Parse returns error for Stripe module

I want to use the Stripe Cloud Module for charging credit cards inside my app, however the cloud function always returns with error code 141.

Error: Uh oh, something went wrong (Code: 141, Version: 1.5.0)
Error Domain=Parse Code=141 "The operation couldn’t be completed. (Parse error 141.)" UserInfo=0x170a640c0 {error=Uh oh, something went wrong, code=141}

Here is my cloud code:

var Stripe = require('stripe');
Stripe.initialize('pk_test_xxxxxxxxxxxxxxxx');

Parse.Cloud.define("chargeCreditCard", function(request, response) {

 Stripe.Charges.create({
   amount: request.params.amount * 100, 
   currency: "usd",
   card: request.params.token
 },{
   success: function(httpResponse) {
     response.success("Purchase made!");
   },
   error: function(httpResponse) {
     response.error("Uh oh, something went wrong");
   }
 });

});

That's how I call this function from my app:

NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[params setObject:[NSNumber numberWithInt:100] forKey:@"amount"];
[params setObject:token.tokenId forKey:@"token"];

[PFCloud callFunctionInBackground:@"chargeCreditCard" withParameters:params block:^(id object, NSError *error) {
    if (error) {
        NSLog(@"%@", error);
    }
}];

I've debugged it and the tokenId is correct. I've also changed the Parse version number in the global.json file to 1.5.0. Any help is much appreciated!

Upvotes: 0

Views: 604

Answers (1)

gpichler
gpichler

Reputation: 2381

I could figure the problem out by myself. First hint is to log a useful error message, rather than the one provided in the Parse documentation.

error: function(httpResponse) {
 response.error(httpResponse.message);
 // alternatively
 console.log(httpResponse.message);
}

This helped me to find what was causing the issue. In my case I was using the publishable key in my JavaScript cloud code, but the Stripe module needs the secret key.

Upvotes: 3

Related Questions