使用流星的 oauth 中的 Stripe stripe_account header 的正确方法
correct way to use Stripe's stripe_account header from oauth with meteor
我正在尝试构建一个基于使用 Stripe Connect 的 Meteor 的平台。我想使用 Stripe 的 "preferred" 身份验证方法(通过 Stripe-Account header、https://stripe.com/docs/connect/authentication 进行身份验证),以便我可以代表我的用户创建计划和订阅客户。我无法让它工作。我尝试使用第二个参数 object,类似于文档中的示例:
var stripeplancreate = Meteor.wrapAsync(Stripe.plans.create, Stripe.plans);
var plan = stripeplancreate({
amount: prod.price,
interval: prod.interv,
name: prod.name,
currency: prod.curr,
id: prod.id+"-"+prod.price+"-"+prod.curr+"-"+prod.interv,
metadata: { prodId: prod._id, orgId: org._id },
statement_descriptor: prod.descr
},{stripe_account: org.stripe_user_id});
但我得到 "Exception while invoking method 'createStripeProduct' Error: Stripe: Unknown arguments ([object Object]). Did you mean to pass an options object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.",它似乎没有准确反映问题,但促使我尝试在参数 object 本身中添加 stripe_account:
var stripeplancreate = Meteor.wrapAsync(Stripe.plans.create, Stripe.plans);
var plan = stripeplancreate({
amount: prod.price,
(...)
statement_descriptor: prod.descr,
stripe_account: org.stripe_user_id
});
然后我收到以下错误:"Exception while invoking method 'createStripeProduct' Error: Received unknown parameter: stripe_account"
有什么想法吗?有没有人设法让 Stripe Connect stripe_account 身份验证与 Meteor 一起工作,尤其是 Meteor.wrapAsync(...)?
这应该适用于 wrapAsync
,但是请在此处查看我的回答以了解 wrapAsync
- :
可能存在的问题
wrapAsync
上还有一个很棒的视频:https://www.eventedmind.com/feed/meteor-meteor-wrapasync
var createStripePlanAsync = function(shoppingCartObject, callback){
stripe.plans.create({
amount: shoppingCartObject.plan.totalPrice,
interval: shoppingCartObject.plan.interval,
name: shoppingCartObject.plan.planName,
currency: "usd",
id: shoppingCartObject.plan.sku //this ID needs to be unique!
}, function(err, plan) {
// asynchronously called
callback(err, plan);
});
};
var createStripePlanSync = Meteor.wrapAsync(createStripePlanAsync);
var myShoppingCart = {
customerInfo: {
name: "Igor Trout"
},
plan: {
totalPrice: 5000,
interval: "month",
name: "Set Sail For Fail Plan",
sku: "062015SSFF"
}
};
// Creates the plan in your Stripe Account
createStripePlanSync(myShoppingCart);
稍后当您为客户订阅计划时,您只需通过首次创建计划时提供的 id
引用该计划。
经过多次尝试,现在,我只是设法使用 stripe-sync 包而不是 "normal" one + wrapAsync 让它工作。
try{
var plan = Stripe.plans.create({
amount: prod.price,
...
},{stripe_account: org.stripe_user_id});
}catch(error){
// ... process error
}
我正在尝试构建一个基于使用 Stripe Connect 的 Meteor 的平台。我想使用 Stripe 的 "preferred" 身份验证方法(通过 Stripe-Account header、https://stripe.com/docs/connect/authentication 进行身份验证),以便我可以代表我的用户创建计划和订阅客户。我无法让它工作。我尝试使用第二个参数 object,类似于文档中的示例:
var stripeplancreate = Meteor.wrapAsync(Stripe.plans.create, Stripe.plans);
var plan = stripeplancreate({
amount: prod.price,
interval: prod.interv,
name: prod.name,
currency: prod.curr,
id: prod.id+"-"+prod.price+"-"+prod.curr+"-"+prod.interv,
metadata: { prodId: prod._id, orgId: org._id },
statement_descriptor: prod.descr
},{stripe_account: org.stripe_user_id});
但我得到 "Exception while invoking method 'createStripeProduct' Error: Stripe: Unknown arguments ([object Object]). Did you mean to pass an options object? See https://github.com/stripe/stripe-node/wiki/Passing-Options.",它似乎没有准确反映问题,但促使我尝试在参数 object 本身中添加 stripe_account:
var stripeplancreate = Meteor.wrapAsync(Stripe.plans.create, Stripe.plans);
var plan = stripeplancreate({
amount: prod.price,
(...)
statement_descriptor: prod.descr,
stripe_account: org.stripe_user_id
});
然后我收到以下错误:"Exception while invoking method 'createStripeProduct' Error: Received unknown parameter: stripe_account"
有什么想法吗?有没有人设法让 Stripe Connect stripe_account 身份验证与 Meteor 一起工作,尤其是 Meteor.wrapAsync(...)?
这应该适用于 wrapAsync
,但是请在此处查看我的回答以了解 wrapAsync
-
wrapAsync
上还有一个很棒的视频:https://www.eventedmind.com/feed/meteor-meteor-wrapasync
var createStripePlanAsync = function(shoppingCartObject, callback){
stripe.plans.create({
amount: shoppingCartObject.plan.totalPrice,
interval: shoppingCartObject.plan.interval,
name: shoppingCartObject.plan.planName,
currency: "usd",
id: shoppingCartObject.plan.sku //this ID needs to be unique!
}, function(err, plan) {
// asynchronously called
callback(err, plan);
});
};
var createStripePlanSync = Meteor.wrapAsync(createStripePlanAsync);
var myShoppingCart = {
customerInfo: {
name: "Igor Trout"
},
plan: {
totalPrice: 5000,
interval: "month",
name: "Set Sail For Fail Plan",
sku: "062015SSFF"
}
};
// Creates the plan in your Stripe Account
createStripePlanSync(myShoppingCart);
稍后当您为客户订阅计划时,您只需通过首次创建计划时提供的 id
引用该计划。
经过多次尝试,现在,我只是设法使用 stripe-sync 包而不是 "normal" one + wrapAsync 让它工作。
try{
var plan = Stripe.plans.create({
amount: prod.price,
...
},{stripe_account: org.stripe_user_id});
}catch(error){
// ... process error
}