From 46255f3ff3693175ea7c9b9ff9a33aa4835b9853 Mon Sep 17 00:00:00 2001 From: Ben Howdle Date: Wed, 11 Dec 2024 15:14:19 +0000 Subject: [PATCH] feat(commerce): feature inputs --- commerce.go | 13 +++++++++++++ commerce/features/api.go | 6 +++--- commerce/features/client.go | 8 ++++---- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/commerce.go b/commerce.go index 898083b..78c4bfb 100644 --- a/commerce.go +++ b/commerce.go @@ -71,6 +71,8 @@ type CommercePlanFeature struct { UpdatedAt string `json:"updated_at"` } +type CommercePlanFeatureList PaginatedList[CommercePlanFeature] + type CommerceFeature struct { APIResource ID string `json:"id"` @@ -102,6 +104,12 @@ type CreatePlanFeatureParams struct { FeatureID string `json:"feature_id"` } +type CreateMultiplePlanFeaturesParams struct { + APIParams + PlanID string `json:"plan_id"` + FeatureIDs []string `json:"feature_ids"` +} + type DeletePlanFeatureParams struct { APIParams FeatureID string `json:"feature_id"` @@ -127,6 +135,11 @@ type CreateFeatureParams struct { UnitPricing []CommerceFeatureUnitPricing `json:"unit_pricing"` } +type CreateMultipleFeaturesParams struct { + APIParams + Features []CreateFeatureParams `json:"features"` +} + type UpdateFeatureParams struct { APIParams ID string `json:"id"` diff --git a/commerce/features/api.go b/commerce/features/api.go index 65af286..d948d42 100644 --- a/commerce/features/api.go +++ b/commerce/features/api.go @@ -8,12 +8,12 @@ import ( "github.com/clerk/clerk-sdk-go/v2" ) -func Create(ctx context.Context, params *clerk.CreateFeatureParams) (*clerk.CommerceFeature, error) { +func Create(ctx context.Context, params *clerk.CreateMultipleFeaturesParams) (*clerk.CommerceFeatureList, error) { return getClient().Create(ctx, params) } -func CreatePlanFeature(ctx context.Context, params *clerk.CreatePlanFeatureParams) (*clerk.CommercePlanFeature, error) { - return getClient().CreatePlanFeature(ctx, params) +func CreatePlanFeatures(ctx context.Context, params *clerk.CreateMultiplePlanFeaturesParams) (*clerk.CommercePlanFeatureList, error) { + return getClient().CreatePlanFeatures(ctx, params) } func DeletePlanFeature(ctx context.Context, params *clerk.DeletePlanFeatureParams) error { diff --git a/commerce/features/client.go b/commerce/features/client.go index 1cd4603..74d2b44 100644 --- a/commerce/features/client.go +++ b/commerce/features/client.go @@ -23,26 +23,26 @@ func NewClient(config *clerk.ClientConfig) *Client { } } -func (c *Client) Create(ctx context.Context, params *clerk.CreateFeatureParams) (*clerk.CommerceFeature, error) { +func (c *Client) Create(ctx context.Context, params *clerk.CreateMultipleFeaturesParams) (*clerk.CommerceFeatureList, error) { reqPath, err := clerk.JoinPath(rootPath, path) if err != nil { return nil, err } req := clerk.NewAPIRequest(http.MethodPost, reqPath) req.SetParams(params) - resource := &clerk.CommerceFeature{} + resource := &clerk.CommerceFeatureList{} err = c.Backend.Call(ctx, req, resource) return resource, err } -func (c *Client) CreatePlanFeature(ctx context.Context, params *clerk.CreatePlanFeatureParams) (*clerk.CommercePlanFeature, error) { +func (c *Client) CreatePlanFeatures(ctx context.Context, params *clerk.CreateMultiplePlanFeaturesParams) (*clerk.CommercePlanFeatureList, error) { reqPath, err := clerk.JoinPath(rootPath, "plans", params.PlanID, path) if err != nil { return nil, err } req := clerk.NewAPIRequest(http.MethodPost, reqPath) req.SetParams(params) - resource := &clerk.CommercePlanFeature{} + resource := &clerk.CommercePlanFeatureList{} err = c.Backend.Call(ctx, req, resource) return resource, err }