revenuecat

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

install

go get github.com/pkg6/go-revenuecat

Basic Use

client := &revenuecat.Client{
  ApiKeyV1:     "sk_*******************",
  ApiKeyV2:     "sk_*******************",
  PublicAPIKey: "appl_*******************",
}
client.GetOrCreateSubscriber("dev-0")

Implementation List

https://pkg.go.dev/github.com/pkg6/go-revenuecat

Documentation

Index

Constants

View Source
const (
	PlatformIOS         = "ios"
	PlatformAndroid     = "android"
	PlatformAmazon      = "amazon"
	PlatformMacos       = "macos"
	PlatformUikitformac = "uikitformac"
)
View Source
const (
	ApiKeyV1 = "v1"
	ApiKeyV2 = "v2"
)

Variables

This section is empty.

Functions

func IsExpired

func IsExpired(timestamp int64) bool

func JsonUnmarshal

func JsonUnmarshal(v, s any) error

func PathQuery

func PathQuery(path string, query map[string]string) string

func WebHookWithCallback

func WebHookWithCallback(r *http.Request, callbacks ...WebHookCallback) error

Types

type Amazon

type Amazon struct {
	PackageName string `json:"package_name,omitempty"`
}

type AppStore

type AppStore struct {
	BundleId string `json:"bundle_id,omitempty"`
}

type AppsItem

type AppsItem struct {
	AppStore  *AppStore `json:"app_store"`
	CreatedAt int64     `json:"created_at"`
	Id        string    `json:"id"`
	Name      string    `json:"name"`
	Object    string    `json:"object"`
	ProjectId string    `json:"project_id"`
	Type      string    `json:"type"`
}

type Attributes

type Attributes struct {
	ProductId  string             `json:"product_id,omitempty"`
	Price      float64            `json:"price,omitempty"`
	Currency   string             `json:"currency,omitempty"`
	IsRestore  string             `json:"is_restore,omitempty"`
	Attributes *AttributesKeyName `json:"attributes,omitempty"`
	AppUserId  string             `json:"app_user_id,omitempty"`
	FetchToken string             `json:"fetch_token,omitempty"`
}

type AttributesKeyName

type AttributesKeyName struct {
	KeyName *KeyName `json:"key_name,omitempty"`
}

type Client

type Client struct {
	//https://www.revenuecat.com/reference/revenuecat-rest-api
	ApiKeyV1 string
	//https://www.revenuecat.com/reference/revenuecat-rest-api
	ApiKeyV2 string
	//https://app.revenuecat.com/projects/{ProjectID}/apps/{RevenueCatAppID}
	PublicAPIKey string

	BaseURL *url.URL
	Client  *http.Client
}

func (*Client) CallKeyVersion

func (c *Client) CallKeyVersion(keyVersion, method, path string, reqBody any, platform string, respBody any) error

func (*Client) CreateAPurchase

func (c *Client) CreateAPurchase(req *CreateAPurchaseRequest, platforms ...string) (resp *SubscriberResponse, err error)

CreateAPurchase https://www.revenuecat.com/reference/receipts

func (*Client) DeleteSubscriber

func (c *Client) DeleteSubscriber(appUserId string) (resp *SubscriberDeleteResponse, err error)

DeleteSubscriber https://www.revenuecat.com/reference/delete-subscriber

func (*Client) Do

func (c *Client) Do(req *http.Request, d any) (resp *http.Response, err error)

func (*Client) GetAListOfApps

func (c *Client) GetAListOfApps(nextPageOrProjectId string) (resp *GetAlistOfAppsResponse, err error)

GetAListOfApps https://www.revenuecat.com/reference/list-apps

func (*Client) GetAnApp

func (c *Client) GetAnApp(projectId, appId string) (resp *GetAnAppResponse, err error)

GetAnApp https://www.revenuecat.com/reference/get-app

func (*Client) GetOfferings

func (c *Client) GetOfferings(appUserId string, platforms ...string) (resp *GetOfferingsResponse, err error)

GetOfferings https://www.revenuecat.com/reference/get-offerings

func (*Client) GetOrCreateSubscriber

func (c *Client) GetOrCreateSubscriber(appUserId string, platforms ...string) (resp *SubscriberResponse, err error)

GetOrCreateSubscriber https://www.revenuecat.com/reference/subscribers

func (*Client) GooglePlayCancelASubscription

func (c *Client) GooglePlayCancelASubscription(appUserId, storeTransactionIdentifier string) (resp *SubscriberResponse, err error)

GooglePlayCancelASubscription https://www.revenuecat.com/reference/cancel-a-google-subscription

