Skip to content

Latest commit

 

History

History
661 lines (497 loc) · 28.3 KB

README.md

File metadata and controls

661 lines (497 loc) · 28.3 KB

Customers

(Customers)

Overview

Available Operations

List

List customers.

Scopes: customers:read customers:write

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"github.com/polarsource/polar-go/models/operations"
	"log"
)

func main() {
    ctx := context.Background()

    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Customers.List(ctx, operations.CustomersListRequest{
        OrganizationID: polargo.Pointer(operations.CreateCustomersListQueryParamOrganizationIDFilterArrayOfStr(
            []string{
                "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
            },
        )),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.ListResourceCustomer != nil {
        for {
            // handle items

            res, err = res.Next()

            if err != nil {
                // handle error
            }

            if res == nil {
                break
            }
        }
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request operations.CustomersListRequest ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.CustomersListResponse, error

Errors

Error Type Status Code Content Type
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

Create

Create a customer.

Scopes: customers:write

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"github.com/polarsource/polar-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Customers.Create(ctx, components.CustomerCreate{
        ExternalID: polargo.String("usr_1337"),
        Email: "customer@example.com",
        Name: polargo.String("John Doe"),
        BillingAddress: &components.Address{
            Country: "SE",
        },
        TaxID: []*components.CustomerCreateTaxID{
            polargo.Pointer(components.CreateCustomerCreateTaxIDStr(
                "FR61954506077",
            )),
            polargo.Pointer(components.CreateCustomerCreateTaxIDStr(
                "eu_vat",
            )),
        },
        OrganizationID: polargo.String("1dbfc517-0bbf-4301-9ba8-555ca42b9737"),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.Customer != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request components.CustomerCreate ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.CustomersCreateResponse, error

Errors

Error Type Status Code Content Type
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

Get

Get a customer by ID.

Scopes: customers:read customers:write

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"log"
)

func main() {
    ctx := context.Background()

    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Customers.Get(ctx, "<value>")
    if err != nil {
        log.Fatal(err)
    }
    if res.Customer != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
id string ✔️ The customer ID.
opts []operations.Option The options for this request.

Response

*operations.CustomersGetResponse, error

Errors

Error Type Status Code Content Type
apierrors.ResourceNotFound 404 application/json
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

Update

Update a customer.

Scopes: customers:write

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"github.com/polarsource/polar-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Customers.Update(ctx, "<value>", components.CustomerUpdate{
        ExternalID: polargo.String("usr_1337"),
        Email: polargo.String("customer@example.com"),
        Name: polargo.String("John Doe"),
        BillingAddress: &components.Address{
            Country: "FR",
        },
        TaxID: []*components.CustomerUpdateTaxID{
            polargo.Pointer(components.CreateCustomerUpdateTaxIDStr(
                "FR61954506077",
            )),
            polargo.Pointer(components.CreateCustomerUpdateTaxIDStr(
                "eu_vat",
            )),
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.Customer != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
id string ✔️ The customer ID.
customerUpdate components.CustomerUpdate ✔️ N/A
opts []operations.Option The options for this request.

Response

*operations.CustomersUpdateResponse, error

Errors

Error Type Status Code Content Type
apierrors.ResourceNotFound 404 application/json
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

Delete

Delete a customer.

This action cannot be undone and will immediately:

  • Cancel any active subscriptions for the customer
  • Revoke all their benefits
  • Clear any external_id

Use it only in the context of deleting a user within your own service. Otherwise, use more granular API endpoints to cancel a specific subscription or revoke certain benefits.

Note: The customers information will nonetheless be retained for historic orders and subscriptions.

Scopes: customers:write

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"log"
)

func main() {
    ctx := context.Background()

    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Customers.Delete(ctx, "<value>")
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
id string ✔️ The customer ID.
opts []operations.Option The options for this request.

Response

*operations.CustomersDeleteResponse, error

Errors

Error Type Status Code Content Type
apierrors.ResourceNotFound 404 application/json
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

GetExternal

Get a customer by external ID.

Scopes: customers:read customers:write

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"log"
)

func main() {
    ctx := context.Background()

    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Customers.GetExternal(ctx, "<id>")
    if err != nil {
        log.Fatal(err)
    }
    if res.Customer != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
externalID string ✔️ The customer external ID.
opts []operations.Option The options for this request.

Response

*operations.CustomersGetExternalResponse, error

Errors

Error Type Status Code Content Type
apierrors.ResourceNotFound 404 application/json
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

UpdateExternal

Update a customer by external ID.

Scopes: customers:write

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"github.com/polarsource/polar-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Customers.UpdateExternal(ctx, "<id>", components.CustomerUpdate{
        ExternalID: polargo.String("usr_1337"),
        Email: polargo.String("customer@example.com"),
        Name: polargo.String("John Doe"),
        BillingAddress: &components.Address{
            Country: "US",
        },
        TaxID: []*components.CustomerUpdateTaxID{
            polargo.Pointer(components.CreateCustomerUpdateTaxIDStr(
                "FR61954506077",
            )),
            polargo.Pointer(components.CreateCustomerUpdateTaxIDStr(
                "eu_vat",
            )),
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.Customer != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
externalID string ✔️ The customer external ID.
customerUpdate components.CustomerUpdate ✔️ N/A
opts []operations.Option The options for this request.

Response

*operations.CustomersUpdateExternalResponse, error

Errors

Error Type Status Code Content Type
apierrors.ResourceNotFound 404 application/json
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

DeleteExternal

Delete a customer by external ID.

Immediately cancels any active subscriptions and revokes any active benefits.

Scopes: customers:write

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"log"
)

func main() {
    ctx := context.Background()

    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Customers.DeleteExternal(ctx, "<id>")
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
externalID string ✔️ The customer external ID.
opts []operations.Option The options for this request.

Response

*operations.CustomersDeleteExternalResponse, error

Errors

Error Type Status Code Content Type
apierrors.ResourceNotFound 404 application/json
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

GetState

Get a customer state by ID.

The customer state includes information about the customer's active subscriptions and benefits.

It's the ideal endpoint to use when you need to get a full overview of a customer's status.

Scopes: customers:read customers:write

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"log"
)

func main() {
    ctx := context.Background()

    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Customers.GetState(ctx, "<value>")
    if err != nil {
        log.Fatal(err)
    }
    if res.CustomerState != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
id string ✔️ The customer ID.
opts []operations.Option The options for this request.

Response

*operations.CustomersGetStateResponse, error

Errors

Error Type Status Code Content Type
apierrors.ResourceNotFound 404 application/json
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

GetStateExternal

Get a customer state by external ID.

The customer state includes information about the customer's active subscriptions and benefits.

It's the ideal endpoint to use when you need to get a full overview of a customer's status.

Scopes: customers:read customers:write

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"log"
)

func main() {
    ctx := context.Background()

    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Customers.GetStateExternal(ctx, "<id>")
    if err != nil {
        log.Fatal(err)
    }
    if res.CustomerState != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
externalID string ✔️ The customer external ID.
opts []operations.Option The options for this request.

Response

*operations.CustomersGetStateExternalResponse, error

Errors

Error Type Status Code Content Type
apierrors.ResourceNotFound 404 application/json
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*