#mulo_checkout-metadata

1 messages ¡ Page 1 of 1 (latest)

kind heathBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1249763434480799746

📝 Have more to share? Add details, code, screenshots, videos, etc. below.

crimson marlin
#

@real gorge no it's not because of Test mode, it's all expected behaviour. Metadata is per object. If you set the metadata on the Checkout Session then the metadata is only on the Checkout Session and not on other related objects like an Invoice. We cover this in https://docs.stripe.com/metadata#copy-metadata

#

At a high level you should use checkout.session.completed for fulfillment with Checkout. See https://docs.stripe.com/payments/checkout/fulfill-orders

Also you shouldn't use invoice.payment_succeeded as it's been deprecated a few years ago, you should prefer invoice.paid which is better (it is sent even for Invoices paid out of band for example)

#

mulo_checkout-metadata

real gorge
#

so I just have to save the sub create id into db, then on the invoice paid get the id to match the db to get my metadata? Is there not a way to get the metadata out of a re-occurring payment directly?

crimson marlin
#

Yes to the first part of your question.

real gorge
#

paypal api gives that custom metadata on subsequent payments, that is handy

crimson marlin
#

And it is definitely possible to do what you are after but I recommend reading that doc I shared end to end first to understand metadata better.
What you can do is configure the metadata on the Subscription instead of the Checkout Session. This is done by passing the subscription_data[metadata] parameter. This will automatically put the metadata on the Subscription that Checkout creates.

Then on an Invoice, you can look at the subscription_details[metadata] property. It's a "cached version" of the Subscription's metadata at the time of Invoice finalization.

real gorge
#

thanks

real gorge
#

overall is a bit unpractical compare to paypal: many people will open the checkout page which I have to save,but not all will actually pay. So I have to save all those sessions

crimson marlin
#

@real gorge I gave you a detailed answer above on how to do this with metadata with the exact flow

#

So that should fit exactly what you want and mirror what Paypal offers

real gorge
crimson marlin
#

what does that mean "the subscription is dynamic"?

real gorge
#

to put it simply, users log through discord, then apply the premium subscription to a server ID, so the metadata should contain both user and disocrd server id

crimson marlin
#

You control the Subscription creation with code in that flow right?

real gorge
#

hence im confused when u mentioned add the metadata on the sub instead of the checkout, since the sub is manually created in the dashboard?

crimson marlin
#

what

#

Why would the Subscription be created manually? You mentioned you were using Checkout in your original question and Checkout would create the Subscription

#

Did I misunderstand that part of your question?

kind heathBOT
real gorge
#

by subscription I mean "plan" where price is set.

let testSubId = 'price_1NH...' //< this i get from creating the sub-tier-plan manually in the dashboard
const session = await stripe.checkout.sessions.create({
         success_url: `https://...`,
         cancel_url: `https://...`,
         line_items: [
           {
             price: testSubId,
             quantity: 1,
           },
         ],
         mode: 'subscription',
         metadata: {
            custom: `${discordUserId}@${guildId}`
          },
       });
crimson marlin
#

In that code, pass subscription_data: { metadata: { custom: `${discordUserId}@${guildId}` } }

real gorge
#

Thanks

#

and just to be 100% sure, this same metadata will continue to be sent to me on all subsequent payouts from the users?

#

since it's a subscription