当前位置: 首页>>代码示例>>Golang>>正文


Golang OrderParams.AppendTo方法代码示例

本文整理汇总了Golang中github.com/stripe/stripe-go.OrderParams.AppendTo方法的典型用法代码示例。如果您正苦于以下问题:Golang OrderParams.AppendTo方法的具体用法?Golang OrderParams.AppendTo怎么用?Golang OrderParams.AppendTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/stripe/stripe-go.OrderParams的用法示例。


在下文中一共展示了OrderParams.AppendTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Get

func (c Client) Get(id string, params *stripe.OrderParams) (*stripe.Order, error) {
	var body *url.Values
	var commonParams *stripe.Params

	if params != nil {
		body = &url.Values{}
		commonParams = &params.Params
		params.AppendTo(body)
	}

	order := &stripe.Order{}
	err := c.B.Call("GET", "/orders/"+id, c.Key, body, commonParams, order)
	return order, err
}
开发者ID:outdoorsy,项目名称:stripe-go,代码行数:14,代码来源:client.go

示例2: New

// New POSTs a new order.
// For more details see https://stripe.com/docs/api#create_order.
func (c Client) New(params *stripe.OrderParams) (*stripe.Order, error) {
	var body *url.Values
	var commonParams *stripe.Params

	if params != nil {
		body = &url.Values{}
		commonParams = &params.Params
		// Required fields
		body.Add("currency", string(params.Currency))

		if params.Customer != "" {
			body.Add("customer", params.Customer)
		}

		if params.Email != "" {
			body.Add("email", params.Email)
		}

		if params.Email != "" {
			body.Add("email", params.Email)
		}

		if len(params.Items) > 0 {
			for _, item := range params.Items {
				body.Add("items[][description]", item.Description)
				body.Add("items[][type]", string(item.Type))
				body.Add("items[][amount]", strconv.FormatInt(item.Amount, 10))
				if item.Currency != "" {
					body.Add("items[][currency]", string(item.Currency))
				}
				if item.Parent != "" {
					body.Add("items[][parent]", item.Parent)
				}
				if item.Quantity != nil {
					body.Add("items[][quantity]", strconv.FormatInt(*item.Quantity, 10))
				}
			}
		}

		body.Add("shipping[address][line1]", params.Shipping.Address.Line1)
		if params.Shipping.Address.Line2 != "" {
			body.Add("shipping[address][line2]", params.Shipping.Address.Line2)
		}
		if params.Shipping.Address.City != "" {
			body.Add("shipping[address][city]", params.Shipping.Address.City)
		}
		if params.Shipping.Address.Country != "" {
			body.Add("shipping[address][country]", params.Shipping.Address.Country)
		}
		if params.Shipping.Address.PostalCode != "" {
			body.Add("shipping[address][postal_code]", params.Shipping.Address.PostalCode)
		}
		if params.Shipping.Address.State != "" {
			body.Add("shipping[address][state]", params.Shipping.Address.State)
		}

		if params.Shipping.Name != "" {
			body.Add("shipping[name]", params.Shipping.Name)
		}
		if params.Shipping.Phone != "" {
			body.Add("shipping[phone]", params.Shipping.Phone)
		}

		params.AppendTo(body)
	}

	p := &stripe.Order{}
	err := c.B.Call("POST", "/orders", c.Key, body, commonParams, p)

	return p, err
}
开发者ID:outdoorsy,项目名称:stripe-go,代码行数:73,代码来源:client.go


注:本文中的github.com/stripe/stripe-go.OrderParams.AppendTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。