revenuecat

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2021 License: MIT Imports: 7 Imported by: 0

README

RevenueCat

PkgGoDev Test

Go package for interacting with the RevenueCat API.

Usage

Example
package main

import (
	"fmt"

	"github.com/mhemmings/revenuecat"
)

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

	fmt.Println("user entitled: %t", entitled)
}
Documentation

For full documentation, see pkg.go.dev/github.com/mhemmings/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. https://docs.revenuecat.com/reference#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, or Stripe and will create a user if they don't already exist. https://docs.revenuecat.com/reference#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://docs.revenuecat.com/reference#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://docs.revenuecat.com/reference#delete-offering-override

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

DeleteSubscriber permanently deletes a subscriber. https://docs.revenuecat.com/reference#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://docs.revenuecat.com/reference#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://docs.revenuecat.com/reference#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://docs.revenuecat.com/reference#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://docs.revenuecat.com/reference#override-offering

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://docs.revenuecat.com/reference#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://docs.revenuecat.com/reference#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://docs.revenuecat.com/reference#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) *Client

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

func NewWithClient

func NewWithClient(apiKey string, client *http.Client) *Client

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

func (*Client) AddUserAttribution

func (c *Client) AddUserAttribution(ctx context.Context, userID string, network Network, data AttributionData) error

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

func (*Client) CreatePurchase

func (c *Client) CreatePurchase(
	ctx context.Context,
	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://docs.revenuecat.com/reference#receipts

func (*Client) DeferGoogleSubscription

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

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

func (*Client) DeleteOfferingOverride

func (c *Client) DeleteOfferingOverride(ctx context.Context, userID string) (Subscriber, error)

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

func (*Client) DeleteSubscriber

func (c *Client) DeleteSubscriber(ctx context.Context, userID string) error

DeleteSubscriber permanently deletes a subscriber. https://docs.revenuecat.com/reference#subscribersapp_user_id

func (*Client) GetSubscriber

func (c *Client) GetSubscriber(ctx context.Context, userID string) (Subscriber, error)

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

func (*Client) GetSubscriberWithPlatform

func (c *Client) GetSubscriberWithPlatform(ctx context.Context, 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://docs.revenuecat.com/reference#subscribers

func (*Client) GrantEntitlement

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

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

func (*Client) OverrideOffering

func (c *Client) OverrideOffering(ctx context.Context, userID string, offeringUUID string) (Subscriber, error)

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

func (*Client) RefundGoogleSubscription

func (c *Client) RefundGoogleSubscription(ctx context.Context, userID string, id string) (Subscriber, error)

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

func (*Client) RevokeEntitlement

func (c *Client) RevokeEntitlement(ctx context.Context, userID string, id string) (Subscriber, error)

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

func (*Client) UpdateSubscriberAttributes

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

UpdateSubscriberAttributes updates subscriber attributes for a user. https://docs.revenuecat.com/reference#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"`
	Attributes        map[string]SubscriberAttribute `json:"attributes,omitempty"`
}

CreatePurchaseOptions holds the optional values for creating a purchase. https://docs.revenuecat.com/reference#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://docs.revenuecat.com/reference#duration-values

type Entitlement

type Entitlement struct {
	ExpiresDate       time.Time `json:"expires_date"`
	PurchaseDate      time.Time `json:"purchase_date"`
	ProductIdentifier string    `json:"product_identifier"`
}

https://docs.revenuecat.com/reference#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://docs.revenuecat.com/reference#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://docs.revenuecat.com/reference#section-the-non-subscription-object

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://docs.revenuecat.com/reference#the-subscription-object

type Store

type Store string

PeriodType 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://docs.revenuecat.com/reference#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"`
	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) 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://docs.revenuecat.com/reference#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"`
}

https://docs.revenuecat.com/reference#the-subscription-object

Jump to

Keyboard shortcuts

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