paddle

package
v0.179.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ConfigEnvPrefix is the prefix applied to environment variables for configuring Paddle.
	ConfigEnvPrefix = "PADDLE_"
)

Variables

View Source
var ErrNotFound = errors.New("not found")
View Source
var NewWebhookClient = sync.OnceValues(func() (*WebhookClient, error) {
	if err := loadConfig(); err != nil {
		return nil, fmt.Errorf("load config: %w", err)
	}
	return &WebhookClient{WebhookVerifier: paddle.NewWebhookVerifier(cfg.WebhookSecret)}, nil
})

NewWebhookClient creates a new webhook client.

Functions

func CancelSubscription

func CancelSubscription(ctx context.Context, user *models.User) error

CancelSubscription will cancel a user's subscription.

func GetClientToken

func GetClientToken() (string, error)

func GetCustomerPortalURL

func GetCustomerPortalURL() (string, error)

func GetPriceID

func GetPriceID(frequency string) (string, error)

func GetUserByCustomerID

func GetUserByCustomerID(ctx context.Context, id string) (*models.User, error)

GetUserByCustomerID retrieves the user associated with the given customer ID. It handles finding and adding customer details to an existing user for a new customer.

func HandleWebhook

func HandleWebhook(ctx context.Context, webhook Webhook)

func IsActive added in v0.157.0

func IsActive(s *models.PaddleSubscription) bool

func IsCancelled added in v0.157.0

func IsCancelled(s *models.PaddleSubscription) bool

func IsPastDue added in v0.157.0

func IsPastDue(s *models.PaddleSubscription) bool

func IsPaused added in v0.157.0

func IsPaused(s *models.PaddleSubscription) bool

func IsTrial added in v0.157.0

func IsTrial(s *models.PaddleSubscription) bool

func UpdateUserSubscription

func UpdateUserSubscription[T subscriptionData](ctx context.Context, user *models.User, subscription T) error

UpdateUserSubscription handles updating a user's subscription data.

Types

type Client

type Client struct {
	*paddle.SDK
}

type Config

type Config struct {
	// WebhookSecret is the secret used to verify webhook requests.
	WebhookSecret string `koanf:"webhooksecret" validate:"required"`
	// APIKey is the api key used to authorize requests with the paddle backend.
	APIKey string `koanf:"apikey" validate:"required"`
	// ClientToken is a token used for setting up paddle in the app.
	ClientToken string            `koanf:"clienttoken" validate:"required"`
	Pricing     map[string]string `koanf:"pricing"     validate:"required"`
	// // MonthlyPriceID is the ID of the monthly subscription object in the paddle backend.
	// MonthlyPriceID string `koanf:"monthlypriceid" validate:"required"`
	// // AnnualPriceID is the ID of the annual subscription object in the paddle backend.
	// AnnualPriceID string `koanf:"annualpriceid" validate:"required"`
	// CustomerPortalURL is the URL that customers can use to manage their subscription.
	CustomerPortalURL string `koanf:"customerportalurl" validate:"required"`
}

Config contains the pubsub configuration options.

type Webhook

type Webhook struct {
	EventID   string                           `json:"event_id"`
	EventType paddlenotification.EventTypeName `json:"event_type"`
	RawBody   []byte                           `json:"-"`
}

Webhook represents an incoming webhook event. It is a stripped down version of the payload used to identify the event that can then be parsed appropriately.

type WebhookClient

type WebhookClient struct {
	*paddle.WebhookVerifier
}

WebhookClient is a client that handles decoding and verifying incoming Paddle webhooks.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL