如何在Stripe中为新订阅添加元数据?

huangapple go评论98阅读模式
英文:

How to add metadata to a new subscription in Stripe?

问题

我有这段代码,来自Stripe API文档网站上的示例:

stripe.Key = "my_key"

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

这段代码运行得很好。但是我找不到如何在这个请求中添加元数据,比如 Product: "special-services"

我能在创建订阅时一次性完成吗?如果可以,那么该怎么做?

谢谢!

英文:

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!

答案1

得分: 6

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

stripe.SubParams 嵌入了 stripe.Params,它具有一个方法 AddMeta,用于向 map[string]string 添加元数据信息。

英文:
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.

huangapple
  • 本文由 发表于 2016年12月29日 14:28:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/41374298.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定