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


Golang stripe-go.RequestValues類代碼示例

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


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

示例1: List

func (c Client) List(params *stripe.BitcoinTransactionListParams) *Iter {
	var body *stripe.RequestValues
	var lp *stripe.ListParams
	var p *stripe.Params

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

		if len(params.Customer) > 0 {
			body.Add("customer", params.Customer)
		}

		params.AppendTo(body)
		lp = &params.ListParams
		p = params.ToParams()
	}

	return &Iter{stripe.GetIter(lp, body, func(b *stripe.RequestValues) ([]interface{}, stripe.ListMeta, error) {
		list := &stripe.BitcoinTransactionList{}
		err := c.B.Call("GET", fmt.Sprintf("/bitcoin/receivers/%v/transactions", params.Receiver), c.Key, b, p, list)

		ret := make([]interface{}, len(list.Values))
		for i, v := range list.Values {
			ret[i] = v
		}

		return ret, list.ListMeta, err
	})}
}
開發者ID:captain401,項目名稱:stripe-go,代碼行數:29,代碼來源:client.go

示例2: List

func (c Client) List(params *stripe.SubListParams) *Iter {
	var body *stripe.RequestValues
	var lp *stripe.ListParams
	var p *stripe.Params

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

		if len(params.Customer) > 0 {
			body.Add("customer", params.Customer)
		}

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

		params.AppendTo(body)

		lp = &params.ListParams
		p = params.ToParams()
	}

	return &Iter{stripe.GetIter(lp, body, func(b *stripe.RequestValues) ([]interface{}, stripe.ListMeta, error) {
		list := &stripe.SubList{}
		err := c.B.Call("GET", "/subscriptions", c.Key, b, p, list)

		ret := make([]interface{}, len(list.Values))
		for i, v := range list.Values {
			ret[i] = v
		}

		return ret, list.ListMeta, err
	})}
}
開發者ID:carriercomm,項目名稱:stripe-go,代碼行數:34,代碼來源:client.go

示例3: Update

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

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

		if params.Default {
			body.Add("default_for_currency", strconv.FormatBool(params.Default))
		}

		params.AppendTo(body)
	}

	ba := &stripe.BankAccount{}
	var err error

	if len(params.Customer) > 0 {
		err = c.B.Call("POST", fmt.Sprintf("/customers/%v/bank_accounts/%v", params.Customer, id), c.Key, body, commonParams, ba)
	} else if len(params.AccountID) > 0 {
		err = c.B.Call("POST", fmt.Sprintf("/accounts/%v/bank_accounts/%v", params.AccountID, id), c.Key, body, commonParams, ba)
	} else {
		err = errors.New("Invalid bank account params: either Customer or AccountID need to be set")
	}

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

示例4: New

func (c Client) New(params *stripe.SubItemParams) (*stripe.SubItem, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params
	token := c.Key

	if params != nil {
		body = &stripe.RequestValues{}
		body.Add("subscription", params.Sub)

		if len(params.Plan) > 0 {
			body.Add("plan", params.Plan)
		}
		if params.Quantity > 0 {
			body.Add("quantity", strconv.FormatUint(params.Quantity, 10))
		} else if params.QuantityZero {
			body.Add("quantity", "0")
		}

		commonParams = &params.Params
		params.AppendTo(body)
	}

	item := &stripe.SubItem{}
	err := c.B.Call("POST", "/subscription_items", token, body, commonParams, item)
	return item, err
}
開發者ID:captain401,項目名稱:stripe-go,代碼行數:26,代碼來源:client.go

示例5: Capture

func (c Client) Capture(id string, params *stripe.CaptureParams) (*stripe.Charge, error) {
	var body *stripe.RequestValues
	token := c.Key
	var commonParams *stripe.Params

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

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

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

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

		params.AppendTo(body)
	}

	charge := &stripe.Charge{}

	err := c.B.Call("POST", fmt.Sprintf("/charges/%v/capture", id), token, body, commonParams, charge)

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

示例6: Update

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

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

		if params.Default {
			body.Add("default_for_currency", strconv.FormatBool(params.Default))
		}

		params.AppendTo(body)
	}

	ba := &stripe.BankAccount{}
	err := c.B.Call("POST", fmt.Sprintf("/accounts/%v/bank_accounts/%v", params.AccountID, id), c.Key, body, commonParams, ba)

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

示例7: Cancel

func (c Client) Cancel(id string, params *stripe.SubParams) (*stripe.Sub, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

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

		if params.EndCancel {
			body.Add("at_period_end", strconv.FormatBool(true))
		}

		params.AppendTo(body)
		commonParams = &params.Params
	}

	sub := &stripe.Sub{}
	err := c.B.Call("DELETE", fmt.Sprintf("/subscriptions/%v", id), c.Key, body, commonParams, sub)

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

示例8: Pay

