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


Golang stripe-go.OrderParams類代碼示例

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


在下文中一共展示了OrderParams類的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類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。