This is an example of integration with stripe to create and manage your subscriptions, just in your backend. This api provides the links and redirects you to where you need it.
Libraries:
- Stripe
- class-transformer
- class-validator
You will need of Node.js v16 or up.
Install the dependencies and devDependencies and start the server.
yarn
yarn start:dev
To create a new subscription:
curl --request POST \
--url http://localhost:3000/payment \
--header 'Content-Type: application/json' \
--data '{
"email":"YOUR_EMAIL",
"priceId": "SOME_PRICE_ID"
}'
When a subscription is successful:
curl --request GET \
--url 'http://localhost:3000/payment/success?success=true&session_id={SESSION_ID}'
When a subscription is canceled:
curl --request GET \
--url 'http://localhost:3000/payment/canceled?canceled=true'
To generate and redirect the user to the Portal in order to manage their charges:
curl --request POST \
--url http://localhost:3000/payment/portal \
--header 'Content-Type: application/json' \
--data '{
"sessionId": "SESSION_ID"
}'
MIT Thiago Novato - tnovato.com