paddle

package
v0.241.2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: AGPL-3.0 Imports: 14 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 HandleWebhook

func HandleWebhook(ctx context.Context, userSvc UserService, sender EmailSender, 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

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 EmailSender added in v0.240.0

type EmailSender interface {
	Send(ctx context.Context, options ...resend.EmailOption) error
}

type UserService added in v0.235.0

type UserService interface {
	GetUserByCustomerID(ctx context.Context, id string) (*models.User, error)
	GetUserByEmail(ctx context.Context, email string) (*models.User, error)
	UpdateUser(ctx context.Context, user *models.User, updates map[string]any) error
}

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