revenuecat

package module
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 7 Imported by: 0

README

RevenueCat

PkgGoDev Test

Go package for interacting with the RevenueCat API v1. Inspired by the official TS/JS client

Installation

To install the RevenueCat Go SDK, use go get:

go get github.com/claywarren/revenuecat

Usage

Examples
package main

import (
	"fmt"

	"github.com/claywarren/revenuecat"
)

func main() {
	rc := revenuecat.New("apikey")
	sub, _ := rc.GetSubscriber("123")
	entitled := sub.IsEntitledTo("premium")

	fmt.Printf("user entitled: %t\n", entitled)
}
Client With Options
package main

import (
	"fmt"
	"net/http"
	"time"

	"github.com/claywarren/revenuecat"
)

func main() {
	customClient := &http.Client{
		Timeout: 20 * time.Second,
	}

	rc := revenuecat.New("apikey", revenuecat.WithHTTPClient(customClient), revenuecat.WithSandboxEnabled(true), revenuecat.WithAPIURL("https://custom.api.url/v1/"))

	sub, _ := rc.GetSubscriber("123")
	entitled := sub.IsEntitledTo("premium")

	fmt.Printf("user entitled: %t\n", entitled)
}
Documentation

For full documentation, see pkg.go.dev/github.com/claywarren/revenuecat

func (*Client) AddUserAttribution
func (c *Client) AddUserAttribution(userID string, network Network, data AttributionData) error

AddUserAttribution attaches attribution data to a subscriber from specific supported networks. RevenueCat documents this endpoint as deprecated. https://www.revenuecat.com/docs/api-v1#tag/customers/operation/subscribersattribution

func (*Client) CreatePurchase
func (c *Client) CreatePurchase(userID string, receipt string, opt *CreatePurchaseOptions) (Subscriber, error)

CreatePurchase records a purchase for a user from iOS, Android, Amazon, macOS, UIKit for Mac, Stripe, Roku, or Paddle and will create a user if they don't already exist. https://www.revenuecat.com/docs/api-v1#tag/transactions/operation/receipts

func (*Client) DeferGoogleSubscription
func (c *Client) DeferGoogleSubscription(userID string, id string, nextExpiry time.Time) (Subscriber, error)

DeferGoogleSubscription defers the purchase of a Google Subscription to a later date. https://www.revenuecat.com/docs/api-v1#defer-a-google-subscription

func (*Client) DeferGoogleSubscriptionByDays
func (c *Client) DeferGoogleSubscriptionByDays(userID string, id string, days int) (Subscriber, error)

DeferGoogleSubscriptionByDays defers a Google Subscription by a number of days. https://www.revenuecat.com/docs/api-v1#tag/transactions/operation/defer-a-google-subscription

func (*Client) DeleteOfferingOverride
func (c *Client) DeleteOfferingOverride(userID string) (Subscriber, error)

DeleteOfferingOverride reset the offering overrides back to the current offering for a specific user. https://www.revenuecat.com/docs/api-v1#delete-offering-override

func (*Client) DeleteSubscriber
func (c *Client) DeleteSubscriber(userID string) error

DeleteSubscriber permanently deletes a subscriber. https://www.revenuecat.com/docs/api-v1#subscribersapp_user_id

func (*Client) GetSubscriber
func (c *Client) GetSubscriber(userID string) (Subscriber, error)

GetSubscriber gets the latest subscriber info or creates one if it doesn't exist. https://www.revenuecat.com/docs/api-v1#subscribers

func (*Client) GetSubscriberWithPlatform
func (c *Client) GetSubscriberWithPlatform(userID string, platform string) (Subscriber, error)

GetSubscriberWithPlatform gets the latest subscriber info or creates one if it doesn't exist, updating the subscriber record's last_seen value for the platform provided. https://www.revenuecat.com/docs/api-v1#subscribers

func (*Client) GrantEntitlement
func (c *Client) GrantEntitlement(userID string, id string, duration Duration, startTime time.Time) (Subscriber, error)

GrantEntitlement grants a user a promotional entitlement. https://www.revenuecat.com/docs/api-v1#tag/entitlements/operation/grant-a-promotional-entitlement

