Parse.com + Cloud code + Android + Stripe

微笑、不失礼 提交于 2020-01-01 17:25:11

问题


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:


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


来源:https://stackoverflow.com/questions/35032828/parse-com-cloud-code-android-stripe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!