One time and susbcription metadata

351 views
Skip to first unread message

MALIK forz

unread,
Aug 13, 2022, 1:02:54 PM8/13/22
to Stripe API Discussion
Hello,  so I am implementing stripe subscription, and I want to pass metadata  but it doesn't work when using metadata  and also when using susbcription_data metadata,  
any solution for this? and also for one time payment same issue.   thank you so much!  

Remi J.

unread,
Aug 13, 2022, 2:04:48 PM8/13/22
to api-d...@lists.stripe.com
Hello Malik,

You didn't give much context in your ask either in what you do in your code or what isn't working unfortunately. You mentioned `subscription_data` though so I'm going to assume you are using Checkout and its Sessions API. That API does let you configure the metadata that should be set on the resulting primary object depending on the Session's `mode`:
* For `payment` you would pass `payment_intent_data[metadata]` and the resulting PaymentIntent would have its `metadata` property set from it.
* For `subscription` you would pass `subscription_data[metadata]` and the resulting Subscription would have its `metadata` property set from it.
* For `setup` you would pass `setup_intent_data[metadata]` and the resulting Subscription would have its `metadata` property set from it.

In each case, you then have to go through Checkout and complete the Session. After that you will either get a redirect or the `checkout.session.completed` Event. In both cases, you won't see the metadata there since the underlying primary object created would not be returned in the payload, just its id. So for example you will see `subscription: 'sub_123456'` which is the id of that Subscription that was created as a result. Then, you can use the Retrieve Subscription API to retrieve the entire resource and confirm the `metadata` on it is set properly.

Alternatively, you can make use of our Expand feature (https://stripe.com/docs/expand) which lets you retrieve multiple separate objects at the same time. For example you can call the Retrieve Checkout Session API and also expand the underlying Subscription, SetupIntent or PaymentIntent that was created after the Session completed successfully.

It is also important to note that metadata does not propagate between objects except in really specific cases. If you set `metadata` on the Checkout Session itself, it will only be on the Session object, nothing else. That's why you need to explicitly use `payment_intent_data[metadata]` for example for the `metadata` to appear on the PaymentIntent, but in turn it's not reflected back on the Session itself.

Overall, this definitely works as expected and is widely used by developers working with Checkout! If you have a follow up question, I'd recommend working with our support team directly and providing clear examples where it isn't working and they will be able to help you narrow it down. You can contact them here: https://support.stripe.com/contact

Best,
Remi

On Sat, Aug 13, 2022 at 10:02 AM MALIK forz <forzlam...@gmail.com> wrote:
Hello,  so I am implementing stripe subscription, and I want to pass metadata  but it doesn't work when using metadata  and also when using susbcription_data metadata,  
any solution for this? and also for one time payment same issue.   thank you so much!  

--
To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss...@lists.stripe.com.

MALIK forz

unread,
Aug 20, 2022, 12:12:08 PM8/20/22
to Stripe API Discussion, re...@stripe.com

Hello,  thank you so much for your detaileld response, however, the issue wasn't in the code itself but it was in the python /stripe library, we tried the same code structure in node js and it worked fine!  

Remi J.

unread,
Aug 20, 2022, 12:13:31 PM8/20/22
to MALIK forz, Stripe API Discussion
Hello,

There's no issue with stripe-python that could lead to this behaviour. The only thing that can cause this is that you either don't confirm the PaymentIntent properly client-side or that your server-side code creates a brand new PaymentIntent when it shouldn't.

Hope this helps!
Best,
Remi
Reply all
Reply to author
Forward
0 new messages