Skip to content

Latest commit

 

History

History
240 lines (178 loc) · 11.7 KB

README.md

File metadata and controls

240 lines (178 loc) · 11.7 KB

Subscriptions

(Subscriptions)

Overview

Available Operations

  • List - List Subscriptions
  • Export - Export Subscriptions
  • Update - Update Subscription
  • Revoke - Revoke Subscription

List

List subscriptions.

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

Response

*operations.SubscriptionsListResponse, error

Errors

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

Export

Export subscriptions as a CSV file.

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.Subscriptions.Export(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }
    if res.Any != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
organizationID *operations.OrganizationID Filter by organization ID.
opts []operations.Option The options for this request.

Response

*operations.SubscriptionsExportResponse, error

Errors

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

Update

Update a subscription.

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

Parameters

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

Response

*operations.SubscriptionsUpdateResponse, error

Errors

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

Revoke

Revoke a subscription, i.e cancel immediately.

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

Parameters

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

Response

*operations.SubscriptionsRevokeResponse, error

Errors

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