From 7584b41882d54051b94707bb143acd6c8ff7dc8e Mon Sep 17 00:00:00 2001 From: Ben Howdle Date: Tue, 7 Jan 2025 16:48:26 +0000 Subject: [PATCH] Ben/commerce feature plans (#364) * chore: Remove the Github PR template (#211) (#212) The PR template is probably not needed. * feat: Ability to configure a SAML Connection via IdP Metadata URL Some IdP providers, expose a metadata url which contains all their necessary information in order to configure an integration. We update our SAML Connection Create & Update operations to accept this new url as the 'idp_metadata_url' property * fix: Add URL to actor token responses (#217) Added the ActorTokenResponse.URL field. * feat: Support define SAML Connection Attribute mapping As part of the SAML Connection Create and Update operations, allow to define the attribute mapping of IdP properties to Clerk's user properties * feat: Add create session token given a template slug endpoint * feat: Introduce 'allow_subdomains' SAML Connection property We now expose a new property 'allow_subdomains' as part of the SAML Connection response. You can also define it during the Update operation. Default value is false * feat: Introduce 'allow_idp_initiated' SAML Connection property We now expose a new property 'allow_idp_initiated' as part of the SAML Connection response. You can also define it during the Update operation. Default value is false * chore: add github action for semgrep to run security scans in monitoring mode (#264) * feat: Allow SAML Connection configuration with IdP Metadata Our SAML Connection Create/Update operations now accepts a new optional property 'IdpMetadata' which you can use in order to configure an IdP using the metadata file. If provided, we also include it in the response as well * feat: Add `external_account_id` to OAuth access token response (#274) * feat: Support reply to email name for templates * chore: Update CODEOWNERS * docs: changing clerk hiring page * Add IgnoreDotsForGmailAddresses on SDK restriction resource (#291) * feat: add IgnoreDotsForGmailAddresses restriction on sdk * test: IgnoreDotsForGmailAddresses restriction * feat: Add SAMLAccounts for users (#299) Backporting the SAMLAccounts field on the User struct for v1. * sessions.go: Fix typo in tokens url for CreateTokenFromTemplate This URL can be found here: https://clerk.com/docs/reference/backend-api/tag/Sessions#operation/CreateSessionTokenFromTemplate * sessions_test.go: Update CreateTokenFromTemplate URL for integration tests * chore: merge * chore(commerce): revert accidental merge with wrong branch * chore(commerce): more reverts for bad merge * feat(commerce): add features to plan * feat(commerce): feature responses * feat(commerce): feature inputs * fix(commerce): add missing fields * feat(commerce): delete plan feature ids * fix(commerce): update params name * fix for deleting PlanFeatures * feat(commerce): add payee types * fix(commerce): fix payees package name * update some payee types * feat(commerce): add payers * feat(commerce): add payment sources * feat(commerce): payment source params * fix(commerce): single feature create * fix(commerce): change to payer * add is_free to plan * feat(commerce): missing fields * feat(commerce): string dates to ms --------- Co-authored-by: Giannis Katsanos Co-authored-by: Haris Chaniotakis Co-authored-by: Roberto Garcia Navarro Co-authored-by: Ross Nanopoulos <2287187+zythosec@users.noreply.github.com> Co-authored-by: Konstantinos Pittas Co-authored-by: Mary Zhong Co-authored-by: pedroimpulcetto Co-authored-by: nicolas lopes <57234795+NicolasLopes7@users.noreply.github.com> Co-authored-by: Shashank Verma <39261691+shank03@users.noreply.github.com> Co-authored-by: Michael Osuna Jr Co-authored-by: Keiran Flanigan --- commerce.go | 190 +++++++++++++++++++++--------- commerce/features/api.go | 8 ++ commerce/features/client.go | 26 +++- commerce/payees/api.go | 31 +++++ commerce/payees/client.go | 84 +++++++++++++ commerce/payers/api.go | 31 +++++ commerce/payers/client.go | 85 +++++++++++++ commerce/paymentsources/api.go | 31 +++++ commerce/paymentsources/client.go | 85 +++++++++++++ commerce/subscriptions/client.go | 2 +- organization/api.go | 6 + 11 files changed, 522 insertions(+), 57 deletions(-) create mode 100644 commerce/payees/api.go create mode 100644 commerce/payees/client.go create mode 100644 commerce/payers/api.go create mode 100644 commerce/payers/client.go create mode 100644 commerce/paymentsources/api.go create mode 100644 commerce/paymentsources/client.go diff --git a/commerce.go b/commerce.go index 54e4b366..63731078 100644 --- a/commerce.go +++ b/commerce.go @@ -12,16 +12,16 @@ type CreateProductParams struct { Name string `json:"name"` Slug string `json:"slug"` Currency string `json:"currency"` - SubscriberType []string `json:"subscriber_type"` + PayerType []string `json:"payer_type"` OwnerEntityType string `json:"owner_entity_type"` } type UpdateProductParams struct { APIParams - Name *string `json:"name,omitempty"` - Slug *string `json:"slug,omitempty"` - Currency *string `json:"currency,omitempty"` - SubscriberType *[]string `json:"subscriber_type,omitempty"` + Name *string `json:"name,omitempty"` + Slug *string `json:"slug,omitempty"` + Currency *string `json:"currency,omitempty"` + PayerType *[]string `json:"payer_type,omitempty"` } type GetProductByIDParams struct { @@ -36,10 +36,10 @@ type CommerceProduct struct { Slug string `json:"slug"` Currency string `json:"currency"` Plans []*CommercePlan `json:"plans"` - SubscriberType []string `json:"subscriber_type"` + PayerType []string `json:"payer_type"` OwnerEntityType string `json:"owner_entity_type"` - CreatedAt string `json:"created_at"` - UpdatedAt string `json:"updated_at"` + CreatedAt int64 `json:"created_at"` + UpdatedAt int64 `json:"updated_at"` } type CommerceProductWithPlans struct { @@ -62,10 +62,20 @@ type CommerceFeatureUnitPricing struct { Qty int `json:"qty"` } +type CommercePlanFeature struct { + APIResource + ID string `json:"id"` + PlanID string `json:"plan_id"` + FeatureID string `json:"feature_id"` + CreatedAt int64 `json:"created_at"` + UpdatedAt int64 `json:"updated_at"` +} + +type CommercePlanFeatureList PaginatedList[CommercePlanFeature] + type CommerceFeature struct { APIResource ID string `json:"id"` - PlanID string `json:"plan_id"` Name string `json:"name"` Description string `json:"description"` AvatarURL string `json:"avatar_url"` @@ -82,17 +92,34 @@ type CommerceFeature struct { HasTrialUnits bool `json:"has_trial_units"` TrialUnits int `json:"trial_units"` UnitPricing []CommerceFeatureUnitPricing `json:"unit_pricing"` - CreatedAt string `json:"created_at"` - UpdatedAt string `json:"updated_at"` + CreatedAt int64 `json:"created_at"` + UpdatedAt int64 `json:"updated_at"` } type CommerceFeatureList PaginatedList[CommerceFeature] +type CreatePlanFeatureParams struct { + APIParams + PlanID string `json:"plan_id"` + FeatureID string `json:"feature_id"` +} + +type CreateMultiplePlanFeaturesParams struct { + APIParams + PlanID string `json:"plan_id"` + FeatureIDs []string `json:"feature_ids"` +} + +type DeletePlanFeaturesParams struct { + APIParams + FeatureIDs []string `json:"feature_ids"` + PlanID string `json:"plan_id"` +} + type CreateFeatureParams struct { APIParams Name string `json:"name"` Description string `json:"description"` - PlanID string `json:"plan_id"` AvatarURL string `json:"avatar_url"` Slug string `json:"slug"` PubliclyVisible bool `json:"publicly_visible"` @@ -108,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"` @@ -144,9 +176,11 @@ type CreatePlanParams struct { APIParams Name string `json:"name"` ProductID string `json:"product_id"` + Slug string `json:"slug"` Amount int64 `json:"amount"` IsRecurring bool `json:"is_recurring"` IsProrated bool `json:"is_prorated"` + IsFree bool `json:"is_free"` Period string `json:"period"` Interval int `json:"interval"` AvatarURL string `json:"avatar_url"` @@ -158,8 +192,11 @@ type UpdatePlanParams struct { ID string `json:"id"` Name *string `json:"name,omitempty"` Amount *int64 `json:"amount,omitempty"` + Slug *string `json:"slug,omitempty"` IsRecurring *bool `json:"is_recurring,omitempty"` + Description *string `json:"description,omitempty"` IsProrated *bool `json:"is_prorated,omitempty"` + IsFree bool `json:"is_free"` Period *string `json:"period,omitempty"` Interval *int `json:"interval,omitempty"` AvatarURL *string `json:"avatar_url,omitempty"` @@ -172,22 +209,25 @@ type GetPlanByIDParams struct { type CommercePlan struct { APIResource - ID string `json:"id"` - Name string `json:"name"` - Product *CommerceProduct `json:"product,omitempty"` - Amount int64 `json:"amount"` - IsRecurring bool `json:"is_recurring"` - IsProrated bool `json:"is_prorated"` - Period string `json:"period"` - Interval int `json:"interval"` - AvatarURL string `json:"avatar_url"` - ProductID string `json:"product_id"` - Description string `json:"description"` - Slug string `json:"slug"` - BillingCycles *int `json:"billing_cycles,omitempty"` - SubscriberCount int64 `json:"subscriber_count"` - CreatedAt string `json:"created_at"` - UpdatedAt string `json:"updated_at"` + ID string `json:"id"` + Name string `json:"name"` + Product *CommerceProduct `json:"product,omitempty"` + Amount int64 `json:"amount"` + IsRecurring bool `json:"is_recurring"` + IsProrated bool `json:"is_prorated"` + IsFree bool `json:"is_free"` + IsDefault bool `json:"is_default"` + Period string `json:"period"` + Interval int `json:"interval"` + AvatarURL string `json:"avatar_url"` + ProductID string `json:"product_id"` + Description string `json:"description"` + Slug string `json:"slug"` + BillingCycles *int `json:"billing_cycles,omitempty"` + PayerCount int64 `json:"payer_count"` + CreatedAt int64 `json:"created_at"` + UpdatedAt int64 `json:"updated_at"` + Features []CommerceFeature `json:"features"` } type CommercePlanWithNoProduct struct { @@ -205,7 +245,7 @@ type ListPlansByInstanceIDParams struct { type CreateSubscriptionParams struct { APIParams - CustomerID string `json:"customer_id"` + PayerID string `json:"payer_id"` PlanID string `json:"plan_id"` PaymentSourceID string `json:"payment_source_id"` } @@ -222,24 +262,24 @@ type GetSubscriptionByIDParams struct { type ListSubscriptionsByUserIDParams struct { APIParams - ID string `json:"id"` - SubscriberType string `json:"subscriber_type"` + ID string `json:"id"` + PayerType string `json:"payer_type"` } type CommerceSubscription struct { APIResource - ID string `json:"id"` - AppID string `json:"app_id"` - Customer *CommerceCustomer `json:"customer,omitempty"` - InstanceID string `json:"instance_id"` - PaymentSourceID string `json:"payment_source_id"` - PlanID string `json:"plan_id"` - Plan *CommercePlan `json:"plan,omitempty"` - Status string `json:"status"` - LastInvoice *CommerceInvoice `json:"last_invoice,omitempty"` - NextInvoice *CommerceInvoice `json:"next_invoice,omitempty"` - CreatedAt string `json:"created_at"` // ISO 8601 format - UpdatedAt string `json:"updated_at"` // ISO 8601 format + ID string `json:"id"` + AppID string `json:"app_id"` + Payer *CommercePayer `json:"payer,omitempty"` + InstanceID string `json:"instance_id"` + PaymentSourceID string `json:"payment_source_id"` + PlanID string `json:"plan_id"` + Plan *CommercePlan `json:"plan,omitempty"` + Status string `json:"status"` + LastInvoice *CommerceInvoice `json:"last_invoice,omitempty"` + NextInvoice *CommerceInvoice `json:"next_invoice,omitempty"` + CreatedAt int64 `json:"created_at"` // ISO 8601 format + UpdatedAt int64 `json:"updated_at"` // ISO 8601 format } type ListCommerceSubscriptionsResponse struct { @@ -247,6 +287,31 @@ type ListCommerceSubscriptionsResponse struct { PaginatedList[CommerceSubscription] } +type CreatePaymentSourceParams struct { + APIParams + PayerID string `json:"payer_id"` + Gateway string `json:"gateway"` + PayeeID string `json:"payee_id"` + ExternalID string `json:"external_id"` + Last4 string `json:"last4"` + CardType string `json:"card_type"` +} + +type CommercePaymentSource struct { + APIResource + ID string `json:"id"` + PayerID string `json:"payer_id"` + Gateway string `json:"gateway"` + PayeeID string `json:"payee_id"` + ExternalID string `json:"external_id"` + CardType string `json:"card_type"` + LastFour string `json:"last4"` + CreatedAt int64 `json:"created_at"` + UpdatedAt int64 `json:"updated_at"` +} + +type CommercePaymentSourceList PaginatedList[CommercePaymentSource] + // --- Subscription Types --- type GetSubscriptionParams struct { @@ -254,20 +319,30 @@ type GetSubscriptionParams struct { ID string `json:"id"` } -type ListSubscribersParams struct { +type ListPayersParams struct { APIParams InstanceID string `json:"instance_id"` } -type CommerceSubscriber struct { +type CommercePayer struct { + APIResource ID string `json:"id"` Name string `json:"name"` Email string `json:"email"` } -type ListCommerceSubscribersResponse struct { +type CommercePayerList PaginatedList[CommercePayer] + +type CreatePayerParams struct { + APIParams + InstanceID string `json:"instance_id"` + Name string `json:"name"` + Email string `json:"email"` +} + +type ListCommercePayersResponse struct { APIResource - PaginatedList[CommerceSubscriber] + PaginatedList[CommercePayer] } // Supporting structs for emails @@ -304,13 +379,18 @@ type ListCommercePaymentAttemptsResponse struct { PaginatedList[CommercePaymentAttempt] } -// --- Customer Types --- +// --- Payee Types --- + +type CommercePayee struct { + APIResource -type CommerceCustomer struct { - ID string `json:"id"` - AppID string `json:"app_id"` - Entity *struct { - ID string `json:"id"` - Name string `json:"name"` - } `json:"entity"` + ID string `json:"id"` + GatewayStatus string `json:"gateway_status"` + GatewayType string `json:"gateway_type"` + StripeURL string `json:"stripe_url"` + StripeID string `json:"stripe_id"` + CreatedAt int64 `json:"created_at"` + UpdatedAt int64 `json:"updated_at"` } + +type CommercePayeeList PaginatedList[CommercePayee] diff --git a/commerce/features/api.go b/commerce/features/api.go index 473a96ab..93b38acd 100644 --- a/commerce/features/api.go +++ b/commerce/features/api.go @@ -12,6 +12,14 @@ func Create(ctx context.Context, params *clerk.CreateFeatureParams) (*clerk.Comm return getClient().Create(ctx, params) } +func CreatePlanFeatures(ctx context.Context, params *clerk.CreateMultiplePlanFeaturesParams) (*clerk.CommercePlanFeatureList, error) { + return getClient().CreatePlanFeatures(ctx, params) +} + +func DeletePlanFeatures(ctx context.Context, params *clerk.DeletePlanFeaturesParams) (*clerk.DeletedResource, error) { + return getClient().DeletePlanFeatures(ctx, params) +} + func List(ctx context.Context, params *clerk.ListFeaturesByInstanceIDParams) (*clerk.CommerceFeatureList, error) { return getClient().List(ctx, params) } diff --git a/commerce/features/client.go b/commerce/features/client.go index 4fb60b5d..58e88a9f 100644 --- a/commerce/features/client.go +++ b/commerce/features/client.go @@ -24,7 +24,7 @@ func NewClient(config *clerk.ClientConfig) *Client { } func (c *Client) Create(ctx context.Context, params *clerk.CreateFeatureParams) (*clerk.CommerceFeature, error) { - reqPath, err := clerk.JoinPath(rootPath, "plans", params.PlanID, path) + reqPath, err := clerk.JoinPath(rootPath, path) if err != nil { return nil, err } @@ -35,6 +35,30 @@ func (c *Client) Create(ctx context.Context, params *clerk.CreateFeatureParams) return resource, err } +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.CommercePlanFeatureList{} + err = c.Backend.Call(ctx, req, resource) + return resource, err +} + +func (c *Client) DeletePlanFeatures(ctx context.Context, params *clerk.DeletePlanFeaturesParams) (*clerk.DeletedResource, error) { + reqPath, err := clerk.JoinPath(rootPath, "plans", params.PlanID, path) + if err != nil { + return nil, err + } + req := clerk.NewAPIRequest(http.MethodDelete, reqPath) + req.SetParams(params) + resource := &clerk.DeletedResource{} + err = c.Backend.Call(ctx, req, resource) + return resource, err +} + func (c *Client) List(ctx context.Context, params *clerk.ListFeaturesByInstanceIDParams) (*clerk.CommerceFeatureList, error) { reqPath, err := clerk.JoinPath(rootPath, path) if err != nil { diff --git a/commerce/payees/api.go b/commerce/payees/api.go new file mode 100644 index 00000000..0be56a03 --- /dev/null +++ b/commerce/payees/api.go @@ -0,0 +1,31 @@ +// Code generated by "gen"; DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. +package payees + +import ( + "context" + + "github.com/clerk/clerk-sdk-go/v2" +) + +func Create(ctx context.Context, params *CreateParams) (*clerk.CommercePayee, error) { + return getClient().Create(ctx, params) +} + +func List(ctx context.Context, params *ListParams) (*clerk.CommercePayeeList, error) { + return getClient().List(ctx, params) +} + +func Get(ctx context.Context, id string) (*clerk.CommercePayee, error) { + return getClient().Get(ctx, id) +} + +func Update(ctx context.Context, id string, params *UpdateParams) (*clerk.CommercePayee, error) { + return getClient().Update(ctx, id, params) +} + +func getClient() *Client { + return &Client{ + Backend: clerk.GetBackend(), + } +} diff --git a/commerce/payees/client.go b/commerce/payees/client.go new file mode 100644 index 00000000..f45e88c7 --- /dev/null +++ b/commerce/payees/client.go @@ -0,0 +1,84 @@ +package payees + +import ( + "context" + "net/http" + + "github.com/clerk/clerk-sdk-go/v2" +) + +//go:generate go run ../../cmd/gen/main.go +const ( + rootPath = "/commerce" + path = "/payees" +) + +type CreateParams struct { + clerk.APIParams + GatewayType string `json:"gateway_type" form:"gateway_type"` + Email string `json:"email" form:"email"` +} + +type UpdateParams struct { + clerk.APIParams +} + +type ListParams struct { + clerk.APIParams +} + +type Client struct { + Backend clerk.Backend +} + +func NewClient(config *clerk.ClientConfig) *Client { + return &Client{ + Backend: clerk.NewBackend(&config.BackendConfig), + } +} + +func (c *Client) Create(ctx context.Context, params *CreateParams) (*clerk.CommercePayee, error) { + reqPath, err := clerk.JoinPath(rootPath, path) + if err != nil { + return nil, err + } + req := clerk.NewAPIRequest(http.MethodPost, reqPath) + req.SetParams(params) + resource := &clerk.CommercePayee{} + err = c.Backend.Call(ctx, req, resource) + return resource, err +} + +func (c *Client) List(ctx context.Context, params *ListParams) (*clerk.CommercePayeeList, error) { + reqPath, err := clerk.JoinPath(rootPath, path) + if err != nil { + return nil, err + } + req := clerk.NewAPIRequest(http.MethodGet, reqPath) + resource := &clerk.CommercePayeeList{} + err = c.Backend.Call(ctx, req, resource) + return resource, err +} + +func (c *Client) Get(ctx context.Context, id string) (*clerk.CommercePayee, error) { + reqPath, err := clerk.JoinPath(rootPath, path, id) + if err != nil { + return nil, err + } + req := clerk.NewAPIRequest(http.MethodGet, reqPath) + resource := &clerk.CommercePayee{} + err = c.Backend.Call(ctx, req, resource) + return resource, err +} + +func (c *Client) Update(ctx context.Context, id string, params *UpdateParams) (*clerk.CommercePayee, error) { + reqPath, err := clerk.JoinPath(rootPath, path, id) + if err != nil { + return nil, err + } + req := clerk.NewAPIRequest(http.MethodPut, reqPath) + req.SetParams(params) + resource := &clerk.CommercePayee{} + err = c.Backend.Call(ctx, req, resource) + return resource, err +} diff --git a/commerce/payers/api.go b/commerce/payers/api.go new file mode 100644 index 00000000..06abd176 --- /dev/null +++ b/commerce/payers/api.go @@ -0,0 +1,31 @@ +// Code generated by "gen"; DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. +package payers + +import ( + "context" + + "github.com/clerk/clerk-sdk-go/v2" +) + +func Create(ctx context.Context, params *CreateParams) (*clerk.CommercePayer, error) { + return getClient().Create(ctx, params) +} + +func List(ctx context.Context, params *ListParams) (*clerk.CommercePayerList, error) { + return getClient().List(ctx, params) +} + +func Get(ctx context.Context, id string) (*clerk.CommercePayer, error) { + return getClient().Get(ctx, id) +} + +func Update(ctx context.Context, id string, params *UpdateParams) (*clerk.CommercePayer, error) { + return getClient().Update(ctx, id, params) +} + +func getClient() *Client { + return &Client{ + Backend: clerk.GetBackend(), + } +} diff --git a/commerce/payers/client.go b/commerce/payers/client.go new file mode 100644 index 00000000..a7a59224 --- /dev/null +++ b/commerce/payers/client.go @@ -0,0 +1,85 @@ +package payers + +import ( + "context" + "net/http" + + "github.com/clerk/clerk-sdk-go/v2" +) + +//go:generate go run ../../cmd/gen/main.go +const ( + rootPath = "/commerce" + path = "/payers" +) + +type CreateParams struct { + clerk.APIParams + Name string `json:"name" form:"name"` + Email string `json:"email" form:"email"` + UserID string `json:"user_id" form:"user_id"` +} + +type UpdateParams struct { + clerk.APIParams +} + +type ListParams struct { + clerk.APIParams +} + +type Client struct { + Backend clerk.Backend +} + +func NewClient(config *clerk.ClientConfig) *Client { + return &Client{ + Backend: clerk.NewBackend(&config.BackendConfig), + } +} + +func (c *Client) Create(ctx context.Context, params *CreateParams) (*clerk.CommercePayer, error) { + reqPath, err := clerk.JoinPath(rootPath, path) + if err != nil { + return nil, err + } + req := clerk.NewAPIRequest(http.MethodPost, reqPath) + req.SetParams(params) + resource := &clerk.CommercePayer{} + err = c.Backend.Call(ctx, req, resource) + return resource, err +} + +func (c *Client) List(ctx context.Context, params *ListParams) (*clerk.CommercePayerList, error) { + reqPath, err := clerk.JoinPath(rootPath, path) + if err != nil { + return nil, err + } + req := clerk.NewAPIRequest(http.MethodGet, reqPath) + resource := &clerk.CommercePayerList{} + err = c.Backend.Call(ctx, req, resource) + return resource, err +} + +func (c *Client) Get(ctx context.Context, id string) (*clerk.CommercePayer, error) { + reqPath, err := clerk.JoinPath(rootPath, path, id) + if err != nil { + return nil, err + } + req := clerk.NewAPIRequest(http.MethodGet, reqPath) + resource := &clerk.CommercePayer{} + err = c.Backend.Call(ctx, req, resource) + return resource, err +} + +func (c *Client) Update(ctx context.Context, id string, params *UpdateParams) (*clerk.CommercePayer, error) { + reqPath, err := clerk.JoinPath(rootPath, path, id) + if err != nil { + return nil, err + } + req := clerk.NewAPIRequest(http.MethodPut, reqPath) + req.SetParams(params) + resource := &clerk.CommercePayer{} + err = c.Backend.Call(ctx, req, resource) + return resource, err +} diff --git a/commerce/paymentsources/api.go b/commerce/paymentsources/api.go new file mode 100644 index 00000000..18c4f57f --- /dev/null +++ b/commerce/paymentsources/api.go @@ -0,0 +1,31 @@ +// Code generated by "gen"; DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. +package paymentsources + +import ( + "context" + + "github.com/clerk/clerk-sdk-go/v2" +) + +func Create(ctx context.Context, params *CreateParams) (*clerk.CommercePaymentSource, error) { + return getClient().Create(ctx, params) +} + +func List(ctx context.Context, params *ListParams) (*clerk.CommercePaymentSourceList, error) { + return getClient().List(ctx, params) +} + +func Get(ctx context.Context, id string) (*clerk.CommercePaymentSource, error) { + return getClient().Get(ctx, id) +} + +func Update(ctx context.Context, id string, params *UpdateParams) (*clerk.CommercePaymentSource, error) { + return getClient().Update(ctx, id, params) +} + +func getClient() *Client { + return &Client{ + Backend: clerk.GetBackend(), + } +} diff --git a/commerce/paymentsources/client.go b/commerce/paymentsources/client.go new file mode 100644 index 00000000..05242e2e --- /dev/null +++ b/commerce/paymentsources/client.go @@ -0,0 +1,85 @@ +package paymentsources + +import ( + "context" + "net/http" + + "github.com/clerk/clerk-sdk-go/v2" +) + +//go:generate go run ../../cmd/gen/main.go +const ( + rootPath = "/commerce" + path = "/payment_sources" +) + +type CreateParams struct { + clerk.APIParams + PayerID string `json:"payer_id"` + PayeeID string `json:"payee_id"` + Gateway string `json:"gateway"` +} + +type UpdateParams struct { + clerk.APIParams +} + +type ListParams struct { + clerk.APIParams +} + +type Client struct { + Backend clerk.Backend +} + +func NewClient(config *clerk.ClientConfig) *Client { + return &Client{ + Backend: clerk.NewBackend(&config.BackendConfig), + } +} + +func (c *Client) Create(ctx context.Context, params *CreateParams) (*clerk.CommercePaymentSource, error) { + reqPath, err := clerk.JoinPath(rootPath, path) + if err != nil { + return nil, err + } + req := clerk.NewAPIRequest(http.MethodPost, reqPath) + req.SetParams(params) + resource := &clerk.CommercePaymentSource{} + err = c.Backend.Call(ctx, req, resource) + return resource, err +} + +func (c *Client) List(ctx context.Context, params *ListParams) (*clerk.CommercePaymentSourceList, error) { + reqPath, err := clerk.JoinPath(rootPath, path) + if err != nil { + return nil, err + } + req := clerk.NewAPIRequest(http.MethodGet, reqPath) + resource := &clerk.CommercePaymentSourceList{} + err = c.Backend.Call(ctx, req, resource) + return resource, err +} + +func (c *Client) Get(ctx context.Context, id string) (*clerk.CommercePaymentSource, error) { + reqPath, err := clerk.JoinPath(rootPath, path, id) + if err != nil { + return nil, err + } + req := clerk.NewAPIRequest(http.MethodGet, reqPath) + resource := &clerk.CommercePaymentSource{} + err = c.Backend.Call(ctx, req, resource) + return resource, err +} + +func (c *Client) Update(ctx context.Context, id string, params *UpdateParams) (*clerk.CommercePaymentSource, error) { + reqPath, err := clerk.JoinPath(rootPath, path, id) + if err != nil { + return nil, err + } + req := clerk.NewAPIRequest(http.MethodPut, reqPath) + req.SetParams(params) + resource := &clerk.CommercePaymentSource{} + err = c.Backend.Call(ctx, req, resource) + return resource, err +} diff --git a/commerce/subscriptions/client.go b/commerce/subscriptions/client.go index e9e2458f..26f02f39 100644 --- a/commerce/subscriptions/client.go +++ b/commerce/subscriptions/client.go @@ -73,7 +73,7 @@ func (c *Client) ListInvoices(ctx context.Context, subscriptionID string) (*cler } func (c *Client) ListByUserID(ctx context.Context, params *clerk.ListSubscriptionsByUserIDParams) (*clerk.ListCommerceSubscriptionsResponse, error) { - reqPath, err := clerk.JoinPath(rootPath, "subscribers", params.SubscriberType, params.ID, "subscriptions") + reqPath, err := clerk.JoinPath(rootPath, "subscribers", params.PayerType, params.ID, "subscriptions") if err != nil { return nil, err } diff --git a/organization/api.go b/organization/api.go index fa942759..f88096c0 100644 --- a/organization/api.go +++ b/organization/api.go @@ -19,6 +19,12 @@ func Get(ctx context.Context, idOrSlug string) (*clerk.Organization, error) { return getClient().Get(ctx, idOrSlug) } +// GetWithParams retrieves details for an organization. +// The organization can be fetched by either the ID or its slug. +func GetWithParams(ctx context.Context, idOrSlug string, params *GetParams) (*clerk.Organization, error) { + return getClient().GetWithParams(ctx, idOrSlug, params) +} + // Update updates an organization. func Update(ctx context.Context, id string, params *UpdateParams) (*clerk.Organization, error) { return getClient().Update(ctx, id, params)