func (*Client) GrantEntitlementUntil
func (c *Client) GrantEntitlementUntil(userID string, id string, endTime time.Time) (Subscriber, error)

GrantEntitlementUntil grants a user a promotional entitlement until a specific expiration time. https://www.revenuecat.com/docs/api-v1#tag/entitlements/operation/grant-a-promotional-entitlement

func (*Client) OverrideOffering
func (c *Client) OverrideOffering(userID string, offeringUUID string) (Subscriber, error)

OverrideOffering overrides the current Offering for a specific user. https://www.revenuecat.com/docs/api-v1#override-offering

func (*Client) CancelGoogleSubscription
func (c *Client) CancelGoogleSubscription(userID string, transactionID string) (Subscriber, error)

CancelGoogleSubscription cancels a Google subscription without immediately revoking access. https://www.revenuecat.com/docs/api-v1#tag/transactions/operation/cancel-a-google-subscription

func (*Client) ExtendAppStoreSubscription
func (c *Client) ExtendAppStoreSubscription(userID string, transactionID string, days int) (Subscriber, error)

ExtendAppStoreSubscription extends an App Store subscription renewal date. https://www.revenuecat.com/docs/api-v1#tag/transactions/operation/extend-an-app-store-subscription

func (*Client) RefundGooglePurchase
func (c *Client) RefundGooglePurchase(userID string, transactionID string) (Subscriber, error)

RefundGooglePurchase issues a refund for a Google transaction and revokes access. https://www.revenuecat.com/docs/api-v1#tag/transactions/operation/refund-a-google-purchase

func (*Client) RefundGoogleSubscription
func (c *Client) RefundGoogleSubscription(userID string, id string) (Subscriber, error)

RefundGoogleSubscription immediately revokes access to a Google Subscription and issues a refund for the last purchase. https://www.revenuecat.com/docs/api-v1#revoke-a-google-subscription

func (*Client) RevokeEntitlement
func (c *Client) RevokeEntitlement(userID string, id string) (Subscriber, error)

RevokeEntitlement revokes all promotional entitlements for a given entitlement identifier and app user ID. https://www.revenuecat.com/docs/api-v1#revoke-promotional-entitlements

func (*Client) UpdateSubscriberAttributes
func (c *Client) UpdateSubscriberAttributes(userID string, attributes map[string]SubscriberAttribute) error

UpdateSubscriberAttributes updates subscriber attributes for a user. https://www.revenuecat.com/docs/api-v1#update-subscriber-attributes

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AttributionData

type AttributionData struct {
	IDFA           string `json:"rc_idfa,omitempty"`
	PlayServicesID string `json:"rc_gps_adid,omitempty"`
}

AttributionData holds the identifier value for either the App Store or Play Services.

type Client

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

Client makes authorized calls to the RevenueCat API.

func New

func New(apiKey string, opts ...Option) *Client

New returns a new *Client for the provided API key. For more information on authentication, see https://docs.revenuecat.com/docs/authentication.

func (*Client) AddUserAttribution

func (c *Client) AddUserAttribution(userID string, network Network, data AttributionData) error

AddUserAttribution attaches attribution data to a subscriber from specific supported networks. https://www.revenuecat.com/docs/api-v1#subscribersattribution

func (*Client) CancelGoogleSubscription added in v0.11.0

func (c *Client) CancelGoogleSubscription(userID string, transactionID string) (Subscriber, error)

CancelGoogleSubscription cancels a Google subscription without immediately revoking access. https://www.revenuecat.com/docs/api-v1#tag/transactions/operation/cancel-a-google-subscription

func (*Client) CreatePurchase

func (c *Client) CreatePurchase(userID string, receipt string, opt *CreatePurchaseOptions) (Subscriber, error)

CreatePurchase records a purchase for a user from iOS, Android, or Stripe and will create a user if they don't already exist. https://www.revenuecat.com/docs/api-v1#receipts

func (*Client) DeferGoogleSubscription

func (c *Client) DeferGoogleSubscription(userID string, id string, nextExpiry time.Time) (Subscriber, error)

DeferGoogleSubscription defers the purchase of a Google Subscription to a later date. https://www.revenuecat.com/docs/api-v1#defer-a-google-subscription

