當前位置: 首頁>>代碼示例>>Golang>>正文


Golang stripe-go.ProductParams類代碼示例

本文整理匯總了Golang中github.com/stripe/stripe-go.ProductParams的典型用法代碼示例。如果您正苦於以下問題:Golang ProductParams類的具體用法?Golang ProductParams怎麽用?Golang ProductParams使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ProductParams類的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
}
開發者ID:captain401,項目名稱:stripe-go,代碼行數:54,代碼來源:client.go

示例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
}
開發者ID:outdoorsy,項目名稱:stripe-go,代碼行數:39,代碼來源:client.go

示例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
}
開發者ID:captain401,項目名稱:stripe-go,代碼行數:72,代碼來源:client.go


注:本文中的github.com/stripe/stripe-go.ProductParams類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。