当前位置: 首页>>代码示例>>Golang>>正文


Golang stripe-go.SubParams类代码示例

本文整理汇总了Golang中github.com/stripe/stripe-go.SubParams的典型用法代码示例。如果您正苦于以下问题:Golang SubParams类的具体用法?Golang SubParams怎么用?Golang SubParams使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SubParams类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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

示例2: Update

func (c Client) Update(id string, params *stripe.SubParams) (*stripe.Sub, error) {
	body := &url.Values{}

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

	if params.NoProrate {
		body.Add("prorate", strconv.FormatBool(false))
	}

	if len(params.Token) > 0 {
		body.Add("card", params.Token)
	} else if params.Card != nil {
		if len(params.Card.Token) > 0 {
			body.Add("card", params.Card.Token)
		} else {
			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.Quantity > 0 {
		body.Add("quantity", strconv.FormatUint(params.Quantity, 10))
	}

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

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

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

	params.AppendTo(body)

	sub := &stripe.Sub{}
	err := c.B.Call("POST", fmt.Sprintf("/customers/%v/subscriptions/%v", params.Customer, id), token, body, &params.Params, sub)

	return sub, err
}
开发者ID:outdoorsy,项目名称:stripe-go,代码行数:55,代码来源:client.go

示例3: Cancel

func (c Client) Cancel(id string, params *stripe.SubParams) error {
	body := &url.Values{}

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

	params.AppendTo(body)

	return c.B.Call("DELETE", fmt.Sprintf("/customers/%v/subscriptions/%v", params.Customer, id), c.Key, body, &params.Params, nil)
}
开发者ID:zkirill,项目名称:stripe-go,代码行数:11,代码来源:client.go

示例4: Get

func (c Client) Get(id string, params *stripe.SubParams) (*stripe.Sub, error) {
	if params == nil {
		return nil, fmt.Errorf("params cannot be nil, and params.Customer must be set")
	}

	body := &url.Values{}
	params.AppendTo(body)

	sub := &stripe.Sub{}
	err := c.B.Call("GET", fmt.Sprintf("/customers/%v/subscriptions/%v", params.Customer, id), c.Key, body, &params.Params, sub)

	return sub, err
}
开发者ID:zkirill,项目名称:stripe-go,代码行数:13,代码来源:client.go

示例5: New

func (c Client) New(params *stripe.SubParams) (*stripe.Sub, error) {
	body := &url.Values{
		"plan": {params.Plan},
	}

	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.Quantity > 0 {
		body.Add("quantity", strconv.FormatUint(params.Quantity, 10))
	} else if params.QuantityZero {
		body.Add("quantity", "0")
	}

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

	if params.TaxPercent > 0 {
		body.Add("tax_percent", strconv.FormatFloat(params.TaxPercent, '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))
	}

	params.AppendTo(body)

	sub := &stripe.Sub{}
	err := c.B.Call("POST", fmt.Sprintf("/customers/%v/subscriptions", params.Customer), token, body, &params.Params, sub)

	return sub, err
}
开发者ID:zkirill,项目名称:stripe-go,代码行数:49,代码来源:client.go

示例6: Get

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

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

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

	return sub, err
}
开发者ID:carriercomm,项目名称:stripe-go,代码行数:15,代码来源: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: Update

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

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

		if len(params.Items) > 0 {
			for i, item := range params.Items {
				key := fmt.Sprintf("items[%d]", i)
				if len(item.ID) > 0 {
					body.Add(key+"[id]", item.ID)
				}
				if len(item.Plan) > 0 {
					body.Add(key+"[plan]", item.Plan)
				}
				if item.Quantity > 0 {
					body.Add(key+"[quantity]", strconv.FormatUint(item.Quantity, 10))
				} else if item.QuantityZero {
					body.Add(key+"[quantity]", "0")
				}
			}
		}

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

		if params.NoProrate {
			body.Add("prorate", strconv.FormatBool(false))
		}

		if len(params.Token) > 0 {
			body.Add("card", params.Token)
		} else if params.Card != nil {
			if len(params.Card.Token) > 0 {
				body.Add("card", params.Card.Token)
			} else {
				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.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.TaxPercent > 0 {
			body.Add("tax_percent", strconv.FormatFloat(params.TaxPercent, 'f', 2, 64))
		} else if params.TaxPercentZero {
			body.Add("tax_percent", "0")
		}

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

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

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

	return sub, err
}
开发者ID:captain401,项目名称:stripe-go,代码行数:82,代码来源:client.go

示例9: EnsureSubscriptionForGroup

// EnsureSubscriptionForGroup ensures subscription for a group
func EnsureSubscriptionForGroup(groupName string, params *stripe.SubParams) (*stripe.Sub, error) {
	if params == nil {
		params = &stripe.SubParams{
			Plan: Plans[UpTo10Users].ID,
		}
	}

	group, err := modelhelper.GetGroup(groupName)
	if err != nil {
		return nil, err
	}

	if group.Payment.Subscription.ID != "" {
		return sub.Get(group.Payment.Subscription.ID, nil)
	}

	if group.Payment.Customer.ID == "" {
		return nil, ErrCustomerNotExists
	}

	if err := CheckCustomerHasSource(group.Payment.Customer.ID); err != nil {
		return nil, err
	}

	now := time.Now().UTC()
	thirtyDaysLater := now.Add(30 * 24 * time.Hour).Unix()
	sevenDaysLater := now.Add(7 * 24 * time.Hour).Unix()

	if params.TrialEnd != 0 {
		// we only allow 0, 7 and 30 day trials
		if params.TrialEnd < sevenDaysLater {
			params.TrialEnd = sevenDaysLater
		}

		if params.TrialEnd > sevenDaysLater {
			params.TrialEnd = thirtyDaysLater
		}
	}

	// override quantity and plan in case we did not charge the user previously
	// due to failed payment and the subscription is deleted by stripe, create
	// new subscription
	quantity := uint64(1)
	activeCount, _ := (&socialapimodels.PresenceDaily{}).CountDistinctByGroupName(groupName)
	if activeCount != 0 {
		quantity = uint64(activeCount)
		params.Plan = GetPlanID(activeCount)
		params.TrialEnd = 0
	}

	// only send our whitelisted params
	req := &stripe.SubParams{
		Customer: group.Payment.Customer.ID,
		Quantity: quantity,
		Plan:     params.Plan,
		Coupon:   params.Coupon,
		Token:    params.Token,
		TrialEnd: params.TrialEnd,
		Card:     params.Card,
	}

	sub, err := sub.New(req)
	if err != nil {
		return nil, err
	}

	if err := syncGroupWithCustomerID(group.Payment.Customer.ID); err != nil {
		return nil, err
	}

	return sub, nil
}
开发者ID:,项目名称:,代码行数:73,代码来源:


注:本文中的github.com/stripe/stripe-go.SubParams类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。