I want to charge a customer on my web app. I want 2 main features:
I want to retrieve a subscription which gets created in stripe dashboard when the user signs up from landing page and pay the subscription fees.
I want let the user cancel the subscription from the dashboard itself by clicking on a button Cancel and then confirmed cancel.
To perform these actions I have found out that I will need to use the stripe APIs for retrieve and cancel subscription end points from stripe documentaion api =>
Source: https://stripe.com/docs/api/subscriptions/retrieve?lang=node
So my questions is how the method of cancellation or retrieval gets called since only the decaltion of method has been given.
This is the code for the cancel using DELETE endpoint and passing the params as subscription id.
const stripe = require('stripe')('sk_test_51HtWQoGQ1LZjNPNJ3xH0UHVUuEIb2jPtQanATwPgQbaWeJOfT28vckXQEZbFdFZIBmMMNL6qspAT5B8J3dpqSAv600RUyizWkq');
const deleted = await stripe.subscriptions.del(
'sub_Im6JO8OJWyMIaw'
);
and this is the route link:
DELETE /v1/subscriptions/:id
My doubt is do I need to just keep the above code inside this end point and call it on cancel click button merely? And then the subscription will get cancelled? And same for other operations as well?
Would like to know how to run these?
You likely want to make some changes to your own data as well, but yes, that's how you delete a Subscription in Stripe using Node.js.