func (*Client) GooglePlayDeferASubscription

func (c *Client) GooglePlayDeferASubscription(appUserId, productIdentifier string, req *GooglePlayDeferASubscriptionRequest) (resp *SubscriberResponse, err error)

GooglePlayDeferASubscription https://www.revenuecat.com/reference/defer-a-google-subscription

func (*Client) GooglePlayRefundAndRevokePurchase

func (c *Client) GooglePlayRefundAndRevokePurchase(appUserId, storeTransactionIdentifier string) (resp *SubscriberResponse, err error)

GooglePlayRefundAndRevokePurchase https://www.revenuecat.com/reference/refund-a-google-purchase

func (*Client) GooglePlayRefundAndRevokeSubscription

func (c *Client) GooglePlayRefundAndRevokeSubscription(appUserId, productIdentifier string) (resp *SubscriberResponse, err error)

GooglePlayRefundAndRevokeSubscription https://www.revenuecat.com/reference/revoke-a-google-subscription

func (*Client) GrantAPromotionalEntitlement

func (c *Client) GrantAPromotionalEntitlement(appUserId, entitlementIdentifier string, req *GrantAPromotionalEntitlementRequest) (resp *SubscriberResponse, err error)

GrantAPromotionalEntitlement https://www.revenuecat.com/reference/grant-a-promotional-entitlement

func (*Client) NewRequest

func (c *Client) NewRequest(apiKey, method, urlStr, platform string, reqBody any) (*http.Request, error)

func (*Client) OverrideACustomerSCurrentOffering

func (c *Client) OverrideACustomerSCurrentOffering(appUserId, offeringUuid string) (resp *SubscriberResponse, err error)

OverrideACustomerSCurrentOffering https://www.revenuecat.com/reference/override-offering

func (*Client) RemoveACustomerSCurrentOfferingOverride

func (c *Client) RemoveACustomerSCurrentOfferingOverride(appUserId string) (resp *SubscriberResponse, err error)

RemoveACustomerSCurrentOfferingOverride https://www.revenuecat.com/reference/delete-offering-override

func (*Client) RevokePromotionalEntitlements

func (c *Client) RevokePromotionalEntitlements(appUserId, entitlementIdentifier string) (resp *SubscriberResponse, err error)

RevokePromotionalEntitlements https://www.revenuecat.com/reference/revoke-promotional-entitlements

type CreateAPurchaseRequest

type CreateAPurchaseRequest struct {
	AppUserId                   string      `json:"app_user_id"`
	FetchToken                  string      `json:"fetch_token"`
	ProductId                   string      `json:"product_id,omitempty"`
	Price                       float64     `json:"price,omitempty"`
	Currency                    string      `json:"currency,omitempty"`
	IsRestore                   bool        `json:"is_restore,omitempty"`
	PaymentMode                 int         `json:"payment_mode,omitempty"`
	CreateEvents                bool        `json:"create_events,omitempty"`
	ShouldUpdateLastSeenFields  bool        `json:"should_update_last_seen_fields,omitempty"`
	SubscriptionGroupId         string      `json:"subscription_group_id,omitempty"`
	StoreUserId                 string      `json:"store_user_id,omitempty"`
	PresentedOfferingIdentifier string      `json:"presented_offering_identifier,omitempty"`
	ObserverMode                bool        `json:"observer_mode,omitempty"`
	IntroductoryPrice           float64     `json:"introductory_price,omitempty"`
	NormalDuration              string      `json:"normal_duration,omitempty"`
	IntroDuration               string      `json:"intro_duration,omitempty"`
	TrialDuration               string      `json:"trial_duration,omitempty"`
	StoreCountry                string      `json:"store_country,omitempty"`
	IpAddress                   string      `json:"ip_address,omitempty"`
	Attributes                  *Attributes `json:"attributes,omitempty"`
}

type DurationValue

type DurationValue string
const (
	// DurationValueDaily
	//24 hour access
	DurationValueDaily DurationValue = "daily"
	// DurationValueThreeDay
	//72 hour access
	DurationValueThreeDay DurationValue = "three_day"
	// DurationValueWeekly
	//7 day access
	DurationValueWeekly DurationValue = "weekly"
	// DurationValueMonthly
	//1 month (31-day) access
	DurationValueMonthly DurationValue = "monthly"
	// DurationValueTwoMonth
	//2 month (61-day) access
	DurationValueTwoMonth DurationValue = "two_month"
	// DurationValueThreeMonth
	//3 month (92-day) access
	DurationValueThreeMonth DurationValue = "three_month"
	// DurationValueSixMonth
	//6 month (183-day) access
	DurationValueSixMonth DurationValue = "six_month"
	// DurationValueYearly
	//1 year (365-day) access
	DurationValueYearly DurationValue = "yearly"
	// DurationValueLifetime
	//200 year access
	DurationValueLifetime DurationValue = "lifetime"
)

