entitlements

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package entitlements is a wrapper package for the entitlements service and a basic stripe integration

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WritePlansToYAML

func WritePlansToYAML(product []Product, filename string) error

WritePlansToYAML writes the []Product information into a YAML file.

Types

type Checkout

type Checkout struct {
	ID  string `json:"id"`
	URL string `json:"url"`
}

Checkout holds the checkout information

type Config

type Config struct {
	// Enabled determines if the entitlements service is enabled
	Enabled bool `json:"enabled" koanf:"enabled" default:"false"`
	// PublicStripeKey is the key for the stripe service
	PublicStripeKey string `json:"publicStripeKey" koanf:"publicStripeKey" default:""`
	// PrivateStripeKey is the key for the stripe service
	PrivateStripeKey string `json:"privateStripeKey" koanf:"privateStripeKey" default:""`
	// StripeWebhookSecret is the secret for the stripe service
	StripeWebhookSecret string `json:"stripeWebhookSecret" koanf:"stripeWebhookSecret" default:""`
	// TrialSubscriptionPriceID is the price ID for the trial subscription
	TrialSubscriptionPriceID string `json:"trialSubscriptionPriceID" koanf:"trialSubscriptionPriceID" default:"price_1QKLyeBvxky1R7SvaZYGWyQb"`
}

type Customer

type Customer struct {
	ID             string `json:"customer_id" yaml:"customer_id"`
	Email          string `json:"email" yaml:"email"`
	Phone          string `json:"phone" yaml:"phone"`
	Address        string `json:"address" yaml:"address"`
	Plans          []Plan `json:"plans" yaml:"plans"`
	StripeParams   *stripe.CustomerParams
	StripeCustomer []stripe.Customer
}

NOTE: these are incomplete and are only meant to be used as a reference currently - they will be updated as the project progresses Customer holds the customer information

type Feature

type Feature struct {
	ID               string `json:"id" yaml:"id"`
	Name             string `json:"name" yaml:"name"`
	Lookupkey        string `json:"lookupkey" yaml:"lookupkey"`
	ProductFeatureID string `json:"product_feature_id" yaml:"product_feature_id"`
}

Feature are part of a product

type Plan

type Plan struct {
	ID                 string `json:"plan_id" yaml:"plan_id"`
	Product            string `json:"product_id" yaml:"product_id"`
	Price              string `json:"price_id" yaml:"price_id"`
	StartDate          int64  `json:"start_date" yaml:"start_date"`
	EndDate            int64  `json:"end_date" yaml:"end_date"`
	StripeParams       *stripe.SubscriptionParams
	StripeSubscription []stripe.Subscription
	Products           []Product
	Features           []Feature
	TrialEnd           int64
	Status             string
}

Plan is the recurring context that holds the payment information

type Price

type Price struct {
	ID           string              `json:"price_id" yaml:"price_id"`
	Price        float64             `json:"price" yaml:"price"`
	ProductID    string              `json:"product_id" yaml:"product_id"`
	Interval     string              `json:"interval" yaml:"interval"`
	StripeParams *stripe.PriceParams `json:"stripe_params,omitempty" yaml:"stripe_params,omitempty"`
	StripePrice  []stripe.Price      `json:"stripe_price,omitempty" yaml:"stripe_price,omitempty"`
}

Price holds stripe price params and the associated Product

type Product

type Product struct {
	ID            string                `json:"product_id" yaml:"product_id"`
	Name          string                `json:"name" yaml:"name"`
	Description   string                `json:"description" yaml:"description"`
	Features      []Feature             `json:"features" yaml:"features"`
	Prices        []Price               `json:"prices" yaml:"prices"`
	StripeParams  *stripe.ProductParams `json:"stripe_params,omitempty" yaml:"stripe_params,omitempty"`
	StripeProduct []stripe.Product      `json:"stripe_product,omitempty" yaml:"stripe_product,omitempty"`
}

Product holds what we'd more commply call a "tier"

type ProductFeature

type ProductFeature struct {
	ProductFeatureID string `json:"product_feature_id" yaml:"product_feature_id"`
	FeatureID        string `json:"feature_id" yaml:"feature_id"`
	ProductID        string `json:"product_id" yaml:"product_id"`
	Name             string `json:"name" yaml:"name"`
	Lookupkey        string `json:"lookupkey" yaml:"lookupkey"`
}

type StripeClient

type StripeClient struct {
	// Client is the Stripe client and is used for accessing all subsequent stripe objects, e.g. products, prices, etc.
	Client *client.API

	// TODO[MKA] cleanup these fields and determine if an interface is easier to use than internal struct mapping and how to mock out the use of the stripe client
	// Customer is a ref to a generic Customer struct used to wrap Stripe customer and Openlane Organizations (typically)
	Cust Customer
	// Plans are a nomenclature for the recurring context that holds the payment information and is synonymous with Stripe subscriptions
	Plan Plan
	// Product is a stripe product; also know as a "tier"
	Product Product
	// Price holds the interval and amount to be billed
	Price Price
	// contains filtered or unexported fields
}

