本文整理汇总了Golang中github.com/stripe/stripe-go.RequestValues.Add方法的典型用法代码示例。如果您正苦于以下问题:Golang RequestValues.Add方法的具体用法?Golang RequestValues.Add怎么用?Golang RequestValues.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/stripe/stripe-go.RequestValues
的用法示例。
在下文中一共展示了RequestValues.Add方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: List
func (c Client) List(params *stripe.RecipientListParams) *Iter {
var body *stripe.RequestValues
var lp *stripe.ListParams
var p *stripe.Params
if params != nil {
body = &stripe.RequestValues{}
if params.Verified {
body.Add("verified", strconv.FormatBool(true))
}
params.AppendTo(body)
lp = ¶ms.ListParams
p = params.ToParams()
}
return &Iter{stripe.GetIter(lp, body, func(b *stripe.RequestValues) ([]interface{}, stripe.ListMeta, error) {
list := &stripe.RecipientList{}
err := c.B.Call("GET", "/recipients", 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
})}
}
示例2: 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 = ¶ms.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
}
示例3: 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 = ¶ms.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
})}
}
示例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 = ¶ms.Params
params.AppendTo(body)
}
item := &stripe.SubItem{}
err := c.B.Call("POST", "/subscription_items", token, body, commonParams, item)
return item, err
}
示例5: 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 = ¶ms.Params
}
sub := &stripe.Sub{}
err := c.B.Call("DELETE", fmt.Sprintf("/subscriptions/%v", id), c.Key, body, commonParams, sub)
return sub, err
}
示例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 = ¶ms.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
}
示例7: 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 = ¶ms.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
}
示例8: 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
}
示例9: 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 = ¶ms.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
}
示例10: 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)
}
}
示例11: 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 = ¶ms.Params
params.AppendTo(body)
}
sub := &stripe.Sub{}
err := c.B.Call("POST", "/subscriptions", token, body, commonParams, sub)
return sub, err
}