#tounka
1 messages · Page 1 of 1 (latest)
Instead of setting the price ID as metadata, you can simply use Checkout Session Retrieval API and expand line_items field to get the prices of a Checkout Session:
- Checkout Session Retrieval API: https://stripe.com/docs/api/checkout/sessions/retrieve
- Expand: https://stripe.com/docs/api/expanding_objects
i was trying to avoid having to make an extra API call. i would need to make this call every time i receive the checkout.session.completed event
do you not recommend passing the price_id as metadata?
Setting price_id as metadata is fine
cool, so the price_id metadata in the event would be the same as if i made the API call?
Yes!
Also, when creating a new checkout session, let's say i add an internal ID to the metadata. Later a user changes their subscription from monthly to yearly. When i get the customer.subscription.updated event, will the subscription object still have that internalID i originally added in the metadata?
since the subscription object is different does the metadata still carry over
If you set the metadata on subscription_data.metadata of Checkout Session creation, then the metadata will remain on Subscription object even if the subscription is changed from monthly to yearly
subscription_data.metadata: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-metadata
got you. so setting the price_id as metadata on the subscription object would be a bad idea in this case
Yup, unless you also update the metadata when changing the subscription
i plan on using the customer portal, so not sure how i would do that
on another note, will setting the price_id in the metadata on checkout session creation, have any gotchas like this scenario you just mentioned?
i'm assuming not since the checkout.session.completed event is not recurring right and i only receive it once each time a user checks out
i plan on using the customer portal, so not sure how i would do that
Using won't be possible to update subscription's metadata in such case
on another note, will setting the price_id in the metadata on checkout session creation, have any gotchas like this scenario you just mentioned?
if it's one-time payment, i.e.mode: payment, setting price_id in metadata shouldn't be a problem
where do i confirm if its a one-time payment? i'm pretty sure it is. its monthly or yearly subscription
One-time payment will be mode: payment whereas Subscription payment will be mode: subscription
Mode on the Checkout Session: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-mode
Do you use third-party plugin or direct integration with Stripe?
direction integration with stripe
Hi @wheat fractal I'm taking over
You should set mode to subscription when creating a checkout session that includes recurring payment prices in the line_items
hey
river mentioned "if it's one-time payment, i.e. mode: payment, setting price_id in metadata shouldn't be a problem"
my concern is that my mode is CheckoutSessionModeSubscription so will setting price_id as metadata when creating the checkout session cause any problems
No I don't see this as a problem.