func (*Client) DeferGoogleSubscriptionByDays added in v0.11.0

func (c *Client) DeferGoogleSubscriptionByDays(userID string, id string, days int) (Subscriber, error)

DeferGoogleSubscriptionByDays defers a Google Subscription by a number of days. https://www.revenuecat.com/docs/api-v1#tag/transactions/operation/defer-a-google-subscription

func (*Client) DeleteOfferingOverride

func (c *Client) DeleteOfferingOverride(userID string) (Subscriber, error)

DeleteOfferingOverride reset the offering overrides back to the current offering for a specific user. https://www.revenuecat.com/docs/api-v1#delete-offering-override

func (*Client) DeleteSubscriber

func (c *Client) DeleteSubscriber(userID string) error

DeleteSubscriber permanently deletes a subscriber. https://www.revenuecat.com/docs/api-v1#subscribersapp_user_id

func (*Client) ExtendAppStoreSubscription added in v0.11.0

func (c *Client) ExtendAppStoreSubscription(userID string, transactionID string, days int) (Subscriber, error)

ExtendAppStoreSubscription extends an App Store subscription renewal date. https://www.revenuecat.com/docs/api-v1#tag/transactions/operation/extend-an-app-store-subscription

func (*Client) GetOfferings

func (c *Client) GetOfferings(userID string) (*Offerings, error)

GetOfferings gets the offerings for a specific user. https://www.revenuecat.com/docs/api-v1#get-offerings

func (*Client) GetSubscriber

func (c *Client) GetSubscriber(userID string) (Subscriber, error)

GetSubscriber gets the latest subscriber info or creates one if it doesn't exist. https://www.revenuecat.com/docs/api-v1#subscribers

func (*Client) GetSubscriberWithPlatform

func (c *Client) GetSubscriberWithPlatform(userID string, platform string) (Subscriber, error)

GetSubscriberWithPlatform gets the latest subscriber info or creates one if it doesn't exist, updating the subscriber record's last_seen value for the platform provided. https://www.revenuecat.com/docs/api-v1#subscribers

func (*Client) GrantEntitlement

func (c *Client) GrantEntitlement(userID string, id string, duration Duration, startTime time.Time) (Subscriber, error)

GrantEntitlement grants a user a promotional entitlement. https://www.revenuecat.com/docs/api-v1#grant-a-promotional-entitlement

func (*Client) GrantEntitlementUntil added in v0.11.0

func (c *Client) GrantEntitlementUntil(userID string, id string, endTime time.Time) (Subscriber, error)

GrantEntitlementUntil grants a user a promotional entitlement until a specific expiration time. https://www.revenuecat.com/docs/api-v1#tag/entitlements/operation/grant-a-promotional-entitlement

func (*Client) OverrideOffering

func (c *Client) OverrideOffering(userID string, offeringUUID string) (Subscriber, error)

OverrideOffering overrides the current Offering for a specific user. https://www.revenuecat.com/docs/api-v1#override-offering

func (*Client) RefundGooglePurchase added in v0.11.0

func (c *Client) RefundGooglePurchase(userID string, transactionID string) (Subscriber, error)

RefundGooglePurchase issues a refund for a Google transaction and revokes access. https://www.revenuecat.com/docs/api-v1#tag/transactions/operation/refund-a-google-purchase

func (*Client) RefundGoogleSubscription

func (c *Client) RefundGoogleSubscription(userID string, id string) (Subscriber, error)

RefundGoogleSubscription immediately revokes access to a Google Subscription and issues a refund for the last purchase. https://www.revenuecat.com/docs/api-v1#revoke-a-google-subscription

func (*Client) RevokeEntitlement

func (c *Client) RevokeEntitlement(userID string, id string) (Subscriber, error)

RevokeEntitlement revokes all promotional entitlements for a given entitlement identifier and app user ID. https://www.revenuecat.com/docs/api-v1#revoke-promotional-entitlements

func (*Client) UpdateSubscriberAttributes

func (c *Client) UpdateSubscriberAttributes(userID string, attributes map[string]SubscriberAttribute) error

