Parse + Stripe iOS Main.Js

Store credit card with Stripe and Parse. has no method each error

Revert your cloud code version to 1.5.0 or earlier.

Explained here : Parse + Stripe iOS main.js

Parse returns error for Stripe module

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.

Issues while integrating Stripe with Parse

After spending one night finally I spotted my errors there is Three errors in my code:

Error 1

Replace this

   NSString *myVal = [NSString stringWithFormat:@"%@",token];

with

  NSString *myVal = [NSString stringWithFormat:@"%@",token.tokenId];

Error 2

stripe.initialize('sk_test_ldqwdqwdqwdqwdwqdqwd ');

Their is extra space in key after last word i.e 'd'.

Error 3

Remove this

 response.success(request.params.token);

from top

Finally working code is ::

Create 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 = 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);
}

}];

};
}];

}

Parse Cloud code (main.js)

// Use Parse.Cloud.define to define as many cloud functions as you want.
// For example:
var stripe = require('stripe');
stripe.initialize('sk_test_lweGasdaqwMKnZRndg5123G');
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);

});

});

Parse-Stripe: Payment after a task is done

Run an afterSave for Task on Cloud Code. If the Task is marked as complete, generate the token using the proper credit card (I'd recommend a pointer structure of Task -> Client -> Credit Card classes) and send it to Stripe. Don't forget to use Parse.Cloud.useMasterKey();



Related Topics



Leave a reply



Submit