问题
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