2
votes

My Parse cloud function after adding stripe as custom js module to parse is-

main.js

Parse.Cloud.define("createCustomer", function(request, response) {
             //      var Stripe = require("stripe");
                var Stripe = require("cloud/stripe.js")(kStripePrivateKey);
               //    Stripe.initialize(kStripePrivateKey);
                   Stripe.Customers.create(
                                           {
                                           description : request.params.description
                                           },
                                           {
                                           success: function(httpResponse)
                                           {
                                           console.log(httpResponse);
                                           response.success(httpResponse);
                                           },
                                           error: function(httpResponse)
                                           {
                                           console.log(httpResponse.message);
                                           response.error(httpResponse.message);
                                           }
                                           }
                                           );
                   });

and I am trying to call this function as:

**

mCustomerUserName = ParseUser.getCurrentUser().getUsername();

        HashMap<String, Object> params = new HashMap<String, Object>();

        params.put("description",mCustomerUserName);
        ParseCloud.callFunctionInBackground("createCustomer", params, new FunctionCallback<Object>() {
            @Override
            public void done(Object object, ParseException e) {
                if (e == null) {
                    Log.e("SUCCESS CREATE CUSTOMER", "" + object.toString());
                } else {
                    e.printStackTrace();
                    Log.e("", "" + e.getCode() + "/" + e.getMessage());
                }
            }
        });

**

And now my error is:

Result: TypeError: Cannot call method 'create' of undefined at main.js:218:37

please help me out here.

1
One thing to note is Parse no longer support's their Stripe Library. I'd recommend using github.com/matthewarkin/stripe-parse which is based on the latest version of the Stripe Node.js module - Matthew Arkin
Is there any way I could you use stripe's old version on parse cloud ? - Dhaval Patel
The old version is not Stripe's it was built by parse about 4 years ago. They've removed support and documentation from it which makes it a bit hard to debug. There are people saying that downgrading their version of cloud code has fixed issues. - Matthew Arkin
@MatthewArkin I used your gitHub link and imported 'stripe.js' file to my cloud folder. I changed line var Stripe = require("stripe"); to var Stripe = require("cloud/stripe.js")(kStripePrivateKey); and commented both lines var Stripe = require("stripe"); and Stripe.initialize(kStripePrivateKey); And now I get error Result: TypeError: Cannot call method 'create' of undefined at main.js:218:37 - Dhaval Patel
@MatthewArkin Here I am not sure am i suppose to comment line "Stripe.initialize(kStripePrivateKey);" - Dhaval Patel

1 Answers

1
votes

Since you're now using the Stripe library based on Stripe-Node instead of the Parse version, the code for the function call looks a bit different to resemble Node callback style

stripe.customers.create({
  description: request.params.description,
}, function(err, customer) {
  if(err){
    console.log(err);
    response.error(err);
  }
  else{
    console.log(customer);
    response.success(customer);
  }
});