0

我正在尝试基于 Meteor 构建一个使用 Stripe Connect 的平台。我想使用 Stripe 的“首选”身份验证方法(通过 Stripe-Account 标头进行身份验证,https://stripe.com/docs/connect/authentication),以便我可以代表我的用户创建计划和订阅客户。我无法让它工作。我尝试了第二个 params 对象,类似于文档中的示例:

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});

但我得到“调用方法'createStripeProduct'时出现异常错误:条纹:未知参数([object Object])。你的意思是传递一个选项对象吗?请参阅https://github.com/stripe/stripe-node/wiki/传递选项。” 这似乎不能准确反映问题,但提示我尝试在 params 对象本身中添加 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
});

然后我收到以下错误:“调用方法'createStripeProduct'时出现异常错误:收到未知参数:stripe_account”

有任何想法吗?有没有人设法让 Stripe Connect stripe_account 身份验证与 Meteor 一起工作,尤其是 Meteor.wrapAsync(...)?

4

2 回答 2

0

这应该适用wrapAsync,但是请在此处查看我的答案以了解可能存在的问题wrapAsync- Wrapping Stripe 在流星中的 Fibers 中创建客户回调

这里还有一个很棒的视频wrapAsynchttps ://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您在首次创建计划时提供的计划来引用该计划。

于 2015-06-30T00:20:40.743 回答
0

经过多次尝试,现在,我只是设法使用 stripe-sync 包而不是“正常”的一个 + wrapAsync 让它工作。

try{
  var plan = Stripe.plans.create({
    amount: prod.price,
    ...
  },{stripe_account: org.stripe_user_id});
}catch(error){
  // ... process error
}
于 2015-09-11T12:22:28.847 回答