NodeJS Stripe在JS中取消订阅

vbopmzt1  于 2023-08-04  发布在  Node.js
关注(0)|答案(3)|浏览(141)

stripe文档不包含JS中取消订阅的方法。Java的方法是调用:

Subscription subscription = Subscription.retrieve("sub_49ty4767H20z6a");
subscription.cancel();

字符串
我试过:

const subscription = stripe.subscriptions.cancel("sub_49ty4767H20z6a");


但这行不通。如何在JS中取消订阅?

vd2z7a6w

vd2z7a6w1#

删除订阅以取消订阅是不合理的。以下是您正在寻找的解决方案:

const subscription = await stripe.subscriptions.update(
  user.stripe_subscription,
  {cancel_at_period_end: true}
);

字符串

0dxa2lsx

0dxa2lsx2#

要取消订阅,请使用del
stripe.subscriptions.del("sub_49ty4767H20z6a")
https://stripe.com/docs/api/subscriptions/cancel

b4wnujal

b4wnujal3#

我的情况是
我用**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,
 });

});

字符串

相关问题