本文整理汇总了Golang中github.com/stripe/stripe-go.ProductParams.AppendTo方法的典型用法代码示例。如果您正苦于以下问题:Golang ProductParams.AppendTo方法的具体用法?Golang ProductParams.AppendTo怎么用?Golang ProductParams.AppendTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/stripe/stripe-go.ProductParams
的用法示例。
在下文中一共展示了ProductParams.AppendTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Update
// Update updates a product's properties.
// For more details see https://stripe.com/docs/api#update_product.
func (c Client) Update(id string, params *stripe.ProductParams) (*stripe.Product, error) {
var body *stripe.RequestValues
var commonParams *stripe.Params
if params != nil {
body = &stripe.RequestValues{}
if len(params.Name) > 0 {
body.Add("name", params.Name)
}
if len(params.Desc) > 0 {
body.Add("description", params.Desc)
}
if params.Active != nil {
body.Add("active", strconv.FormatBool(*(params.Active)))
}
if len(params.Images) > 0 {
for _, v := range params.Images {
body.Add("images[]", v)
}
}
if len(params.URL) > 0 {
body.Add("url", params.URL)
}
// Passing empty attributes should unset the attributes.
if params.Attrs != nil {
if len(params.Attrs) > 0 {
for _, v := range params.Attrs {
body.Add("attributes[]", v)
}
} else {
body.Add("attributes", "")
}
}
for _, app := range params.DeactivateOn {
body.Add("deactivate_on[]", app)
}
params.AppendTo(body)
}
p := &stripe.Product{}
err := c.B.Call("POST", "/products/"+id, c.Key, body, commonParams, p)
return p, err
}
示例2: Update
// Update updates a product's properties.
// For more details see https://stripe.com/docs/api#update_product.
func (c Client) Update(id string, params *stripe.ProductParams) (*stripe.Product, error) {
var body *url.Values
var commonParams *stripe.Params
if params != nil {
body = &url.Values{}
if len(params.Name) > 0 {
body.Add("name", params.Name)
}
if len(params.Desc) > 0 {
body.Add("description", params.Desc)
}
if params.Active != nil {
body.Add("active", strconv.FormatBool(*(params.Active)))
}
if len(params.Images) > 0 {
for _, v := range params.Images {
body.Add("images[]", v)
}
}
if len(params.URL) > 0 {
body.Add("url", params.URL)
}
params.AppendTo(body)
}
p := &stripe.Product{}
err := c.B.Call("POST", "/products/"+id, c.Key, body, commonParams, p)
return p, err
}
示例3: New
// New POSTs a new product.
// For more details see https://stripe.com/docs/api#create_product.
func (c Client) New(params *stripe.ProductParams) (*stripe.Product, error) {
var body *stripe.RequestValues
var commonParams *stripe.Params
if params != nil {
body = &stripe.RequestValues{}
// Required fields
body.Add("name", params.Name)
// Optional fields
if len(params.Desc) > 0 {
body.Add("description", params.Desc)
}
if params.ID != "" {
body.Add("id", params.ID)
}
if params.Active != nil {
body.Add("active", strconv.FormatBool(*(params.Active)))
}
if params.Caption != "" {
body.Add("caption", params.Caption)
}
if len(params.Attrs) > 0 {
for _, v := range params.Attrs {
body.Add("attributes[]", v)
}
}
if len(params.Images) > 0 {
for _, v := range params.Images {
body.Add("images[]", v)
}
}
if len(params.URL) > 0 {
body.Add("url", params.URL)
}
if params.Shippable != nil {
body.Add("shippable", strconv.FormatBool(*(params.Shippable)))
}
if params.PackageDimensions != nil {
body.Add("package_dimensions[height]",
fmt.Sprintf("%.2f", params.PackageDimensions.Height))
body.Add("package_dimensions[length]",
fmt.Sprintf("%.2f", params.PackageDimensions.Length))
body.Add("package_dimensions[width]",
fmt.Sprintf("%.2f", params.PackageDimensions.Width))
body.Add("package_dimensions[weight]",
fmt.Sprintf("%.2f", params.PackageDimensions.Weight))
}
for _, app := range params.DeactivateOn {
body.Add("deactivate_on[]", app)
}
params.AppendTo(body)
}
p := &stripe.Product{}
err := c.B.Call("POST", "/products", c.Key, body, commonParams, p)
return p, err
}