revenuecat

package
v1.28.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSignature    = errors.New("invalid_revenuecat_webhook_signature")
	ErrInvalidPayload      = errors.New("invalid_revenuecat_webhook_payload")
	ErrMissingAppUserID    = errors.New("missing_app_user_id")
	ErrUnknownProductID    = errors.New("unknown_product_id")
	ErrExpiredSubscription = errors.New("subscription_already_expired")
)

Common errors

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the RevenueCat webhook client

func NewClient

func NewClient(webhookSecret string) *Client

NewClient creates a new RevenueCat client

func (*Client) AddProductMapping

func (c *Client) AddProductMapping(productID string, planCode, billingCycle string)

AddProductMapping adds a product ID to plan code mapping

func (*Client) GetPlanCode

func (c *Client) GetPlanCode(productID string) (string, string, error)

GetPlanCode returns the plan code for a product ID

func (*Client) ParseWebhook

func (c *Client) ParseWebhook(payload []byte, authToken string) (*WebhookEvent, error)

ParseWebhook parses and verifies a webhook payload

func (*Client) VerifyAuthorization

func (c *Client) VerifyAuthorization(authToken string) error

VerifyAuthorization verifies the webhook authorization from RevenueCat RevenueCat sends the configured secret in the Authorization header This is a simple string comparison, not HMAC

type Environment

type Environment string

Environment represents the RevenueCat environment

const (
	EnvironmentProduction Environment = "PRODUCTION"
	EnvironmentSandbox    Environment = "SANDBOX"
)

type Event

type Event struct {
	// Event identification
	ID        string    `json:"id"`
	Type      EventType `json:"type"`
	Timestamp int64     `json:"event_timestamp_ms"`

	// App info
	AppID     string `json:"app_id"`
	AppUserID string `json:"app_user_id"` // This is our user.uuid

	// Aliases (alternative user IDs)
	Aliases []string `json:"aliases"`

	// Original app user ID (for transfers)
	OriginalAppUserID string `json:"original_app_user_id"`

	// Subscription info
	ProductID                 string      `json:"product_id"`
	EntitlementID             *string     `json:"entitlement_id"`
	EntitlementIDs            []string    `json:"entitlement_ids"`
	PresentedOfferingID       *string     `json:"presented_offering_id"`
	PeriodType                PeriodType  `json:"period_type"`
	PurchasedAtMs             int64       `json:"purchased_at_ms"`
	ExpirationAtMs            int64       `json:"expiration_at_ms"`
	GracePeriodExpirationAtMs int64       `json:"grace_period_expiration_at_ms"`
	Environment               Environment `json:"environment"`
	Store                     Store       `json:"store"`
	TransactionID             *string     `json:"transaction_id"`
	StoreTransactionID        *string     `json:"store_transaction_id"`
	OriginalTransactionID     *string     `json:"original_transaction_id"`

	// Pricing info
	Price                    *float64 `json:"price"`
	PriceInPurchasedCurrency *float64 `json:"price_in_purchased_currency"`
	Currency                 *string  `json:"currency"`
	TakehomePercentage       *float64 `json:"takehome_percentage"`
	TaxPercentage            *float64 `json:"tax_percentage"`
	CommissionPercentage     *float64 `json:"commission_percentage"`

	// Renewal/cancellation info
	IsTrialConversion *bool   `json:"is_trial_conversion"`
	IsFamilyShare     *bool   `json:"is_family_share"`
	CountryCode       string  `json:"country_code"`
	OfferCode         *string `json:"offer_code"`
	CancelReason      *string `json:"cancel_reason"`
	AutoResumeAt      int64   `json:"auto_resume_at_ms"`
	NewProductID      *string `json:"new_product_id"` // For PRODUCT_CHANGE
	RenewalNumber     *int    `json:"renewal_number"`

	// Subscriber attributes (custom data set via SDK)
	SubscriberAttributes map[string]SubscriberAttribute `json:"subscriber_attributes"`

	// Metadata (custom data)
	Metadata map[string]interface{} `json:"metadata"`
}

Event represents the event data in a webhook

func (*Event) GetAppUserID

func (e *Event) GetAppUserID() string

