#mxd

1 messages ยท Page 1 of 1 (latest)

thorn marlinBOT
round shell
#

You can't add metadata to Events, but you can add metadata to pretty much any of the objects contained within the events. Can you elaborate more on what you're trying to do?

half swan
#

yeah so from this instruction here: If need user_id: user_id to provision the subscription (add it to metadata)

#

basically I need to retrieve that user_id or some form of id from the webhook so i can store it in the database

#

What Im trying to do is, provision access to paid features, so once the customer pays, I have an sqlalchemy trigger that stores info on that user and the subscription type..then reroute them to a paid membership page that checks who the user is and displays features relevant to that user and their subscription

round shell
#

Ah, okay. So which webhook event are you listening for that you need this info from? It's okay if you're not sure which is best, but I figured I'd start there

half swan
#

yeah Idk because I looked through the event types and I only did: checkout.session.completed customer.bank_account.updated customer.card.updated customer.source.updated customer.subscription.created customer.subscription.deleted invoice.paid invoice.payment_failed

#

looking at the meta data, its empty: "metadata": { },

#

just dont know how to get that in the webhook

velvet shoal
#

๐Ÿ‘‹ stepping in for my colleague who needs to step away

half swan
velvet shoal
#

in the docs example, # 3 above mentions that, as part of this example company's integration, they add metadata to Checkout sessions and subscriptions

half swan
#

yeah, but I dont see that option on the webhooks page

#

i think I saw it once, the add meta data option

velvet shoal
#

metadata will be empty unless explicitly added. metadata isn't added to a webhook but an object (e.g. PaymentIntent, Charge, Checkout Session, etc.)

half swan
#

idk how to do that

velvet shoal
half swan
#

better yet how do I do that here: ``` if event_type == 'checkout.session.completed':
# Payment is successful and the subscription is created.
# You should provision the subscription and save the customer ID to your database.
print(data)
elif event_type == 'invoice.paid':
# Continue to provision the subscription as payments continue to be made.
# Store the status in your database and check when a user accesses your service.
# This approach helps you avoid hitting rate limits.
print(data)
elif event_type == 'invoice.payment_failed':
# The payment failed or the customer does not have a valid payment method.
# The subscription becomes past_due. Notify your customer and send them to the
# customer portal to update their payment information.
print(data)
else:
print('Unhandled event type {}'.format(event_type))

return jsonify({'status': 'success'})```
#

save the customer ID to your database

velvet shoal
#

okay, the "customer ID" in this case is completely separate from any metadata you add. the comment above is referring to the customer property on the checkout session object

#

are you referencing a specific doc that includes the webhook handler code above?

half swan
#

I cant create the product because it doesn't trigger the webhook, so I created the product in the pricing table feature in the stripe dashboard

#

is the meta data this thing?

velvet shoal
#

Okay, I'm not exactly sure what you're trying to do. that webhook handler code has conditionals based on the event type. if you need to inspect metadata on the checkout session, you'll need to inspect data_object.metadata

half swan
#

ok so now, when a user checks out, how do I get the user id?

#

like this?

velvet shoal
#

I'm not sure you're understanding how metadata works

#

Metadata should be used if you want to store key/value pairs on Stripe objects. These values are likely values that you use to identify items in your own databases

#

For example, if you don't want to only rely on Stripe's Customer IDs (that are in the format "cus_###...") and use your own IDs to identify customers on your end, you can add your internal customer IDs as metadata on customer objects. Does this make sense?

half swan
#

it is a little bit

velvet shoal
#

got it. does your team need to use metadata, then?

half swan
#

does stripe have phone support or is it only discord?

velvet shoal