diff --git a/example_test.go b/example_test.go index ff24e16e1f..832cbfe578 100644 --- a/example_test.go +++ b/example_test.go @@ -90,7 +90,7 @@ func ExamplePlan_list() { it := plan.List(params) for it.Next() { - log.Printf("%v ", it.Plan().Name) + log.Printf("%v ", it.Plan().Nickname) } if err := it.Err(); err != nil { log.Fatal(err) diff --git a/plan.go b/plan.go index 6ce8decb72..114a163450 100644 --- a/plan.go +++ b/plan.go @@ -16,8 +16,8 @@ type Plan struct { IntervalCount uint64 `json:"interval_count"` Live bool `json:"livemode"` Meta map[string]string `json:"metadata"` - Name string `json:"name"` - Statement string `json:"statement_descriptor"` + Nickname string `json:"nickname"` + Product string `json:"product"` TrialPeriod uint64 `json:"trial_period_days"` } @@ -39,12 +39,13 @@ 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"` - Currency Currency `form:"currency"` - ID string `form:"id"` - Interval PlanInterval `form:"interval"` - IntervalCount uint64 `form:"interval_count"` - Name string `form:"name"` - Statement string `form:"statement_descriptor"` - TrialPeriod uint64 `form:"trial_period_days"` + Amount uint64 `form:"amount"` + 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"` } diff --git a/plan/client_test.go b/plan/client_test.go index 0cf347a750..f550d8b41a 100644 --- a/plan/client_test.go +++ b/plan/client_test.go @@ -35,7 +35,23 @@ func TestPlanNew(t *testing.T) { Currency: "usd", ID: "sapphire-elite", Interval: "month", - Name: "Sapphire Elite", + Product: &stripe.ProductParams{ + Name: "Sapphire Elite", + Type: stripe.ProductTypeService, + }, + }) + assert.Nil(t, err) + assert.NotNil(t, plan) +} + +func TestPlanNewWithProductID(t *testing.T) { + productId := "prod_12345abc" + plan, err := New(&stripe.PlanParams{ + Amount: 1, + Currency: "usd", + ID: "sapphire-elite", + Interval: "month", + ProductID: &productId, }) assert.Nil(t, err) assert.NotNil(t, plan) @@ -43,7 +59,7 @@ func TestPlanNew(t *testing.T) { func TestPlanUpdate(t *testing.T) { plan, err := Update("gold", &stripe.PlanParams{ - Name: "Updated Name", + Nickname: "Updated nickame", }) assert.Nil(t, err) assert.NotNil(t, plan) diff --git a/plan_test.go b/plan_test.go index f83d11574a..1578654268 100644 --- a/plan_test.go +++ b/plan_test.go @@ -39,6 +39,12 @@ func TestPlanListParams_AppendTo_Empty(t *testing.T) { } func TestPlanParams_AppendTo(t *testing.T) { + productParams := ProductParams{ + Name: "Sapphire Elite", + StatementDescriptor: "SAPPHIRE", + Type: ProductTypeService, + } + productId := "prod_123abc" testCases := []struct { field string params *PlanParams @@ -49,8 +55,9 @@ 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)}, - {"name", &PlanParams{Name: "Sapphire Elite"}, "Sapphire Elite"}, - {"statement_descriptor", &PlanParams{Statement: "Sapphire Elite"}, "Sapphire Elite"}, + {"product[name]", &PlanParams{Product: &productParams}, "Sapphire Elite"}, + {"product[statement_descriptor]", &PlanParams{Product: &productParams}, "SAPPHIRE"}, + {"product", &PlanParams{ProductID: &productId}, "prod_123abc"}, {"trial_period_days", &PlanParams{TrialPeriod: 123}, strconv.FormatUint(123, 10)}, } for _, tc := range testCases { diff --git a/product.go b/product.go index 32b508f487..9a7a13c54d 100644 --- a/product.go +++ b/product.go @@ -2,6 +2,19 @@ package stripe import "encoding/json" +// ProductType is the type of a product. +type ProductType string + +const ( + // ProductTypeGood is a constant that indicates a product represents a physical good, + // which may be sold through the Stripe Relay API. + ProductTypeGood ProductType = "good" + + // ProductTypeService is a constant that indicates a product represents a service + // which is provided on a recurring basis and is priced with a Stripe plan. + ProductTypeService ProductType = "service" +) + // PackageDimensions represents the dimension of a product or a sku from the // perspective of shipping. type PackageDimensions struct { @@ -16,39 +29,43 @@ type PackageDimensions struct { // For more details, see https://stripe.com/docs/api#create_product // and https://stripe.com/docs/api#update_product. type ProductParams struct { - Params `form:"*"` - Active *bool `form:"active"` - Attrs []string `form:"attributes"` - Caption string `form:"caption"` - DeactivateOn []string `form:"deactivate_on"` - Desc string `form:"description"` - ID string `form:"id"` - Images []string `form:"images"` - Name string `form:"name"` - PackageDimensions *PackageDimensions `form:"package_dimensions"` - Shippable *bool `form:"shippable"` - URL string `form:"url"` + Params `form:"*"` + Active *bool `form:"active"` + Attrs []string `form:"attributes"` + Caption string `form:"caption"` + DeactivateOn []string `form:"deactivate_on"` + Desc string `form:"description"` + ID string `form:"id"` + Images []string `form:"images"` + Name string `form:"name"` + PackageDimensions *PackageDimensions `form:"package_dimensions"` + Shippable *bool `form:"shippable"` + StatementDescriptor string `form:"statement_descriptor"` + Type ProductType `form:"type"` + URL string `form:"url"` } // Product is the resource representing a Stripe product. // For more details see https://stripe.com/docs/api#products. type Product struct { - Active bool `json:"active"` - Attrs []string `json:"attributes"` - Caption string `json:"caption"` - Created int64 `json:"created"` - DeactivateOn []string `json:"deactivate_on"` - Desc string `json:"description"` - ID string `json:"id"` - Images []string `json:"images"` - Live bool `json:"livemode"` - Meta map[string]string `json:"metadata"` - Name string `json:"name"` - PackageDimensions *PackageDimensions `json:"package_dimensions"` - Shippable bool `json:"shippable"` - Skus *SKUList `json:"skus"` - URL string `json:"url"` - Updated int64 `json:"updated"` + Active bool `json:"active"` + Attrs []string `json:"attributes"` + Caption string `json:"caption"` + Created int64 `json:"created"` + DeactivateOn []string `json:"deactivate_on"` + Desc string `json:"description"` + ID string `json:"id"` + Images []string `json:"images"` + Live bool `json:"livemode"` + Meta map[string]string `json:"metadata"` + Name string `json:"name"` + PackageDimensions *PackageDimensions `json:"package_dimensions"` + Shippable bool `json:"shippable"` + Skus *SKUList `json:"skus"` + StatementDescriptor string `json:"statement_descriptor"` + URL string `json:"url"` + Updated int64 `json:"updated"` + Type ProductType `json:"type"` } // ProductList is a list of products as retrieved from a list endpoint. diff --git a/product/client_test.go b/product/client_test.go index ba2197d705..f68a638aca 100644 --- a/product/client_test.go +++ b/product/client_test.go @@ -47,6 +47,7 @@ func TestProductNew(t *testing.T) { Width: 6.50, Weight: 10, }, + Type: stripe.ProductTypeGood, }) assert.Nil(t, err) assert.NotNil(t, product)