Skip to content

Commit

Permalink
feat(customers): Add checkout_url endpoint (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdenquin authored Nov 20, 2023
1 parent 3be64cb commit 9df5ad6
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ type CustomerPortalUrlResult struct {
CustomerPortalUrl *CustomerPortalUrl `json:"customer"`
}

type CustomerCheckoutUrlResult struct {
CustomerCheckoutUrl *CustomerCheckoutUrl `json:"customer"`
}

type CustomerMetadataInput struct {
LagoID *uuid.UUID `json:"id,omitempty"`
Key string `json:"key,omitempty"`
Expand Down Expand Up @@ -126,6 +130,10 @@ type CustomerPortalUrl struct {
PortalUrl string `json:"portal_url,omitempty"`
}

type CustomerCheckoutUrl struct {
CheckoutUrl string `json:"checkout_url,omitempty"`
}

type CustomerUsageInput struct {
ExternalSubscriptionID string `json:"external_subscription_id,omitempty"`
}
Expand Down Expand Up @@ -294,6 +302,27 @@ func (cr *CustomerRequest) PortalUrl(ctx context.Context, externalCustomerID str
return portalUrlResult.CustomerPortalUrl, nil
}

func (cr *CustomerRequest) CheckoutUrl(ctx context.Context, externalCustomerID string) (*CustomerCheckoutUrl, *Error) {
subPath := fmt.Sprintf("%s/%s/%s", "customers", externalCustomerID, "checkout_url")

clientRequest := &ClientRequest{
Path: subPath,
Result: &CustomerCheckoutUrlResult{},
}

result, err := cr.client.Post(ctx, clientRequest)
if err != nil {
return nil, err
}

checkoutUrlResult, ok := result.(*CustomerCheckoutUrlResult)
if !ok {
return nil, &ErrorTypeAssert
}

return checkoutUrlResult.CustomerCheckoutUrl, nil
}

func (cr *CustomerRequest) Delete(ctx context.Context, externalCustomerID string) (*Customer, *Error) {
subPath := fmt.Sprintf("%s/%s", "customers", externalCustomerID)
clientRequest := &ClientRequest{
Expand Down

0 comments on commit 9df5ad6

Please sign in to comment.