UpdateSubscriberAttributes updates subscriber attributes for a user. https://www.revenuecat.com/docs/api-v1#update-subscriber-attributes

type CreatePurchaseOptions

type CreatePurchaseOptions struct {
	Platform string `json:"-"`

	ProductID                   string                         `json:"product_id,omitempty"`
	Price                       float32                        `json:"price,omitempty"`
	Currency                    string                         `json:"currency,omitempty"`
	PaymentMode                 string                         `json:"payment_mode,omitempty"`
	IntroductoryPrice           float32                        `json:"introductory_price,omitempty"`
	IsRestore                   bool                           `json:"is_restore,omitempty"`
	PresentedOfferingIdentifier string                         `json:"presented_offering_identifier,omitempty"`
	Attributes                  map[string]SubscriberAttribute `json:"attributes,omitempty"`
}

CreatePurchaseOptions holds the optional values for creating a purchase. https://www.revenuecat.com/docs/api-v1#receipts

type Duration

type Duration string

Duration holds a predefined entitlement duration.

const (
	Daily      Duration = "daily"
	Weekly     Duration = "weekly"
	Monthly    Duration = "monthly"
	TwoMonth   Duration = "two_month"
	ThreeMonth Duration = "three_month"
	SixMonth   Duration = "six_month"
	Yearly     Duration = "yearly"
	Lifetime   Duration = "lifetime"
)

https://www.revenuecat.com/docs/api-v1#duration-values

type Entitlement

type Entitlement struct {
	ExpiresDate            *time.Time `json:"expires_date"`
	GracePeriodExpiresDate *time.Time `json:"grace_period_expires_date"`
	PurchaseDate           time.Time  `json:"purchase_date"`
	ProductIdentifier      string     `json:"product_identifier"`
	ProductPlanIdentifier  string     `json:"product_plan_identifier"`
}

https://www.revenuecat.com/docs/api-v1#the-entitlement-object

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

Error represents an error returned by RevenueCat

func (Error) Error

func (err Error) Error() string

type Network

type Network int

Network represents a predefined attribution channel.

const (
	AppleSearchAds Network = iota
	Adjust
	AppsFlyer
	Branch
	Tenjin
	Facebook
)

https://www.revenuecat.com/docs/api-v1#attribution-source-network-codes

type NonSubscription

type NonSubscription struct {
	ID           string    `json:"id"`
	PurchaseDate time.Time `json:"purchase_date"`
	Store        Store     `json:"store"`
	IsSandbox    bool      `json:"is_sandbox"`
}

https://www.revenuecat.com/docs/api-v1#section-the-non-subscription-object

type Offering

