Documentation Index
Fetch the complete documentation index at: https://mintlify.com/polarsource/polar/llms.txt
Use this file to discover all available pages before exploring further.
Examples
Installation
Quickstart
main.go
SDK for Golang
Documentation Index
Fetch the complete documentation index at: https://mintlify.com/polarsource/polar/llms.txt
Use this file to discover all available pages before exploring further.
go get github.com/polarsource/polar-go
package main
import (
"context"
polargo "github.com/polarsource/polar-go"
"log"
"os"
)
func main() {
ctx := context.Background()
s := polargo.New(
polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
)
res, err := s.Organizations.List(ctx, nil, polargo.Pointer[int64](1), polargo.Pointer[int64](10), nil)
if err != nil {
log.Fatal(err)
}
if res.ListResourceOrganization != nil {
for {
// handle items
for _, org := range res.ListResourceOrganization.Items {
log.Println(org.Name)
}
res, err = res.Next()
if err != nil {
log.Fatal(err)
}
if res == nil {
break
}
}
}
}
import polargo "github.com/polarsource/polar-go"
s := polargo.New(
polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
)
package main
import (
"context"
"fmt"
polargo "github.com/polarsource/polar-go"
polargocomponents "github.com/polarsource/polar-go/models/components"
"os"
)
func main() {
ctx := context.Background()
s := polargo.New(
polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
)
checkout, err := s.Checkouts.Create(ctx, polargocomponents.CheckoutCreateInput{
Products: []string{"prod_xxxxxxxxxxxxx"},
SuccessURL: polargo.Pointer("https://myapp.com/success"),
ReturnURL: polargo.Pointer("https://myapp.com"),
})
if err != nil {
panic(err)
}
// Redirect user to checkout.URL
fmt.Println(checkout.URL)
}
package main
import (
"context"
"fmt"
polargo "github.com/polarsource/polar-go"
"os"
)
func main() {
ctx := context.Background()
s := polargo.New(
polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
)
customerState, err := s.Customers.GetStateExternal(ctx, "user_123")
if err != nil {
panic(err)
}
fmt.Println("Granted Benefits:", customerState.GrantedBenefits)
fmt.Println("Subscriptions:", customerState.Subscriptions)
}
package main
import (
"context"
"log"
polargo "github.com/polarsource/polar-go"
"os"
)
func main() {
ctx := context.Background()
s := polargo.New(
polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
)
organizationID := "org_xxxxxxxxxxxxx"
res, err := s.Products.List(
ctx,
polargo.Pointer(organizationID),
polargo.Pointer[int64](1),
polargo.Pointer[int64](10),
)
if err != nil {
log.Fatal(err)
}
if res.ListResourceProduct != nil {
for {
// handle items
for _, product := range res.ListResourceProduct.Items {
log.Println(product.Name)
}
res, err = res.Next()
if err != nil {
log.Fatal(err)
}
if res == nil {
break
}
}
}
}
res, err := s.Products.List(ctx, nil, polargo.Pointer[int64](1), polargo.Pointer[int64](10))
if err != nil {
log.Fatal(err)
}
if res.ListResourceProduct != nil {
for {
// Process each page of results
for _, product := range res.ListResourceProduct.Items {
log.Println(product.ID)
}
res, err = res.Next()
if err != nil {
log.Fatal(err)
}
if res == nil {
break
}
}
}
s := polargo.New(
polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
polargo.WithServerURL("https://sandbox-api.polar.sh"),
)
Powered by Mintlify
Auto-generate your docs