Documentation
¶
Index ¶
- Constants
- Variables
- func CancelSubscription(ctx context.Context, user *models.User) error
- func GetClientToken() (string, error)
- func GetCustomerPortalURL() (string, error)
- func GetPriceID(frequency string) (string, error)
- func GetUserByCustomerID(ctx context.Context, id string) (*models.User, error)
- func HandleWebhook(ctx context.Context, webhook Webhook)
- func IsActive(s *models.PaddleSubscription) bool
- func IsCancelled(s *models.PaddleSubscription) bool
- func IsPastDue(s *models.PaddleSubscription) bool
- func IsPaused(s *models.PaddleSubscription) bool
- func IsTrial(s *models.PaddleSubscription) bool
- func UpdateUserSubscription[T subscriptionData](ctx context.Context, user *models.User, subscription T) error
- type Client
- type Config
- type Webhook
- type WebhookClient
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 ¶
CancelSubscription will cancel a user's subscription.
func GetClientToken ¶
func GetCustomerPortalURL ¶
func GetPriceID ¶
func GetUserByCustomerID ¶
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 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 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.
Click to show internal directories.
Click to hide internal directories.