Фон
Я пытаюсь интегрировать платежи полосы на мой сайт. Мне нужно создать пользователя с полосой, используя мой секретный ключ. Я сохраняю этот ключ на своем сервере и вызываю метод сервера для создания пользователя. Может быть, есть еще один способ сделать это? Здесь strip api (скопировано ниже для удобства): https://stripe.com/docs/api/node#create_customer
//stripe api call
var Stripe = StripeAPI('my_secret_key');
Stripe.customers.create({
description: 'Customer for [email protected]',
card: "foobar" // obtained with Stripe.js
}, function(err, customer) {
// asynchronously called
});
Мои попытки и результаты
Я использовал один и тот же код клиента с другим кодом сервера. Все попытки немедленно дают undefined на клиенте console.log(...), но дают правильный ответ на сервере console.log(...):
//client
Meteor.call('stripeCreateUser', options, function(err, result) {
console.log(err, result);
});
//server attempt 1
var Stripe = StripeAPI('my_secret_key');
Meteor.methods({
stripeCreateUser: function(options) {
return Meteor.wrapAsync(Stripe.customers.create({
description: 'Woot! A new customer!',
card: options.ccToken,
plan: options.pricingPlan
}, function (err, res) {
console.log(res, err);
return (res || err);
}));
}
});
//server attempt 2
var Stripe = StripeAPI('my_secret_key');
Meteor.methods({
stripeCreateUser: function(options) {
return Meteor.wrapAsync(Stripe.customers.create({
description: 'Woot! A new customer!',
card: options.ccToken,
plan: options.pricingPlan
}));
}
});
Я также пробовал оба без Meteor.wrapAsync.
EDIT - я также использую этот пакет: https://atmospherejs.com/mrgalaxy/stripe