解析 CC - 成功回调未触发
Parse CC - success callback not firing
我已经创建了一个 Cloud Code 函数来创建一个新的 Stripe 客户,它工作正常。我想不通的是 return 调用代码的客户 ID;
调用代码
Parse.Cloud.run(
'createCustomer',
{
email: user.get('email'),
username: user.get('username')
},
{
success: function(customerId) {
// never called
console.log('Customer created: ' + customerId);
},
error: function() {
console.log('Error function');
}
}
);
函数
Parse.Cloud.define(
'createCustomer',
function(request, response) {
var email = request.params.email,
description = 'Username: ' + request.params.username;
Parse.Config.get().then(function(config) {
var Stripe = require('stripe');
Stripe.initialize(config.get('stripe_secret_test'));
Stripe.Customers.create({
description: description,
email: email
})
.then(function(customer) {
console.log(customer.id); // Logs out fine
response.success(customer.id);
});
});
}
);
基本上,调用代码中的成功回调永远不会触发,所以我无法访问我想要的客户 ID return。我错过了什么?谢谢!
事实证明,如果从 Cloud Code 中调用 Cloud 函数似乎效果不佳,它们 运行 但我找不到 return 值的方法。
相反,我使用了 Cloud Code Module,因为此函数只需要从 Cloud Code 中调用。最终代码如下;
调用代码(保存前的用户)
var createCustomerModule = require('cloud/stripe/CreateCustomer.js');
createCustomerModule.createCustomer(
user.get('email'),
user.get('username'),
{
success: function(customer) {
request.object.set('stripeCustomerId', customer.id);
response.success();
},
error: function() {
response.error('Failed to create a new Stripe customer');
}
}
);
函数(cloud/stripe/CreateCustomer.js)
exports.createCustomer = function(email, username, callbacks) {
var description = 'Username: ' + username;
Parse.Config.get().then(function(config) {
var Stripe = require('stripe');
Stripe.initialize(config.get('stripe_secret_test'));
// Attempt to create the customer
Stripe.Customers.create({
description: description,
email: email
})
.then(callbacks.success, callbacks.error);
});
};
我已经创建了一个 Cloud Code 函数来创建一个新的 Stripe 客户,它工作正常。我想不通的是 return 调用代码的客户 ID;
调用代码
Parse.Cloud.run(
'createCustomer',
{
email: user.get('email'),
username: user.get('username')
},
{
success: function(customerId) {
// never called
console.log('Customer created: ' + customerId);
},
error: function() {
console.log('Error function');
}
}
);
函数
Parse.Cloud.define(
'createCustomer',
function(request, response) {
var email = request.params.email,
description = 'Username: ' + request.params.username;
Parse.Config.get().then(function(config) {
var Stripe = require('stripe');
Stripe.initialize(config.get('stripe_secret_test'));
Stripe.Customers.create({
description: description,
email: email
})
.then(function(customer) {
console.log(customer.id); // Logs out fine
response.success(customer.id);
});
});
}
);
基本上,调用代码中的成功回调永远不会触发,所以我无法访问我想要的客户 ID return。我错过了什么?谢谢!
事实证明,如果从 Cloud Code 中调用 Cloud 函数似乎效果不佳,它们 运行 但我找不到 return 值的方法。
相反,我使用了 Cloud Code Module,因为此函数只需要从 Cloud Code 中调用。最终代码如下;
调用代码(保存前的用户)
var createCustomerModule = require('cloud/stripe/CreateCustomer.js');
createCustomerModule.createCustomer(
user.get('email'),
user.get('username'),
{
success: function(customer) {
request.object.set('stripeCustomerId', customer.id);
response.success();
},
error: function() {
response.error('Failed to create a new Stripe customer');
}
}
);
函数(cloud/stripe/CreateCustomer.js)
exports.createCustomer = function(email, username, callbacks) {
var description = 'Username: ' + username;
Parse.Config.get().then(function(config) {
var Stripe = require('stripe');
Stripe.initialize(config.get('stripe_secret_test'));
// Attempt to create the customer
Stripe.Customers.create({
description: description,
email: email
})
.then(callbacks.success, callbacks.error);
});
};