revcatgo

package module
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 5 Imported by: 0

README

revcatgo

GoDev

Run test

A helper library for integrating server-side apps with the RevenueCat webhook service.

go get "github.com/iktakahiro/revcatgo@v1.1.0"

Receiving webhooks

func bind(w http.ResponseWriter, r *http.Request) error {
    var webhookEvent revcatgo.WebhookEvent

    err := json.NewDecoder(r.Body).Decode(&webhookEvent)
    if err != nil {
        return err
    }
    fmt.Println(webhookEvent.Type) // e.g. "INITIAL_PURCHASE"
    return nil
}

RevenueCat webhooks specifications

Refer to the official documentation:

Documentation

Index

Constants

View Source
const (
	CancelReasonUnsubscribe        = "UNSUBSCRIBE"
	CancelReasonBillingError       = "BILLING_ERROR"
	CancelReasonDeveloperInitiated = "DEVELOPER_INITIATED"
	CancelReasonPriceIncrease      = "PRICE_INCREASE"
	CancelReasonCustomerSupport    = "CUSTOMER_SUPPORT"
	CancelReasonSubscriptionPaused = "SUBSCRIPTION_PAUSED"
	CancelReasonUnknown            = "UNKNOWN"
)
View Source
const (
	EnvironmentSandbox    = "SANDBOX"
	EnvironmentProduction = "PRODUCTION"
)
View Source
const (
	EventTypeTest                      = "TEST"
	EventTypeInitialPurchase           = "INITIAL_PURCHASE"
	EventTypeNonRenewingPurchase       = "NON_RENEWING_PURCHASE"
	EventTypeRenewal                   = "RENEWAL"
	EventTypeProductChange             = "PRODUCT_CHANGE"
	EventTypeCancellation              = "CANCELLATION"
	EventTypeUnCancellation            = "UNCANCELLATION"
	EventTypeBillingIssue              = "BILLING_ISSUE"
	EventTypeSubscriberAlias           = "SUBSCRIBER_ALIAS"
	EventTypeSubscriptionPaused        = "SUBSCRIPTION_PAUSED"
	EventTypeTransfer                  = "TRANSFER"
	EventTypeExpiration                = "EXPIRATION"
	EventTypeSubscriptionExtended      = "SUBSCRIPTION_EXTENDED"
	EventTypeTemporaryEntitlementGrant = "TEMPORARY_ENTITLEMENT_GRANT"
)
View Source
const (
	PeriodTypeTrial       = "TRIAL"
	PeriodTypeIntro       = "INTRO"
	PeriodTypeNormal      = "NORMAL"
	PeriodTypePromotional = "PROMOTIONAL"
)
View Source
const (
	StoreAmazon      = "AMAZON"
	StorePlayStore   = "PLAY_STORE"
	StoreAppStore    = "APP_STORE"
	StoreStripe      = "STRIPE"
	StoreMacAppStore = "MAC_APP_STORE"
	StorePromotional = "PROMOTIONAL"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Entitlement added in v0.3.1

type Entitlement struct {
	ProductIdentifier      string    `json:"product_identifier"`
	ExpiresDate            time.Time `json:"expires_date"`
	GracePeriodExpiresDate null.Time `json:"grace_period_expires_date"`
	PurchaseDate           time.Time `json:"purchase_dat"`
}

type Event

type Event struct {
	ID                       string               `json:"id"`
	Type                     eventType            `json:"type"`
	EventTimestampAt         milliseconds         `json:"event_timestamp_ms"`
	AppUserID                string               `json:"app_user_id"`
	Aliases                  []string             `json:"aliases"`
	OriginalAppUserID        string               `json:"original_app_user_id"`
	ProductID                string               `json:"product_id"`
	EntitlementIDs           []string             `json:"entitlement_ids"`
	PeriodType               periodType           `json:"period_type"`
	PurchasedAt              milliseconds         `json:"purchased_at_ms"`
	GracePeriodExpirationAt  milliseconds         `json:"grace_period_expiration_at_ms"`
	ExpirationAt             milliseconds         `json:"expiration_at_ms"`
	AutoResumeAt             milliseconds         `json:"auto_resume_at_ms"`
	Store                    store                `json:"store"`
	Environment              environment          `json:"environment"`
	IsTrialConversion        null.Bool            `json:"is_trial_conversion"`
	CancelReason             cancelReason         `json:"cancel_reason"`
	ExpirationReason         cancelReason         `json:"expiration_reason"`
	NewProductID             string               `json:"new_product_id"`
	PresentedOfferingID      string               `json:"presented_offering_id"`
	Price                    price                `json:"price"`
	Currency                 null.String          `json:"currency"`
	PriceInPurchasedCurrency float32              `json:"price_in_purchased_currency"`
	TakeHomePercentage       float32              `json:"takehome_percentage"`
	CommissionPercentage     float32              `json:"commission_percentage"`
	SubscriberAttributes     subscriberAttributes `json:"subscriber_attributes"`
	TransactionID            string               `json:"transaction_id"`
	OriginalTransactionID    string               `json:"original_transaction_id"`
	IsFamilyShare            bool                 `json:"is_family_share"`
	TransferredFrom          []string             `json:"transferred_from"`
	TransferredTo            []string             `json:"transferred_to"`
	CountryCode              string               `json:"country_code"`
	OfferCode                string               `json:"offer_code"`
}

Event represents an Event of RevenueCat webhook

func (*Event) GetAllRelatedUserID added in v0.4.0

func (e *Event) GetAllRelatedUserID() []string

GetAllRelatedUserID returns a unique id list of AppUserID, OriginalAppUserID, and Aliases.

func (*Event) HasEntitlementID added in v0.2.6

func (e *Event) HasEntitlementID(id string) bool

HasEntitlementID checks whether the id exists or not.

func (*Event) IsExpired added in v0.2.0

func (e *Event) IsExpired(grace time.Duration, base *time.Time) bool

IsExpired checks whether a subscription is expired or not.

type NonSubscription added in v0.3.1

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

type Subscriber added in v0.3.1

type Subscriber struct {
	Entitlements      map[string]Entitlement       `json:"entitlements"`
	FirstSeen         time.Time                    `json:"first_seen"`
	LastSeen          time.Time                    `json:"last_seen"`
	ManagementURL     null.String                  `json:"management_url"`
	OriginalAppUserID null.String                  `json:"original_app_user_id"`
	Subscriptions     map[string]Subscription      `json:"subscriptions"`
	NonSubscription   map[string][]NonSubscription `json:"non_subscriptions"`
}

type SubscriberResponse added in v0.3.1

type SubscriberResponse struct {
	RequestDateAt milliseconds `json:"request_date_ms"`
	Subscriber    Subscriber   `json:"subscriber"`
}

type Subscription added in v0.3.1

type Subscription struct {
	ExpiresDate            time.Time  `json:"expires_date"`
	GracePeriodExpiresDate null.Time  `json:"grace_period_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  null.Time  `json:"unsubscribe_detected_at"`
	BillingIssueDetectedAt null.Time  `json:"billing_issue_detected_at"`
}

type WebhookEvent

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

WebhookEvent represents a request body of RevenueCat webhook. https://docs.revenuecat.com/docs/webhooks

Jump to

Keyboard shortcuts

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