Code to make Token
- (IBAction)save:(id)sender
{
STPCard *card = [[STPCard alloc] init];
card.number = self.paymentView.card.number;
card.expMonth = self.paymentView.card.expMonth;
card.expYear = self.paymentView.card.expYear;
card.cvc = self.paymentView.card.cvc;
[[STPAPIClient sharedClient] createTokenWithCard:card
completion:^(STPToken *token, NSError *error) {
if (error) {
NSLog(@"%@",error);
} else {
NSString *myVal = [NSString stringWithFormat:@"%@",token];
NSLog(@"%@",token);
[PFCloud callFunctionInBackground:@"chargeMoney"
withParameters:@{@"token":myVal}
block:^(NSString *result, NSError *error) {
if (!error) {
NSLog(@"from Cloud Code: %@",result);
}
}];
};
}];
}
Code to Charge
Parse.Cloud.define("chargeMoney", function(request, response) {
response.success(request.params.token);
var stripe = require('stripe');
stripe.initialize('sk_test_ldqwdqwdqwdqwdwqdqwd ');
var stripeToken = request.params.token;
var charge = stripe.charges.create({
amount: 1000, // amount in cents, again
currency: "usd",
source: stripeToken,
description: "payinguser@example.com"
}, function(err, charge) {
if (err && err.type === 'StripeCardError') {
// The card has been declined
}
});
});
Error I am getting
[Error]: TypeError: Cannot call method 'create' of undefined
at main.js:11:31 (Code: 141, Version: 1.7.1)
What's the problem with my code. I haven't change anything i am doing according to the documentation.Any onle please suggest whats the issue in my code.