stripe文档不包含JS中取消订阅的方法。Java的方法是调用:
Subscription subscription = Subscription.retrieve("sub_49ty4767H20z6a"); subscription.cancel();
字符串我试过:
const subscription = stripe.subscriptions.cancel("sub_49ty4767H20z6a");
型但这行不通。如何在JS中取消订阅?
vd2z7a6w1#
删除订阅以取消订阅是不合理的。以下是您正在寻找的解决方案:
const subscription = await stripe.subscriptions.update( user.stripe_subscription, {cancel_at_period_end: true} );
字符串
0dxa2lsx2#
要取消订阅,请使用delstripe.subscriptions.del("sub_49ty4767H20z6a")个https://stripe.com/docs/api/subscriptions/cancel
del
stripe.subscriptions.del("sub_49ty4767H20z6a")
b4wnujal3#
我的情况是我用**Node js**
Node js
router. Post("/cancel-sub-test", async function (req, res, next) { const { planId, email, phone } = req.body; const customersData = await stripeTest.customers.list(); let findData = customersData.data.find((x) => x.email === email); let customer = findData; // find customer/user const customerGet = await stripeTest.customers.retrieve(customer.id, { expand: ["subscriptions"], }); const [subscriptions] = customerGet.subscriptions.data; //subscription id const resp = await stripeTest.subscriptions.cancel(subscriptions.id); //cancel subscription res.send({ status: resp.status, }); });
3条答案
按热度按时间vd2z7a6w1#
删除订阅以取消订阅是不合理的。以下是您正在寻找的解决方案:
字符串
0dxa2lsx2#
要取消订阅,请使用
del
stripe.subscriptions.del("sub_49ty4767H20z6a")
个https://stripe.com/docs/api/subscriptions/cancel
b4wnujal3#
我的情况是
我用**
Node js
**字符串