StripeClient is a client for the Stripe API

func NewStripeClient

func NewStripeClient(opts ...StripeOptions) *StripeClient

NewStripeClient creates a new Stripe client

func (*StripeClient) CancelSubscription

func (sc *StripeClient) CancelSubscription(id string, params *stripe.SubscriptionCancelParams) (*stripe.Subscription, error)

CancelSubscription cancels a subscription

func (*StripeClient) CreateBillingPortalUpdateSession

func (sc *StripeClient) CreateBillingPortalUpdateSession(subsID, custID string) (Checkout, error)

TODO determine what return URL is needed (if any) and move to a more accessible location vs. hardcoded CreateCheckoutSession creates a new checkout session for the customer portal and given product and price

func (*StripeClient) CreateCustomer

func (sc *StripeClient) CreateCustomer(email string) (*stripe.Customer, error)

CreateCustomer creates a new customer

func (*StripeClient) CreateSubscription

func (sc *StripeClient) CreateSubscription(params *stripe.SubscriptionParams) (*stripe.Subscription, error)

CreateSubscription creates a new subscription

func (*StripeClient) CreateTrialSubscription

func (sc *StripeClient) CreateTrialSubscription(customerID string) (*Subscription, error)

CreateTrialSubscription creates a trial subscription with the configured price

func (*StripeClient) DeleteCustomer

func (sc *StripeClient) DeleteCustomer(id string) error

DeleteCustomer deletes a customer

func (*StripeClient) GetCustomerByID

func (sc *StripeClient) GetCustomerByID(id string) (*stripe.Customer, error)

GetCustomerByID gets a customer by ID

func (*StripeClient) GetPrices

func (sc *StripeClient) GetPrices() []Price

GetPrices retrieves all prices from stripe which are active and maps them into a []Price struct

func (*StripeClient) GetProductFeatures

func (sc *StripeClient) GetProductFeatures(productID string) []ProductFeature

GetProductFeatures retrieves all product features from stripe which are active and maps them into a []ProductFeature struct

func (*StripeClient) GetProducts

func (sc *StripeClient) GetProducts() []Product

GetProducts retrieves all products from stripe which are active

func (*StripeClient) GetSubscriptionByID

func (sc *StripeClient) GetSubscriptionByID(id string) (*stripe.Subscription, error)

GetSubscriptionByID gets a subscription by ID

func (*StripeClient) ListOrCreateSubscriptions

func (sc *StripeClient) ListOrCreateSubscriptions(customerID string) (*Subscription, error)

ListStripeSubscriptions lists stripe subscriptions by customer

func (*StripeClient) UpdateCustomer

func (sc *StripeClient) UpdateCustomer(id string, params *stripe.CustomerParams) (*stripe.Customer, error)

UpdateCustomer updates a customer

func (*StripeClient) UpdateSubscription

func (sc *StripeClient) UpdateSubscription(id string, params *stripe.SubscriptionParams) (*stripe.Subscription, error)

UpdateSubscription updates a subscription

type StripeOptions

type StripeOptions func(*StripeClient)

StripeOptions is a type for setting options on the Stripe client

func WithAPIKey

func WithAPIKey(apiKey string) StripeOptions

WithAPIKey sets the API key for the Stripe client

func WithTrialSubscriptionPriceID

func WithTrialSubscriptionPriceID(trialSubscriptionPriceID string) StripeOptions

WithTrialSubscriptionPriceID sets the trial subscription price ID for the Stripe client

func WithWebhookSecret

func WithWebhookSecret(webhookSecret string) StripeOptions

WithWebhookSecret sets the webhook secret for the Stripe client

type Subs

type Subs struct {
	SubsID string
	Prices []Price
}

type Subscription

type Subscription struct {
	ID                 string `json:"plan_id" yaml:"plan_id"`
	Product            string `json:"product_id" yaml:"product_id"`
	Price              string `json:"price_id" yaml:"price_id"`
	StartDate          int64  `json:"start_date" yaml:"start_date"`
	EndDate            int64  `json:"end_date" yaml:"end_date"`
	StripeParams       *stripe.SubscriptionParams
	StripeSubscription []stripe.Subscription
	StripeProduct      []stripe.Product
	StripeFeature      []stripe.ProductFeature
	Products           []Product
	Features           []Feature
	Prices             []Price
	TrialEnd           int64
	Status             string
	StripeCustomerID   string
	OrganizationID     string
	DaysUntilDue       int64
}

Plan is the recurring context that holds the payment information

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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