type Entitlements

type Entitlements struct {
	ExpiresDate            *time.Time `json:"expires_date,omitempty"`
	GracePeriodExpiresDate *time.Time `json:"grace_period_expires_date,omitempty"`
	PurchaseDate           *time.Time `json:"purchase_date,omitempty"`
	ProductIdentifier      string     `json:"product_identifier,omitempty"`
}

type GetAListOfProjectsItem

type GetAListOfProjectsItem struct {
	CreatedAt int64  `json:"created_at,omitempty"`
	Id        string `json:"id,omitempty"`
	Name      string `json:"name,omitempty"`
	Object    string `json:"object,omitempty"`
}

type GetAListOfProjectsResponse

type GetAListOfProjectsResponse struct {
	Items []*GetAListOfProjectsItem `json:"items,omitempty"`
	//https://api.revnuecat.com/v2/projects?starting_after=proj82bc1db5&limit=1
	NextPage string `json:"next_page,omitempty"`
	Object   string `json:"object,omitempty"`
	Url      string `json:"url,omitempty"`
}

type GetAlistOfAppsResponse

type GetAlistOfAppsResponse struct {
	Items    []*AppsItem `json:"items"`
	NextPage string      `json:"next_page"`
	Object   string      `json:"object"`
	Url      string      `json:"url"`
}

type GetAnAppResponse

type GetAnAppResponse struct {
	AppStore  AppStore `json:"app_store"`
	CreatedAt int64    `json:"created_at"`
	Id        string   `json:"id"`
	Name      string   `json:"name"`
	Object    string   `json:"object"`
	ProjectId string   `json:"project_id"`
	Type      string   `json:"type"`
}

type GetOfferingsResponse

type GetOfferingsResponse struct {
	CurrentOfferingId string              `json:"current_offering_id,omitempty"`
	Offerings         []*OfferingResponse `json:"offerings,omitempty"`
}

type GooglePlayDeferASubscriptionRequest

type GooglePlayDeferASubscriptionRequest struct {
	ExpiryTimeMs int64 `json:"expiry_time_msm"`
}

type GrantAPromotionalEntitlementRequest

type GrantAPromotionalEntitlementRequest struct {
	Duration    DurationValue `json:"duration,omitempty"`
	StartTimeMs int64         `json:"start_time_ms,omitempty"`
}

type KeyName

type KeyName struct {
	Value       string `json:"value,omitempty"`
	UpdatedAtMs string `json:"updated_at_ms,omitempty"`
}

type MacAppStore

type MacAppStore struct {
	BundleID string `json:"bundle_id,omitempty"`
}

type NonSubscriptions

type NonSubscriptions struct {
	ID                 string     `json:"id,omitempty"`
	PurchaseDate       *time.Time `json:"purchase_date,omitempty"`
	Store              string     `json:"store,omitempty"`
	IsSandbox          string     `json:"is_sandbox,omitempty"`
	StoreTransactionID string     `json:"store_transaction_id,omitempty"`
}

type OfferingPackage

type OfferingPackage struct {
	Identifier                string `json:"identifier,omitempty"`
	PlatformProductIdentifier string `json:"platform_product_identifier,omitempty"`
}

type OfferingResponse

type OfferingResponse struct {
	Description string             `json:"description,omitempty"`
	Identifier  string             `json:"identifier,omitempty"`
	Packages    []*OfferingPackage `json:"packages,omitempty"`
}

type PlayStore

type PlayStore struct {
	PackageName string `json:"package_name,omitempty"`
}

type RespError

type RespError struct {
	Response  *http.Response
	Code      int    `json:"code,omitempty"`
	Message   string `json:"message,omitempty"`
	DocUrl    string `json:"doc_url,omitempty"`
	Object    string `json:"object,omitempty"`
	Retryable bool   `json:"retryable,omitempty"`
	Type      string `json:"type,omitempty"`
}

func (*RespError) Error

func (err *RespError) Error() string

type Subscriber

type Subscriber struct {
	FirstSeen                  *time.Time        `json:"first_seen"`
	LastSeen                   *time.Time        `json:"last_seen"`
	ManagementUrl              string            `json:"management_url"`
	NonSubscriptions           *NonSubscriptions `json:"non_subscriptions"`
	OriginalAppUserId          string            `json:"original_app_user_id"`
	OriginalApplicationVersion string            `json:"original_application_version"`
	OriginalPurchaseDate       *time.Time        `json:"original_purchase_date"`
	OtherPurchases             *NonSubscriptions `json:"other_purchases"`
	Subscriptions              map[string]any    `json:"subscriptions"`
	Entitlements               map[string]any    `json:"entitlements"`
}

