Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix latest version to properly support Product in plans #522

Merged
merged 2 commits into from
Feb 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,24 @@ type PlanListParams struct {
// For more details see https://stripe.com/docs/api#create_plan and https://stripe.com/docs/api#update_plan.
type PlanParams struct {
Params `form:"*"`
Amount uint64 `form:"amount"`
AmountZero bool `form:"amount,zero"`
Currency Currency `form:"currency"`
ID string `form:"id"`
Interval PlanInterval `form:"interval"`
IntervalCount uint64 `form:"interval_count"`
Nickname string `form:"nickname"`
Product *ProductParams `form:"product"`
ProductID *string `form:"product"`
TrialPeriod uint64 `form:"trial_period_days"`
Amount uint64 `form:"amount"`
AmountZero bool `form:"amount,zero"`
Currency Currency `form:"currency"`
ID string `form:"id"`
Interval PlanInterval `form:"interval"`
IntervalCount uint64 `form:"interval_count"`
Nickname string `form:"nickname"`
Product *PlanProductParams `form:"product"`
ProductID *string `form:"product"`
TrialPeriod uint64 `form:"trial_period_days"`
}

// PlanProductParams is the set of parameters that can be used when creating a product inside a plan
// This can only be used on plan creation and won't work on plan update.
// For more details see https://stripe.com/docs/api#create_plan-product and https://stripe.com/docs/api#update_plan-product
type PlanProductParams struct {
ID string `form:"id"`
Name string `form:"name"`
Meta map[string]string `form:"metadata"`
StatementDescriptor string `form:"statement_descriptor"`
}
7 changes: 4 additions & 3 deletions plan/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ func TestPlanNew(t *testing.T) {
Currency: "usd",
ID: "sapphire-elite",
Interval: "month",
Product: &stripe.ProductParams{
Name: "Sapphire Elite",
Type: stripe.ProductTypeService,
Product: &stripe.PlanProductParams{
ID: "plan_id",
Name: "Sapphire Elite",
StatementDescriptor: "statement descriptor",
},
})
assert.Nil(t, err)
Expand Down
5 changes: 3 additions & 2 deletions plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func TestPlanListParams_AppendTo_Empty(t *testing.T) {
}

func TestPlanParams_AppendTo(t *testing.T) {
productParams := ProductParams{
productParams := PlanProductParams{
ID: "ID",
Name: "Sapphire Elite",
StatementDescriptor: "SAPPHIRE",
Type: ProductTypeService,
}
productId := "prod_123abc"
testCases := []struct {
Expand All @@ -55,6 +55,7 @@ func TestPlanParams_AppendTo(t *testing.T) {
{"id", &PlanParams{ID: "sapphire-elite"}, "sapphire-elite"},
{"interval", &PlanParams{Interval: "month"}, "month"},
{"interval_count", &PlanParams{IntervalCount: 3}, strconv.FormatUint(3, 10)},
{"product[id]", &PlanParams{Product: &productParams}, "ID"},
{"product[name]", &PlanParams{Product: &productParams}, "Sapphire Elite"},
{"product[statement_descriptor]", &PlanParams{Product: &productParams}, "SAPPHIRE"},
{"product", &PlanParams{ProductID: &productId}, "prod_123abc"},
Expand Down
2 changes: 1 addition & 1 deletion stripe.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
)

// apiversion is the currently supported API version
const apiversion = "2017-05-25"
const apiversion = "2018-02-06"

// clientversion is the binding version
const clientversion = "29.0.1"
Expand Down