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


Golang stripe-go.CustomerParams類代碼示例

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


在下文中一共展示了CustomerParams類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: New

func (c Client) New(params *stripe.CustomerParams) (*stripe.Customer, error) {
	var body *url.Values
	var commonParams *stripe.Params

	if params != nil {
		body = &url.Values{}
		if params.Balance != 0 {
			body.Add("account_balance", strconv.FormatInt(params.Balance, 10))
		}

		if params.Source != nil {
			params.Source.AppendDetails(body, true)
		}

		if len(params.Desc) > 0 {
			body.Add("description", params.Desc)
		}

		if len(params.Coupon) > 0 {
			body.Add("coupon", params.Coupon)
		}

		if len(params.Email) > 0 {
			body.Add("email", params.Email)
		}

		if len(params.Plan) > 0 {
			body.Add("plan", params.Plan)

			if params.Quantity > 0 {
				body.Add("quantity", strconv.FormatUint(params.Quantity, 10))
			}

			if params.TrialEnd > 0 {
				body.Add("trial_end", strconv.FormatInt(params.TrialEnd, 10))
			}
		}

		if params.Shipping != nil {
			params.Shipping.AppendDetails(body)
		}

		commonParams = &params.Params

		params.AppendTo(body)
	}

	cust := &stripe.Customer{}
	err := c.B.Call("POST", "/customers", c.Key, body, commonParams, cust)

	return cust, err
}
開發者ID:outdoorsy,項目名稱:stripe-go,代碼行數:52,代碼來源:client.go

示例2: Update

func (c Client) Update(id string, params *stripe.CustomerParams) (*stripe.Customer, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

	if params != nil {
		commonParams = &params.Params
		body = &stripe.RequestValues{}

		if params.Balance != 0 {
			body.Add("account_balance", strconv.FormatInt(params.Balance, 10))
		} else if params.BalanceZero {
			body.Add("account_balance", "0")
		}

		if params.Source != nil {
			params.Source.AppendDetails(body, true)
		}

		if len(params.Desc) > 0 {
			body.Add("description", params.Desc)
		}

		if len(params.Coupon) > 0 {
			body.Add("coupon", params.Coupon)
		}

		if len(params.Email) > 0 {
			body.Add("email", params.Email)
		}

		if len(params.DefaultSource) > 0 {
			body.Add("default_source", params.DefaultSource)
		}
		params.AppendTo(body)

		if params.Shipping != nil {
			params.Shipping.AppendDetails(body)
		}

		if len(params.BusinessVatID) > 0 {
			body.Add("business_vat_id", params.BusinessVatID)
		}
	}

	cust := &stripe.Customer{}
	err := c.B.Call("POST", "/customers/"+id, c.Key, body, commonParams, cust)

	return cust, err
}
開發者ID:captain401,項目名稱:stripe-go,代碼行數:49,代碼來源:client.go

示例3: Get

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

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

	cust := &stripe.Customer{}
	err := c.B.Call("GET", "/customers/"+id, c.Key, body, commonParams, cust)

	return cust, err
}
開發者ID:outdoorsy,項目名稱:stripe-go,代碼行數:15,代碼來源:client.go


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