Skip to content

Commit

Permalink
feat(commerce): add payee types
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeosunajr committed Dec 13, 2024
1 parent 5e93c23 commit 909e4d3
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
13 changes: 13 additions & 0 deletions commerce.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
31 changes: 31 additions & 0 deletions commerce/payees/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions commerce/payees/client.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 909e4d3

Please sign in to comment.