【发布时间】:2023-03-03 07:36:21
【问题描述】:
背景
我正在尝试将条带支付功能集成到我的网站中。我需要使用我的私有条带密钥创建一个条带用户。我将此密钥存储在我的服务器上,并调用服务器方法来创建用户。也许还有另一种方法可以做到这一点?这是条带api(为方便起见,复制如下): https://stripe.com/docs/api/node#create_customer
//stripe api call
var Stripe = StripeAPI('my_secret_key');
Stripe.customers.create({
description: 'Customer for test@example.com',
card: "foobar" // obtained with Stripe.js
}, function(err, customer) {
// asynchronously called
});
我的尝试和结果
我一直在使用相同的客户端代码和不同的服务器代码。所有尝试立即在客户端的 console.log(...) 上给出 undefined 但在服务器 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。
编辑 - 我也在使用这个包: https://atmospherejs.com/mrgalaxy/stripe
【问题讨论】:
-
哦,嘿,用谷歌搜索了这个问题,它几乎与我的代码相同
标签: javascript meteor stripe-payments