func (*Subscriber) EntitlementsMap

func (s *Subscriber) EntitlementsMap() map[string]*Entitlements

func (*Subscriber) SubscriptionsMap

func (s *Subscriber) SubscriptionsMap() map[string]*Subscriptions

type SubscriberDeleteResponse

type SubscriberDeleteResponse struct {
	AppUserId string `json:"app_user_id,omitempty"`
	Deleted   bool   `json:"deleted,omitempty"`
}

type SubscriberResponse

type SubscriberResponse struct {
	RequestDate   *time.Time  `json:"request_date,omitempty"`
	RequestDateMs int64       `json:"request_date_ms,omitempty"`
	Subscriber    *Subscriber `json:"subscriber,omitempty"`
}

func (*SubscriberResponse) IsExpiredEntitlement

func (s *SubscriberResponse) IsExpiredEntitlement(entitlement string) bool

type Subscriptions

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

type WebHookCallback

type WebHookCallback func(resp *WebHookResponse) error

type WebHookEvent

type WebHookEvent struct {
	//Initial Purchase
	Id               string `json:"id,omitempty"`
	Type             string `json:"type,omitempty"`
	Store            string `json:"store,omitempty"`
	Environment      string `json:"environment,omitempty"`
	EventTimestampMs int64  `json:"event_timestamp_ms,omitempty"`

	ProductId      string `json:"product_id,omitempty"`
	PeriodType     string `json:"period_type,omitempty"`
	PurchasedAtMs  int64  `json:"purchased_at_ms,omitempty"`
	ExpirationAtMs int64  `json:"expiration_at_ms,omitempty"`

	EntitlementId            string         `json:"entitlement_id,omitempty"`
	EntitlementIds           []string       `json:"entitlement_ids,omitempty"`
	PresentedOfferingId      string         `json:"presented_offering_id,omitempty"`
	TransactionId            string         `json:"transaction_id,omitempty"`
	OriginalTransactionId    string         `json:"original_transaction_id,omitempty"`
	IsFamilyShare            bool           `json:"is_family_share,omitempty"`
	CountryCode              string         `json:"country_code,omitempty"`
	AppUserId                string         `json:"app_user_id,omitempty"`
	Aliases                  []string       `json:"aliases,omitempty"`
	OriginalAppUserId        string         `json:"original_app_user_id,omitempty"`
	Currency                 string         `json:"currency,omitempty"`
	Price                    float64        `json:"price,omitempty"`
	PriceInPurchasedCurrency float64        `json:"price_in_purchased_currency,omitempty"`
	SubscriberAttributes     map[string]any `json:"subscriber_attributes,omitempty"`

	TakehomePercentage float64 `json:"takehome_percentage,omitempty"`
	OfferCode          string  `json:"offer_code,omitempty"`

	AppId string `json:"app_id,omitempty,omitempty"`

	//Renewal
	IsTrialConversion bool `json:"is_trial_conversion,omitempty"`

	//Cancellation && Trial Cancelled
	CancelReason string `json:"cancel_reason,omitempty"`

	//Uncancellation && Subscription extended
	TaxPercentage float64 `json:"tax_percentage,omitempty"`

	//Refund && Uncancellation && Subscription extended
	CommissionPercentage float64 `json:"commission_percentage,omitempty"`

	//Subscription Paused
	AutoResumeAtMs int64 `json:"auto_resume_at_ms,omitempty"`

	//Expiration
	ExpirationReason string `json:"expiration_reason,omitempty"`

	//Transfer
	TransferredFrom []string `json:"transferred_from,omitempty"`
	TransferredTo   []string `json:"transferred_to,omitempty"`

	//Product Change
	NewProductId string `json:"new_product_id,omitempty"`
}

func (*WebHookEvent) SubscriberAttributesMap

func (w *WebHookEvent) SubscriberAttributesMap() map[string]*WebHookSubscriberAttributes

type WebHookResponse

type WebHookResponse struct {
	Event      *WebHookEvent `json:"event"`
	ApiVersion string        `json:"api_version"`
}

type WebHookSubscriberAttributes

type WebHookSubscriberAttributes struct {
	UpdatedAtMs int64  `json:"updated_at_ms,omitempty"`
	Value       string `json:"value,omitempty"`
}

Jump to

Keyboard shortcuts

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