Documentation
¶
Index ¶
- Variables
- type Client
- func (c *Client) AddProductMapping(productID string, planCode, billingCycle string)
- func (c *Client) GetPlanCode(productID string) (string, string, error)
- func (c *Client) ParseWebhook(payload []byte, authToken string) (*WebhookEvent, error)
- func (c *Client) VerifyAuthorization(authToken string) error
- type Environment
- type Event
- func (e *Event) GetAppUserID() string
- func (e *Event) GetAutoResumeTime() *time.Time
- func (e *Event) GetEventTime() time.Time
- func (e *Event) GetExpirationTime() *time.Time
- func (e *Event) GetGracePeriodExpirationTime() *time.Time
- func (e *Event) GetPurchaseTime() *time.Time
- func (e *Event) GetSubscriberAttributeValue(key string) (string, bool)
- func (e *Event) GetTransactionID() string
- func (e *Event) IsAppStore() bool
- func (e *Event) IsPlayStore() bool
- func (e *Event) IsSandbox() bool
- func (e *Event) IsSubscriptionEvent() bool
- func (e *Event) RequiresSubscriptionUpdate() bool
- type EventType
- type PeriodType
- type ProductMapping
- type Store
- type SubscriberAttribute
- type WebhookEvent
Constants ¶
This section is empty.
Variables ¶
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 (*Client) AddProductMapping ¶
AddProductMapping adds a product ID to plan code mapping
func (*Client) GetPlanCode ¶
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 ¶
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"`
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 ¶
GetAppUserID returns the app user ID from the event (user's UUID in our system)
func (*Event) GetAutoResumeTime ¶
GetAutoResumeTime returns the auto-resume time for paused subscriptions
func (*Event) GetEventTime ¶
GetEventTime returns the event timestamp as time.Time
func (*Event) GetExpirationTime ¶
GetExpirationTime returns the expiration time as time.Time
func (*Event) GetGracePeriodExpirationTime ¶
GetGracePeriodExpirationTime returns the grace period expiration time
func (*Event) GetPurchaseTime ¶
GetPurchaseTime returns the purchase time as time.Time
func (*Event) GetSubscriberAttributeValue ¶
GetSubscriberAttributeValue returns the value of a subscriber attribute
func (*Event) GetTransactionID ¶
GetTransactionID returns the best available transaction ID Priority: original_transaction_id > transaction_id > event ID
func (*Event) IsAppStore ¶
IsAppStore returns true if the purchase is from Apple App Store
func (*Event) IsPlayStore ¶
IsPlayStore returns true if the purchase is from Google Play Store
func (*Event) IsSubscriptionEvent ¶
IsSubscriptionEvent returns true if this is a subscription-related event
func (*Event) RequiresSubscriptionUpdate ¶
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 ¶
ProductMapping maps a RevenueCat product to internal plan
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 ¶
WebhookEvent represents the top-level webhook payload from RevenueCat