【问题标题】:How to get subscriptions attached to a customer in Stripe如何在 Stripe 中获取附加到客户的订阅
【发布时间】:2018-05-18 10:06:41
【问题描述】:

我在 Stripe 上有一个用户,我想取消他的订阅。我在文档中找到了谈论客户对象 (here) 和订阅对象 (here) 的部分,但是如何获取附加到条带用户的订阅 ID?我知道我需要使用这个:

router.get('/cancel-premium', async (req, res, next) => {
    const subscription = await stripe.subscriptions.retrieve('sub_49ty4767H20z6a');
    stripe.subscriptions.del('sub_49ty4767H20z6a', {at_period_end: true});
});

但要做到这一点,我需要附加到客户的订阅 ID

【问题讨论】:

    标签: javascript node.js express stripe-payments stripe.js


    【解决方案1】:

    好吧,没关系。我一定是盲人,这在文档中是正确的。你可以这样做:

    router.get('/cancel-premium', async (req, res, next) => {
        var user = await stripe.customers.retrieve(customerID);
        console.log(user.subscriptions);
        var sub = user.subscriptions.data[0].id;
        const subscription = await stripe.subscriptions.retrieve(sub);
        stripe.subscriptions.del(sub, {at_period_end: false});
        user = await stripe.customers.retrieve(req.user.stripeId);
        console.log(user.subscriptions);
    });
    

    【讨论】:

      猜你喜欢
      • 2019-06-21
      • 2018-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-14
      • 1970-01-01
      • 2015-08-20
      相关资源
      最近更新 更多