I am using the Stripe Parse Cloud Code Module to try and charge a card that I collected the information from in my iOS app. I am using the guide from the parse website: http://parse.com/docs/cloud_modules_guide#stripe
Here is my version in cloud/main.js:
var Stripe = require('stripe');
Stripe.initialize('MY_STRIPE_TEST_SECRET_KEY');
Parse.Cloud.define("purchase", function(request, response) {
Stripe.Charges.create({
amount: 100,
currency: "usd",
card: request.params.cardToken
},{
success: function(httpResponse)
{
response.success("Purchase made!");
},
error: function(httpResponse)
{
response.error(httpResponse);
}
});
});
By looking at the cloud code error logs, I can see that the cloud function purchase was run with a stripe user and with a "cardToken" as input.
The error is:
Failed with: {"name" : "card_error"}
But I don't think it helps me much because that's the most common type of error in the stripe documentation.
Another way I've tried to fix this is through messing around with the "parseVersion" in the config/global.json file since I was referencing a parse questions article with what I thought was an identical problem: http://www.parse.com/questions/stripe-integration-not-working
They said that changing the "parseVersion" to "1.2.5" was the key and that it worked. While it worked for me for a while, I would still get the same error code:
Error: {"name" : "card_error"} (Code: 141, Version: 1.2.20)
I tried changing it to 1.2.20 (as in my error code) and 1.3.3 (which is the most up to date version of the Parse Javascript SDK) and 1.6.1 (which is the most up to date version of the Parse iOS SDK)
Now I get some crazy Python errors that I don't really understand:
Traceback (most recent call last):
File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/bin/parse/__main__.py", line 6, in <module>
File "/usr/local/bin/parse/main.py", line 682, in main
File "/usr/local/bin/parse/main.py", line 170, in handle_deploy
File "/usr/local/bin/parse/parse.py", line 156, in __init__
File "/usr/local/bin/parse/parse.py", line 164, in load_state
File "/usr/local/bin/parse/config_handler.py", line 125, in get_keys_for_app
File "/usr/local/bin/parse/config_handler.py", line 100, in get_info_for_apps
File "/usr/local/bin/parse/config_handler.py", line 112, in get_app_info_for_file
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 290, in load
**kw)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 381, in raw_decode
obj, end = self.scan_once(s, idx)
ValueError: Expecting , delimiter: line 12 column 20 (char 312)
Now even when I change the version back to "1.2.5" I get the same Python error and can't even deploy another version to continue troubleshooting. I'm really stuck and would greatly appreciate the help.
Here is the save function I call when the user first enters the data into parse and hopefully the first purchase is made as well:
- (IBAction)save:(id)sender
{
PTKCard* card = self.paymentView.card;
STPCard* stpcard = [[STPCard alloc] init];
stpcard.number = card.number;
stpcard.expMonth = card.expMonth;
stpcard.expYear = card.expYear;
stpcard.cvc = card.cvc;
[Stripe createTokenWithCard:stpcard completion:^(STPToken *token, NSError *error)
{
if (error)
{
NSLog(@"creating token error: %@", error);
} else
{
NSArray *objectsArray = [NSArray arrayWithObjects:token.tokenId, nil];
NSArray *keysArray = [NSArray arrayWithObjects:@"cardToken", nil];
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjects:objectsArray forKeys:keysArray];
// create a PFObject called "Order" for my own records
PFObject *order = [PFObject objectWithClassName:@"Order"];
order[@"itemName"] = self.restaurant[@"name"];
order[@"name"] = self.currentUser.username;
order[@"email"] = self.currentUser.email;
order[@"address"] = self.currentUser[@"address"];
order[@"price"] = self.total;
// save the order to Parse
[order saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
{
NSLog(@"saved Order");
// call cloud function
[PFCloud callFunctionInBackground:@"purchase" withParameters:dictionary block:^(id object, NSError *error)
{
// if there is no errors
if(error == nil)
{
[[[UIAlertView alloc] initWithTitle:@"It Worked!"
message:@"It charged the card with no error!"
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles: nil] show];
NSLog(@"%@", object);
} else [[[UIAlertView alloc] initWithTitle:@"Error"
message:@"The purchase did not work, your card will not be charged"
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles: nil] show];
}];
}];
}
}];
}