type Offering struct {
	Description string                 `json:"description"`
	Identifier  string                 `json:"identifier"`
	Packages    []Package              `json:"packages"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

Offering holds an offering.

type Offerings

type Offerings struct {
	Current *Offering           `json:"current"`
	All     map[string]Offering `json:"all"`
}

Offerings holds the offerings for a user.

type Option

type Option func(*Client)

func WithAPIURL

func WithAPIURL(url string) Option

WithAPIURL - Option to set the API URL

func WithHTTPClient

func WithHTTPClient(client doer) Option

WithHTTPClient - Option to set the HTTP client

func WithSandboxEnabled

func WithSandboxEnabled(enabled bool) Option

WithSandboxEnabled - Option to enable or disable sandbox mode

type OwnershipType

type OwnershipType string

OwnershipType holds the predefined values for a subscription ownership type.

const (
	PurchasedOwnershipType    OwnershipType = "PURCHASED"
	FamilySharedOwnershipType OwnershipType = "FAMILY_SHARED"
)

type Package

type Package struct {
	Identifier                string                 `json:"identifier"`
	PlatformProductIdentifier string                 `json:"platform_product_identifier"`
	PackageType               PackageType            `json:"package_type"`
	Metadata                  map[string]interface{} `json:"metadata,omitempty"`
}

Package holds a package.

type PackageType

type PackageType string

PackageType holds the predefined values for a package type.

const (
	UnknownPackageType    PackageType = "UNKNOWN"
	CustomPackageType     PackageType = "CUSTOM"
	LifetimePackageType   PackageType = "LIFETIME"
	AnnualPackageType     PackageType = "ANNUAL"
	SixMonthPackageType   PackageType = "SIX_MONTH"
	ThreeMonthPackageType PackageType = "THREE_MONTH"
	TwoMonthPackageType   PackageType = "TWO_MONTH"
	MonthlyPackageType    PackageType = "MONTHLY"
	WeeklyPackageType     PackageType = "WEEKLY"
)

https://docs.revenuecat.com/docs/displaying-products#package-types

type PeriodType

type PeriodType string

PeriodType holds the predefined values for a subscription period.

const (
	NormalPeriodType PeriodType = "normal"
	TrialPeriodType  PeriodType = "trial"
	IntroPeriodType  PeriodType = "intro"
)

https://www.revenuecat.com/docs/api-v1#the-subscription-object

type Store

type Store string

Store holds the predefined values for a store.

const (
	AppStore         Store = "app_store"
	MacAppStore      Store = "mac_app_store"
	PlayStore        Store = "play_store"
	StripeStore      Store = "stripe"
	PromotionalStore Store = "promotional"
)

https://www.revenuecat.com/docs/api-v1#the-subscription-object

type Subscriber

type Subscriber struct {
	OriginalAppUserID          string                         `json:"original_app_user_id"`
	OriginalApplicationVersion *string                        `json:"original_application_version"`
	FirstSeen                  time.Time                      `json:"first_seen"`
	LastSeen                   time.Time                      `json:"last_seen"`
	ManagementURL              *string                        `json:"management_url"`
	Entitlements               map[string]Entitlement         `json:"entitlements"`
	Subscriptions              map[string]Subscription        `json:"subscriptions"`
	NonSubscriptions           map[string][]NonSubscription   `json:"non_subscriptions"`
	SubscriberAttributes       map[string]SubscriberAttribute `json:"subscriber_attributes"`
}

Subscriber holds a subscriber returned by the RevenueCat API.

func (Subscriber) ActiveSubscriptions

func (s Subscriber) ActiveSubscriptions() []string

ActiveSubscriptions returns the identifiers of all active subscriptions.

func (Subscriber) AllPurchasedProductIdentifiers

func (s Subscriber) AllPurchasedProductIdentifiers() []string

AllPurchasedProductIdentifiers returns the identifiers of all products ever purchased.

func (Subscriber) IsEntitledTo

func (s Subscriber) IsEntitledTo(entitlement string) bool

IsEntitledTo returns true if the Subscriber has the given entitlement.

type SubscriberAttribute

type SubscriberAttribute struct {
	Value     string
	UpdatedAt time.Time
}

https://www.revenuecat.com/docs/api-v1#section-the-subscriber-attribute-object

func (SubscriberAttribute) MarshalJSON

func (attr SubscriberAttribute) MarshalJSON() ([]byte, error)

func (*SubscriberAttribute) UnmarshalJSON

func (attr *SubscriberAttribute) UnmarshalJSON(data []byte) error

type Subscription

type Subscription struct {
	ExpiresDate             *time.Time    `json:"expires_date"`
	PurchaseDate            time.Time     `json:"purchase_date"`
	OriginalPurchaseDate    time.Time     `json:"original_purchase_date"`
	PeriodType              PeriodType    `json:"period_type"`
	Store                   Store         `json:"store"`
	IsSandbox               bool          `json:"is_sandbox"`
	UnsubscribeDetectedAt   *time.Time    `json:"unsubscribe_detected_at"`
	BillingIssuesDetectedAt *time.Time    `json:"billing_issues_detected_at"`
	AutoResumeDate          *time.Time    `json:"auto_resume_date"`
	GracePeriodExpiresDate  *time.Time    `json:"grace_period_expires_date"`
	RefundedAt              *time.Time    `json:"refunded_at"`
	OwnershipType           OwnershipType `json:"ownership_type"`
	StoreTransactionID      string        `json:"store_transaction_id"`
	ProductPlanIdentifier   string        `json:"product_plan_identifier"`
}

https://www.revenuecat.com/docs/api-v1#the-subscription-object

Jump to

Keyboard shortcuts

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