Skip to content

Latest commit

 

History

History
311 lines (235 loc) · 14.6 KB

README.md

File metadata and controls

311 lines (235 loc) · 14.6 KB

Products

(Products)

Overview

Available Operations

List

List products.

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.Products.List(ctx, operations.ProductsListRequest{})
    if err != nil {
        log.Fatal(err)
    }
    if res.ListResourceProduct != 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.ProductsListRequest ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.ProductsListResponse, error

Errors

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

Create

Create a product.

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.Products.Create(ctx, components.CreateProductCreateProductRecurringCreate(
        components.ProductRecurringCreate{
            Name: "<value>",
            Prices: components.CreateProductRecurringCreatePricesArrayOfProductPriceRecurringFixedCreate(
                []components.ProductPriceRecurringFixedCreate{
                    components.ProductPriceRecurringFixedCreate{
                        PriceAmount: 796474,
                        RecurringInterval: components.SubscriptionRecurringIntervalYear,
                    },
                },
            ),
        },
    ))
    if err != nil {
        log.Fatal(err)
    }
    if res.Product != nil {
        // handle response
    }
}

Parameters

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

Response

*operations.ProductsCreateResponse, error

Errors

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

Get

Get a product by ID.

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.Products.Get(ctx, "<value>")
    if err != nil {
        log.Fatal(err)
    }
    if res.Product != nil {
        // handle response
    }
}

Parameters

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

Response

*operations.ProductsGetResponse, 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 product.

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.Products.Update(ctx, "<value>", components.ProductUpdate{})
    if err != nil {
        log.Fatal(err)
    }
    if res.Product != nil {
        // handle response
    }
}

Parameters

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

Response

*operations.ProductsUpdateResponse, error

Errors

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

UpdateBenefits

Update benefits granted by a product.

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.Products.UpdateBenefits(ctx, "<value>", components.ProductBenefitsUpdate{
        Benefits: []string{
            "<value>",
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.Product != nil {
        // handle response
    }
}

Parameters

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

Response

*operations.ProductsUpdateBenefitsResponse, error

Errors

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