stripe / stripe-go

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

You cannot specify both the (deprecated) .Params.Metadata and .Metadata, for SubscriptionCancelParams #1944

Closed J7mbo closed 4 weeks ago

J7mbo commented 4 weeks ago

Describe the bug

I have an error when trying to attach metadata to SubscriptionCancelParams:

You cannot specify both the (deprecated) .Params.Metadata and .Metadata in SubscriptionCancelParams

I get the same error from:

params := &stripe.SubscriptionCancelParams{}
params.AddMetadata("user_id", userID)

if _, err := c.sdk.Subscriptions.Cancel(subscriptionID, params); err != nil {
    return fmt.Errorf("error canceling subscription: %v", err)
}

and also from:

params := &stripe.SubscriptionCancelParams{Params: stripe.Params{Metadata: map[string]string{"user_id": userID}}}

if _, err := c.sdk.Subscriptions.Cancel(subscriptionID, params); err != nil {
    return fmt.Errorf("error canceling subscription: %v", err)
}

Problems:

  1. It's not clear which is not allowed, or if Metadata just isn't allowed at all?
  2. If Metadata isn't allowed, then what's the point of listening to the webhook customer.subscription.deleted if I can't even pluck out the user id of the person that cancelled? If that's the case, then the event is useless for me.

To Reproduce

Try the code above.

Expected behavior

I can attach metadata to SubscriptionCancelParams without an error.

Code snippets

No response

OS

macOS

Go version

go version go1.23.2 darwin/arm64

stripe-go version

v80

API version

latest

Additional context

No response

seanzhang-stripe commented 4 weeks ago

Hi @J7mbo metadata isn't a valid param for subscription cancellation. You can refer to the API reference for the list of params that you can pass when cancelling a subscription.

You can get the customer ID from customer.subscription.deleted event data. If you use a different ID to identify your customer and you want to attach the ID as a metadata to a subscription, you should use the update API