From 909e4d36f1f7c5ab3c89112fc93d7ce9273754db Mon Sep 17 00:00:00 2001 From: "Michael Osuna Jr." Date: Fri, 13 Dec 2024 13:07:37 -0800 Subject: [PATCH] feat(commerce): add payee types --- commerce.go | 13 ++++++ commerce/payees/api.go | 31 ++++++++++++++ commerce/payees/client.go | 88 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 commerce/payees/api.go create mode 100644 commerce/payees/client.go diff --git a/commerce.go b/commerce.go index c520879..31461db 100644 --- a/commerce.go +++ b/commerce.go @@ -350,3 +350,16 @@ type CommerceCustomer struct { Name string `json:"name"` } `json:"entity"` } + +// --- Payee Types --- + +type CommercePayee struct { + APIResource + + ID string `json:"id"` + StripeURL string `json:"stripe_url"` + StripeID string `json:"stripe_id"` +} + + +type CommercePayeeList PaginatedList[CommercePayee] diff --git a/commerce/payees/api.go b/commerce/payees/api.go new file mode 100644 index 0000000..0be56a0 --- /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 0000000..75a8ff2 --- /dev/null +++ b/commerce/payees/client.go @@ -0,0 +1,88 @@ + +package payee + +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 + SubscriptionID *string `json:"subscription_id,omitempty"` + Amount *int64 `json:"amount,omitempty"` + DueAt *string `json:"due_at,omitempty"` +} + +type UpdateParams struct { + clerk.APIParams + Status *string `json:"status,omitempty"` +} + +type ListParams struct { + clerk.APIParams + InstanceID *string `json:"-"` +} + +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 +}