Reputation: 29
Any ideas Guys? How can i cancel the subscription in stripe?
That's my code :
app.post('/cancel-subscription', async(req, res) => {
const {subscriptionId} = req.body
const deleted = await stripe.subscriptions.del(
stripe.customers.id
);
res.send(deleted);
});
Upvotes: 1
Views: 163
Reputation: 4486
I'm not familiar with Stripe's API, but their documentation for cancelling a subscription (https://stripe.com/docs/api/subscriptions/cancel?lang=node) gives an example like:
const deleted = await stripe.subscriptions.del(
'sub_AgOem0qdyCowxn'
);
So, in your case, try something like:
app.post('/cancel-subscription', async(req, res) => {
const { subscriptionId } = req.body;
const deleted = await stripe.subscriptions.del(subscriptionId);
res.send("Cancelled the subscription"); // Just an example, include whatever response necessary.
});
However:
subscriptionId
property).deleted
in its entirety back to the client (in case it contains anything sensitive). You might also need to use res.json
instead of res.send
(depending on the data type).Upvotes: 1