Parse.com +云代码+ Android + Stripe [英] Parse.com + Cloud code + Android + Stripe
本文介绍了Parse.com +云代码+ Android + Stripe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Parse云功能是 -
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
},
{
成功:函数(httpResponse)
{
console.log(httpResponse);
response.success(httpResponse);
},
错误:function(httpResponse)
{
console.log(httpResponse.message);
response.error(httpResponse.message);
}
}
);
});
我试图将此功能称为:
**
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());
}
}
});
**
现在我的错误是:
结果:TypeError:无法在main.js调用undefined方法'create':218:37
<请帮助我。
解决方案
由于您现在使用的是基于Stripe-Node的Stripe库而不是解析版本,函数调用的代码看起来有点不同,类似于Node回调样式
stripe.customers.create({
description:request.params.description,
},function(err,customer){
if(err){
console.log(err);
response。错误(错误);
}
其他{
console.log(客户);
response.success(客户);
}
});
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.
解决方案
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);
}
});
这篇关于Parse.com +云代码+ Android + Stripe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文