Skip to content

Latest commit

 

History

History
299 lines (223 loc) · 13.3 KB

README.md

File metadata and controls

299 lines (223 loc) · 13.3 KB

Discounts

(Discounts)

Overview

Available Operations

List

List discounts.

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

Response

*operations.DiscountsListResponse, error

Errors

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

Create

Create a discount.

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.Discounts.Create(ctx, components.CreateDiscountCreateDiscountFixedRepeatDurationCreate(
        components.DiscountFixedRepeatDurationCreate{
            Duration: components.DiscountDurationForever,
            DurationInMonths: 417458,
            Type: components.DiscountTypeFixed,
            Amount: 69025,
            Name: "<value>",
        },
    ))
    if err != nil {
        log.Fatal(err)
    }
    if res.Discount != nil {
        // handle response
    }
}

Parameters

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

Response

*operations.DiscountsCreateResponse, error

Errors

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

Get

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

Parameters

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

Response

*operations.DiscountsGetResponse, 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 discount.

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

Parameters

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

Response

*operations.DiscountsUpdateResponse, 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 discount.

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.Discounts.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 discount ID.
opts []operations.Option The options for this request.

Response

*operations.DiscountsDeleteResponse, error

Errors

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