Sergei Basharov
Sergei Basharov

Reputation: 53850

How to add metadata to a new subscription in Stripe?

I have this code, from the examples on Stripe API docs site:

stripe.Key = "my_key"

s, err := sub.New(&stripe.SubParams{
    Customer: "test_customer",
    Plan: "month-plan",

})

This code works just fine. But I couldn't find how to add metadata to this request, like Product: "special-services".

Can I do it in one request on subscription creation, and if so, then how?

Thanks!

Upvotes: 5

Views: 618

Answers (2)

Akrem Chabchoub
Akrem Chabchoub

Reputation: 634

You can use this approach also:

subParams := &stripe.SubParams{
Customer: "test_customer",
Plan: "month-plan",
Params: stripe.Params{
    Metadata: map[string]string{
        "Product": "special-services",
    },
  },
}
s, err := sub.New(subParams)

Upvotes: 0

John S Perayil
John S Perayil

Reputation: 6345

subParams := &stripe.SubParams{
    Customer: "test_customer",
    Plan: "month-plan",
}
subParams.AddMeta("Product","special-services")
s, err := sub.New(subParams)

stripe.SubParams embeds stripe.Params which has a method AddMeta, which adds meta info to a map[string]string.

Upvotes: 7

Related Questions