stripe / stripe-go

Go library for the Stripe API.
https://stripe.com
MIT License
2.11k stars 456 forks source link

Creating checkout session with metadata not propagating metadata to all events #1771

Closed freshteapot closed 9 months ago

freshteapot commented 9 months ago

Describe the bug

(not sure if it is a bug)

When I create a checkout session with metadata. The "checkout complete" contains the metadata. But the "payment_intent.created" does not

To Reproduce

Using github.com/stripe/stripe-go/v76

params := &stripe.CheckoutSessionParams{
        LineItems: []*stripe.CheckoutSessionLineItemParams{
            product,
        },
        Mode: stripe.String(string(stripe.CheckoutSessionModePayment)),
        Metadata: map[string]string{
            "tier":       tierName,
            "user_uuid":  userUUID,
            "product_id": productID,
            "price_id":   priceReferenceID,
        },
        SuccessURL: stripe.String(successURL),
        CancelURL:  stripe.String(cancelURL),
    }

    session, err := session.New(params)

And then looking at the event stream for the succesful purchase in the stripe dashboard

https://dashboard.stripe.com/test/payments/pi_XXX

Expected behavior

I assumed (possibly the problem) that setting the metadata in stripe.CheckoutSessionParams would cause all events for this payment to include the metadata.

Code snippets

No response

OS

macOS

Go version

1.21.1

stripe-go version

v76.4.0

API version

2023-10-16

Additional context

No response

remi-stripe commented 9 months ago

@freshteapot Github issues are limited to bugs or feature requests with the stripe-go SDK itself. Here this is an integration support question better directed at our support team for 1:1 help instead: https://support.stripe.com/contact

To unblock you, this is all expected behaviour. Metadata apply to the specific object they are set on and don't usually propagate to other objects. We have a handful of exceptions such as PaymentIntent passing its metadata to the Charge on creation but that's extremely rare. Here you set the metadata on the Checkout Session so you will only see metadata on that Checkout Session and nothing else. If you want to see metadata on the PaymentIntent, you need to explicitly set the payement_intent_data[metadata] parameter instead. If you have follow up questions, please work with our support team for help: https://support.stripe.com/contact

freshteapot commented 9 months ago

Thank you for the detailed response.

I am going to embrace the PaymentIntentData and see if that does what I want.

PaymentIntentData: &stripe.CheckoutSessionPaymentIntentDataParams{
    Metadata: map[string]string{
        "tier":       tierName,
        "user_uuid":  userUUID,
        "product_id": productID,
        "price_id":   priceReferenceID,
    },
}