GetAppUserID returns the app user ID from the event (user's UUID in our system)

func (*Event) GetAutoResumeTime

func (e *Event) GetAutoResumeTime() *time.Time

GetAutoResumeTime returns the auto-resume time for paused subscriptions

func (*Event) GetEventTime

func (e *Event) GetEventTime() time.Time

GetEventTime returns the event timestamp as time.Time

func (*Event) GetExpirationTime

func (e *Event) GetExpirationTime() *time.Time

GetExpirationTime returns the expiration time as time.Time

func (*Event) GetGracePeriodExpirationTime

func (e *Event) GetGracePeriodExpirationTime() *time.Time

GetGracePeriodExpirationTime returns the grace period expiration time

func (*Event) GetPurchaseTime

func (e *Event) GetPurchaseTime() *time.Time

GetPurchaseTime returns the purchase time as time.Time

func (*Event) GetSubscriberAttributeValue

func (e *Event) GetSubscriberAttributeValue(key string) (string, bool)

GetSubscriberAttributeValue returns the value of a subscriber attribute

func (*Event) GetTransactionID

func (e *Event) GetTransactionID() string

GetTransactionID returns the best available transaction ID Priority: original_transaction_id > transaction_id > event ID

func (*Event) IsAppStore

func (e *Event) IsAppStore() bool

IsAppStore returns true if the purchase is from Apple App Store

func (*Event) IsPlayStore

func (e *Event) IsPlayStore() bool

IsPlayStore returns true if the purchase is from Google Play Store

func (*Event) IsSandbox

func (e *Event) IsSandbox() bool

IsSandbox returns true if the event is from a sandbox environment

func (*Event) IsSubscriptionEvent

func (e *Event) IsSubscriptionEvent() bool

IsSubscriptionEvent returns true if this is a subscription-related event

func (*Event) RequiresSubscriptionUpdate

func (e *Event) RequiresSubscriptionUpdate() bool

RequiresSubscriptionUpdate returns true if this event should update subscription state

type EventType

type EventType string

EventType represents RevenueCat webhook event types

const (
	// Initial purchase events
	EventInitialPurchase           EventType = "INITIAL_PURCHASE"
	EventNonRenewingPurchase       EventType = "NON_RENEWING_PURCHASE"
	EventRenewal                   EventType = "RENEWAL"
	EventProductChange             EventType = "PRODUCT_CHANGE"
	EventCancellation              EventType = "CANCELLATION"
	EventUncancellation            EventType = "UNCANCELLATION"
	EventBillingIssue              EventType = "BILLING_ISSUE"
	EventSubscriberAlias           EventType = "SUBSCRIBER_ALIAS"
	EventSubscriptionPaused        EventType = "SUBSCRIPTION_PAUSED"
	EventSubscriptionExtended      EventType = "SUBSCRIPTION_EXTENDED"
	EventExpiration                EventType = "EXPIRATION"
	EventTransfer                  EventType = "TRANSFER"
	EventTest                      EventType = "TEST"
	EventTemporaryEntitlementGrant EventType = "TEMPORARY_ENTITLEMENT_GRANT"
)

type PeriodType

type PeriodType string

PeriodType represents the subscription period type

const (
	PeriodTypeNormal      PeriodType = "NORMAL"
	PeriodTypeTrial       PeriodType = "TRIAL"
	PeriodTypeIntro       PeriodType = "INTRO"
	PeriodTypePromotional PeriodType = "PROMOTIONAL"
)

type ProductMapping

type ProductMapping struct {
	PlanCode     string
	BillingCycle string // "monthly" or "yearly"
}

ProductMapping maps a RevenueCat product to internal plan

type Store

type Store string

Store represents the app store

const (
	StoreAppStore    Store = "APP_STORE"
	StorePlayStore   Store = "PLAY_STORE"
	StoreMacAppStore Store = "MAC_APP_STORE"
	StoreStripe      Store = "STRIPE"
	StoreAmazon      Store = "AMAZON"
	StorePromo       Store = "PROMOTIONAL"
)

type SubscriberAttribute

type SubscriberAttribute struct {
	Value     string `json:"value"`
	UpdatedAt int64  `json:"updated_at_ms"`
}

SubscriberAttribute represents a custom attribute set on the subscriber

type WebhookEvent

type WebhookEvent struct {
	APIVersion string `json:"api_version"`
	Event      Event  `json:"event"`
}

WebhookEvent represents the top-level webhook payload from RevenueCat

Jump to

Keyboard shortcuts

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