// Pay pays an order
// For more details see https://stripe.com/docs/api#pay_order.
func (c Client) Pay(id string, params *stripe.OrderPayParams) (*stripe.Order, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

	if params != nil {
		body = &stripe.RequestValues{}
		commonParams = &params.Params
		if params.Source == nil && len(params.Customer) == 0 {
			err := errors.New("Invalid order pay params: either customer or a source must be set")
			return nil, err
		}
		// We can't use `AppendDetails` since that nests under `card`.
		if params.Source != nil {
			if len(params.Source.Token) > 0 {
				body.Add("source", params.Source.Token)
			} else if params.Source.Card != nil {
				c := params.Source.Card

				body.Add("source[object]", "card")
				body.Add("source[number]", c.Number)
				body.Add("source[exp_month]", c.Month)
				body.Add("source[exp_year]", c.Year)

				if len(c.CVC) > 0 {
					body.Add("source[cvc]", c.CVC)
				}

				body.Add("source[name]", c.Name)

				if len(c.Address1) > 0 {
					body.Add("source[address_line1]", c.Address1)
				}

				if len(c.Address2) > 0 {
					body.Add("source[address_line2]", c.Address2)
				}
				if len(c.City) > 0 {
					body.Add("source[address_city]", c.City)
				}

				if len(c.State) > 0 {
					body.Add("source[address_state]", c.State)
				}
				if len(c.Zip) > 0 {
					body.Add("source[address_zip]", c.Zip)
				}
				if len(c.Country) > 0 {
					body.Add("source[address_country]", c.Country)
				}
			}
		}

		if len(params.Customer) > 0 {
			body.Add("customer", params.Customer)
		}

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

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

		params.AppendTo(body)
	}

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

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

示例9: New

func (c Client) New(params *stripe.SubParams) (*stripe.Sub, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params
	token := c.Key

	if params != nil {
		body = &stripe.RequestValues{}
		body.Add("plan", params.Plan)
		body.Add("customer", params.Customer)

		if len(params.Token) > 0 {
			body.Add("card", params.Token)
		} else if params.Card != nil {
			params.Card.AppendDetails(body, true)
		}

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

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

		if params.TaxPercent > 0 {
			body.Add("tax_percent", strconv.FormatFloat(params.TaxPercent, 'f', 2, 64))
		} else if params.TaxPercentZero {
			body.Add("tax_percent", "0")
		}

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

		if params.FeePercent > 0 {
			body.Add("application_fee_percent", strconv.FormatFloat(params.FeePercent, 'f', 2, 64))
		}

		if params.BillingCycleAnchorNow {
			body.Add("billing_cycle_anchor", "now")
		} else if params.BillingCycleAnchor > 0 {
			body.Add("billing_cycle_anchor", strconv.FormatInt(params.BillingCycleAnchor, 10))
		}

		commonParams = &params.Params

		params.AppendTo(body)
	}

	sub := &stripe.Sub{}
	err := c.B.Call("POST", "/subscriptions", token, body, commonParams, sub)

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

示例10: Return

// Return returns all or part of an order.
// For more details see https://stripe.com/docs/api#return_order.
func (c Client) Return(id string, params *stripe.OrderReturnParams) (*stripe.OrderReturn, error) {
	var body *stripe.RequestValues
	var commonParams *stripe.Params

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

		if len(params.Items) > 0 {
			for _, item := range params.Items {
				if item.Description != "" {
					body.Add("items[][description]", item.Description)
				}
				body.Add("items[][type]", string(item.Type))
				if item.Amount > 0 {
					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))
				}
			}
		}

		params.AppendTo(body)
	}

	ret := &stripe.OrderReturn{}
	err := c.B.Call("POST", fmt.Sprintf("/orders/%s/returns", id), c.Key, body, commonParams, ret)

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

示例11: writeAccountParams

func writeAccountParams(
	params *stripe.AccountParams, body *stripe.RequestValues,
) {
	if len(params.Country) > 0 {
		body.Add("country", params.Country)
	}

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

	if params.DebitNegativeBal {
		body.Add("debit_negative_balances", strconv.FormatBool(true))
	} else if params.NoDebitNegativeBal {
		body.Add("debit_negative_balances", strconv.FormatBool(false))
	}

	if len(params.DefaultCurrency) > 0 {
		body.Add("default_currency", params.DefaultCurrency)
	}

	if params.ExternalAccount != nil {
		if len(params.ExternalAccount.Token) > 0 {
			body.Add("external_account", params.ExternalAccount.Token)
		} else {
			body.Add("external_account[object]", "bank_account")
			body.Add("external_account[account_number]", params.ExternalAccount.Account)
			body.Add("external_account[country]", params.ExternalAccount.Country)
			body.Add("external_account[currency]", params.ExternalAccount.Currency)

			if len(params.ExternalAccount.Routing) > 0 {
				body.Add("external_account[routing_number]", params.ExternalAccount.Routing)
			}
		}
	}

	if len(params.Statement) > 0 {
		body.Add("statement_descriptor", params.Statement)
	}

	if len(params.BusinessName) > 0 {
		body.Add("business_name", params.BusinessName)
	}

	if len(params.BusinessPrimaryColor) > 0 {
		body.Add("business_primary_color", params.BusinessPrimaryColor)
	}

	if len(params.BusinessUrl) > 0 {
		body.Add("business_url", params.BusinessUrl)
	}

	if len(params.SupportPhone) > 0 {
		body.Add("support_phone", params.SupportPhone)
	}

	if len(params.SupportEmail) > 0 {
		body.Add("support_email", params.SupportEmail)
	}

	if len(params.SupportUrl) > 0 {
		body.Add("support_url", params.SupportUrl)
	}

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

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

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

	if len(params.FromRecipient) > 0 {
		body.Add("from_recipient", params.FromRecipient)
	}
}
開發者ID:captain401,項目名稱:stripe-go,代碼行數:80,代碼來源:client.go


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