Finally. OK so here is the most basic code that WORKS for using Parse + Stripe.
iOS Code
- (IBAction)save:(id)sender {
STPCard *card = [[STPCard alloc] init];
card.number = self.paymentTextField.cardNumber;
card.expMonth = self.paymentTextField.expirationMonth;
card.expYear = self.paymentTextField.expirationYear;
card.cvc = self.paymentTextField.cvc;
NSLog(@"%@, %@", self.paymentTextField.cvc, self.paymentTextField.cardNumber);
[[STPAPIClient sharedClient] createTokenWithCard:card
completion:^(STPToken *token, NSError *error) {
if (error) {
NSLog(@"up here");
NSLog(@"error - %@", error);
} else {
//[self createBackendChargeWithToken:token];
NSLog(@"down here");
NSString *myVal = token.tokenId;
NSLog(@"%@",token);
[PFCloud callFunctionInBackground:@"hello" withParameters:@{@"token":myVal}
block:^(NSString *result, NSError *error) {
if (!error) {
NSLog(@"from Cloud Code Res: %@",result);
}
else
{
NSLog(@"from Cloud Code: %@",error);
}
}];
}
}];
}
And then the main.js code:
var Stripe = require('stripe');
Stripe.initialize('sk_test_********'); //replace *** with your key values
Parse.Cloud.define(“hello”, function(request, response) {
var stripeToken = request.params.token;
var charge = Stripe.Charges.create({
amount: 1000, // express dollars in cents
currency: 'usd',
card: stripeToken
}).then(null, function(error) {
console.log('Charging with stripe failed. Error: ' + error);
}).then(function() {
// And we're done!
response.success('Success');
});
});
Now again, this ONLY WORKS if you REVERT YOUR CLOUD CODE to Version 1.5.0 (as other have helped me with). Hope this helps someone else also.