Stripe - how to retrieve customer subscription information and update the database

Hi Wapplers,

I have successfully setup Stripe whereby a user can subscribe to a stripe subscription (using server side not client).

How do I retrieve subscription information from stripe so I can update the user start and end dates in my database? Do I retrieve customer information in a seperate call and then update accordingly? I tried doing it this way but it’s not working.

Any tips would be greatly appreciated…

Thanks

Isn’t the Retrieve Subscription step in Server Connect what you need?

was just doing this yesterday. I had to do manually though as .net isn’t supported with the stripe integration. Postman has a whole set of apis so you can test. Should be pretty straight forward. Maybe shoot us a pic of your action script so we can see what going on, and or what its returning in the web tools?

https://github.com/stripe/stripe-postman

All the Stripe actions return an object, so when you execute the Create Subscription, it will respond with the subscription it created. You can follow up the Create Subscription action with a database update to store the data you need.

Thanks for everyone’s responses. I created the stripe subscription by following instructions on wappler docs https://docs.wappler.io/t/stripe-subscriptions/31491 - I.e by creating a checkout session in my server actions. I then ran a database update step after trying to bind data (like subscription start and end date) to my database records, however the results from the checkout session does not have subscription data to select from. It only has other customer data.

Should I be changing the checkout session to a subscription session?

I thought that was to retrieve subscription products not customer related subscriptions?

The docs you reference should probably be updated. You don’t actually “setup” subscriptions; the instructions are for setting up a Product and one or more Prices (There’s nothing wrong with the steps outlined, I just wouldn’t call it “Subscription”.

A subscription is simply a way to charge on a recurring basis and consists (among other things) a customer and one or more prices.

So using Retrieve subscription does that, it gets a subscription object. There are other actions to retrieve products and prices.

Thank you for that! So starting from scratch in my server action steps should I not be using “create checkout session” but rather a subscription call? Or can I just call retrieve subscription after my initial steps and keep it all as is?

There are several ways to handle all this…I’d stick with the docs for now. I do all my Stripe processing server-side, but the step-by-step you are following is for client side.

I’m following server side instructions on docs. If you scroll down all the way in the link you will see the server side instructions

Then yes, you can call the Retrieve subscription at any time once the subscription has been created.

The checkout session object will have a “subscription” – this is the subscription id of the subscription just created. You can use that to retrieve the entire subscription object since it is not expanded by default.

Thank you. What do I put in for Subscription Exposed ID?

The checkout session should have “subscription”… use that

Thanks… should I also create a subscription as below?

If you followed the steps shown, that is when the subscription is created (in create checkout). You don’t need to do it again.

Thank you! I will give it a try now and let you know how I go…

Error - looks like the subscription exposed ID is wrong… I dont think its checkout session “subscription” object

// 20230601101142
// http://localhost:8100/api/subscribe/subscribetoplan

{
“status”: “500”,
“message”: “stripe.retrieveSubscription: subscription_exposed_id is required.”,
“stack”: “Error: stripe.retrieveSubscription: subscription_exposed_id is required.\n at App.parseRequired (/opt/node_app/lib/core/app.js:637:19)\n at exports.retrieveSubscription (/opt/node_app/lib/modules/stripe.js:4254:40)\n at App._exec (/opt/node_app/lib/core/app.js:599:57)\n at App._exec (/opt/node_app/lib/core/app.js:566:28)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async App.exec (/opt/node_app/lib/core/app.js:535:9)\n at async App.define (/opt/node_app/lib/core/app.js:517:9)”
}

Then it’s time for you to troubleshoot. :slightly_smiling_face:

Tools you can use:

  • Stripe. Login to your account and look at the logs which will show you exactly what is happening

  • output the results of create session

  • Stripe api reference docs.

Wait a sec. I’m being stupid. Create session is only creating the session, not confirming it.

You need a workflow that retrieves The subscription id elsewhere.

You can retrieve the checkout session in a separate flow, if you can’t find the subscription id on the client side as part of the confirm process.

Okay just checked those docs you are following. That uses the Stripe portal for payment.

What I would do, is setup a webhook that is triggered whenever a new subscription is created and you’ll receive the entire subscription object.