0

I'm working with Parse + Stripe. My Parse Cloud Code version is 1.5.0 here is my source code in app side.

func performStripeOperation() {

    STPAPIClient.sharedClient().createTokenWithCard(stripCard, completion: { (token: STPToken?, error: NSError?) -> Void in

        if error == nil {
            // credit card details are correct
            print(token!.tokenId)
            var myVal: String = token!.tokenId
            NSLog("%@", token!)
            PFCloud.callFunctionInBackground("pay", withParameters: ["token": myVal], block: {(result: AnyObject?, error: NSError?) -> Void in
                if (error == nil) {
                    NSLog("from Cloud Code Res: %@", result as! String )
                }
                else {
                    NSLog("from Cloud Code: %@", error!)
                }
            })


        } else {
            print("Token error.")
            // Handle Error here
            NSLog("ERRRRR = %@", error!)
            let alert = UIAlertController(title: "Please try again", message: "\(error!.localizedDescription)", preferredStyle: .Alert)
            let actionOk = UIAlertAction(title: "Ok", style: .Default, handler: nil)
            alert.addAction(actionOk)
            self.presentViewController(alert, animated: true, completion: nil)
            //let alert: UIAlertView = UIAlertView(title: "Please try again", message: "\(error!.localizedDescription)", delegate: nil, cancelButtonTitle: "OK", otherButtonTitles: "")
            //alert.show()

        }


    })
}

and for main.js I followed source code from here

var Stripe = require('stripe');
Stripe.initialize('sk_test_******************'); 
Parse.Cloud.define("pay", function(request, response) {
var stripeToken = request.params.token;
var charge = Stripe.Charges.create({
    amount: 1000, // 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, I got this error

[Error]: TypeError: Object [object Object] has no method 'isString'
    at request (stripe.js:49:25)
    at post (stripe.js:117:12)
    at Object.module.exports.Charges.create (stripe.js:157:16)
    at main.js:27:29 (Code: 141, Version: 1.12.0)
2016-04-05 22:56:35.886 Muzicue[39049:832833] from Cloud Code: Error Domain=Parse Code=141 "TypeError: Object [object Object] has no method 'isString'
    at request (stripe.js:49:25)
    at post (stripe.js:117:12)
    at Object.module.exports.Charges.create (stripe.js:157:16)
    at main.js:27:29" UserInfo={code=141, temporary=0, error=TypeError: Object [object Object] has no method 'isString'
    at request (stripe.js:49:25)
    at post (stripe.js:117:12)
    at Object.module.exports.Charges.create (stripe.js:157:16)
    at main.js:27:29, NSLocalizedDescription=TypeError: Object [object Object] has no method 'isString'
    at request (stripe.js:49:25)
    at post (stripe.js:117:12)
    at Object.module.exports.Charges.create (stripe.js:157:16)
    at main.js:27:29}

Any idea where I'm doing wrong? thanks...

Community
  • 1
  • 1
Samira
  • 215
  • 2
  • 14

1 Answers1

0

After I changed the main.js to this, it worked. response.success and response.error both need to be implemented.

var Stripe = require('stripe');

Stripe.initialize('sk_test_**********************');

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

Stripe.Charges.create({

//  amount: request.params.amount,

amount: 1000,

currency: "usd",

card: request.params.token

}).then(

function(param) {

    console.log('Made successful card charge with Stripe!');

    response.success("Stripe charge succeeded.");

},

function(error) {

    console.log('Charging with stripe failed. Error: ' + error);

    response.error(error.message);

}

)

});
Samira
  • 215
  • 2
  • 14