本文整理匯總了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 = ¶ms.Params
params.AppendTo(body)
}
order := &stripe.Order{}
err := c.B.Call("GET", "/orders/"+id, c.Key, body, commonParams, order)
return order, err
}
示例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 = ¶ms.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
}