本文整理汇总了Golang中github.com/stripe/stripe-go.SKUParams类的典型用法代码示例。如果您正苦于以下问题:Golang SKUParams类的具体用法?Golang SKUParams怎么用?Golang SKUParams使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SKUParams类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Update
// Update updates a SKU's properties.
// For more details see https://stripe.com/docs/api#update_sku.
func (c Client) Update(id string, params *stripe.SKUParams) (*stripe.SKU, error) {
var body *url.Values
var commonParams *stripe.Params
if params != nil {
body = &url.Values{}
// Required fields
if params.Price > 0 {
body.Add("price", strconv.FormatInt(params.Price, 10))
}
if len(params.Currency) > 0 {
body.Add("currency", params.Currency)
}
// Optional fields
if params.Active != nil {
body.Add("active", strconv.FormatBool(*(params.Active)))
}
if len(params.Desc) > 0 {
body.Add("description", params.Desc)
}
if len(params.Image) > 0 {
body.Add("image", params.Image)
}
inventory := params.Inventory
if len(inventory.Type) > 0 {
body.Add("inventory[type]", inventory.Type)
switch inventory.Type {
case "finite":
body.Add("inventory[quantity]", strconv.FormatInt(inventory.Quantity, 10))
case "bucket":
body.Add("inventory[value]", inventory.Value)
}
}
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))
}
params.AppendTo(body)
}
p := &stripe.SKU{}
err := c.B.Call("POST", "/skus/"+id, c.Key, body, commonParams, p)
return p, err
}
示例2: Get
func (c Client) Get(id string, params *stripe.SKUParams) (*stripe.SKU, error) {
sku := &stripe.SKU{}
var body *stripe.RequestValues
var commonParams *stripe.Params
if params != nil {
commonParams = ¶ms.Params
body = &stripe.RequestValues{}
params.AppendTo(body)
}
err := c.B.Call("GET", "/skus/"+id, c.Key, body, commonParams, sku)
return sku, err
}