Skip to content

Latest commit

 

History

History
243 lines (181 loc) · 12.8 KB

README.md

File metadata and controls

243 lines (181 loc) · 12.8 KB

PolarSubscriptions

(CustomerPortal.Subscriptions)

Overview

Available Operations

  • List - List Subscriptions
  • Get - Get Subscription
  • Update - Update Subscription
  • Cancel - Cancel Subscription

List

List subscriptions of the authenticated customer or user.

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

Response

*operations.CustomerPortalSubscriptionsListResponse, error

Errors

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

Get

Get a subscription for the authenticated customer or user.

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

Parameters

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

Response

*operations.CustomerPortalSubscriptionsGetResponse, 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 subscription of the authenticated customer or user.

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.CustomerPortal.Subscriptions.Update(ctx, "<value>", components.CreateCustomerSubscriptionUpdateCustomerSubscriptionUpdatePrice(
        components.CustomerSubscriptionUpdatePrice{
            ProductPriceID: "<value>",
        },
    ))
    if err != nil {
        log.Fatal(err)
    }
    if res.CustomerSubscription != nil {
        // handle response
    }
}

Parameters

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

Response

*operations.CustomerPortalSubscriptionsUpdateResponse, 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 */*

Cancel

Cancel a subscription of the authenticated customer or user.

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

Parameters

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

Response

*operations.CustomerPortalSubscriptionsCancelResponse, 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 */*