Documentation ¶
Overview ¶
Package entitlements is a wrapper package for the entitlements service and a basic stripe integration
Index ¶
- Variables
- func CheckForBillingUpdate(props map[string]interface{}, stripeCustomer *OrganizationCustomer) (params *stripe.CustomerParams, hasUpdate bool)
- func WithKeys(keys map[string]string) func(*QueryBuilder)
- func WithOperator(operator string) func(*QueryBuilder)
- func WritePlansToYAML(product []Product, filename string) error
- type Checkout
- type Config
- type ConfigOpts
- func WithEnabled(enabled bool) ConfigOpts
- func WithPrivateStripeKey(privateStripeKey string) ConfigOpts
- func WithPublicStripeKey(publicStripeKey string) ConfigOpts
- func WithStripeBillingPortalSuccessURL(stripeBillingPortalSuccessURL string) ConfigOpts
- func WithStripeWebhookSecret(stripeWebhookSecret string) ConfigOpts
- func WithStripeWebhookURL(stripeWebhookURL string) ConfigOpts
- func WithTrialSubscriptionPriceID(trialSubscriptionPriceID string) ConfigOpts
- type Customer
- type Feature
- type OrganizationCustomer
- type Plan
- type Price
- type Product
- type ProductFeature
- type QueryBuilder
- type StripeClient
- func (sc *StripeClient) CancelSubscription(id string, params *stripe.SubscriptionCancelParams) (*stripe.Subscription, error)
- func (sc *StripeClient) CreateBillingPortalUpdateSession(subsID, custID string) (Checkout, error)
- func (sc *StripeClient) CreateCustomer(c *OrganizationCustomer) (*stripe.Customer, error)
- func (sc *StripeClient) CreateSubscription(params *stripe.SubscriptionParams) (*stripe.Subscription, error)
- func (sc *StripeClient) CreateTrialSubscription(customerID string) (*Subscription, error)
- func (sc *StripeClient) DeleteCustomer(id string) error
- func (sc *StripeClient) FindorCreateCustomer(ctx context.Context, o *OrganizationCustomer) (*OrganizationCustomer, error)
- func (sc *StripeClient) GetCustomerByStripeID(ctx context.Context, customerID string) (*stripe.Customer, error)
- func (sc *StripeClient) GetPrices() []Price
- func (sc *StripeClient) GetProductFeatures(productID string) []ProductFeature
- func (sc *StripeClient) GetProducts() []Product
- func (sc *StripeClient) GetSubscriptionByID(id string) (*stripe.Subscription, error)
- func (sc *StripeClient) ListOrCreateSubscriptions(customerID string) (*Subscription, error)
- func (sc *StripeClient) SearchCustomers(ctx context.Context, query string) (customers []*stripe.Customer, err error)
- func (sc *StripeClient) UpdateCustomer(id string, params *stripe.CustomerParams) (*stripe.Customer, error)
- func (sc *StripeClient) UpdateSubscription(id string, params *stripe.SubscriptionParams) (*stripe.Subscription, error)
- type StripeOptions
- type Subs
- type Subscription
Constants ¶
This section is empty.
Variables ¶
var ( // ErrFoundMultipleCustomers is returned when multiple customers are found ErrFoundMultipleCustomers = errors.New("found multiple customers with the same name") // ErrCustomerNotFound is returned when a customer is not found ErrCustomerNotFound = errors.New("customer not found") // ErrCustomerLookupFailed is returned when a customer lookup fails ErrCustomerLookupFailed = errors.New("failed to lookup customer") // ErrCustomerIDRequired is returned when a customer ID is required ErrCustomerIDRequired = errors.New("customer ID is required") )
Functions ¶
func CheckForBillingUpdate ¶ added in v0.5.0
func CheckForBillingUpdate(props map[string]interface{}, stripeCustomer *OrganizationCustomer) (params *stripe.CustomerParams, hasUpdate bool)
checkForBillingUpdate checks for updates to billing information in the properties and returns a stripe.CustomerParams object with the updated information and a boolean indicating whether there are updates
func WithKeys ¶ added in v0.5.0
func WithKeys(keys map[string]string) func(*QueryBuilder)
WithKeys sets the keys for the query builder
func WithOperator ¶ added in v0.5.0
func WithOperator(operator string) func(*QueryBuilder)
WithOperator sets the operator for the query builder (AND or OR)
func WritePlansToYAML ¶
WritePlansToYAML writes the []Product information into a YAML file.
Types ¶
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"` // StripeWebhookURL is the URL for the stripe webhook StripeWebhookURL string `json:"stripeWebhookURL" koanf:"stripeWebhookURL" default:"https://api.openlane.com/v1/stripe/webhook"` // StripeBillingPortalSuccessURL StripeBillingPortalSuccessURL string `json:"stripeBillingPortalSuccessURL" koanf:"stripeBillingPortalSuccessURL" default:"https://console.openlane.com/billing"` }
func NewConfig ¶ added in v0.5.0
func NewConfig(opts ...ConfigOpts) *Config
NewConfig creates a new entitlements config
type ConfigOpts ¶ added in v0.5.0
type ConfigOpts func(*Config)
func WithEnabled ¶ added in v0.5.0
func WithEnabled(enabled bool) ConfigOpts
WithEnabled sets the enabled field
func WithPrivateStripeKey ¶ added in v0.5.0
func WithPrivateStripeKey(privateStripeKey string) ConfigOpts
WithPrivateStripeKey sets the private stripe key
func WithPublicStripeKey ¶ added in v0.5.0
func WithPublicStripeKey(publicStripeKey string) ConfigOpts
WithPublicStripeKey sets the public stripe key
func WithStripeBillingPortalSuccessURL ¶ added in v0.5.0
func WithStripeBillingPortalSuccessURL(stripeBillingPortalSuccessURL string) ConfigOpts
WithStripeBillingPortalSuccessURL sets the stripe billing portal success URL
func WithStripeWebhookSecret ¶ added in v0.5.0
func WithStripeWebhookSecret(stripeWebhookSecret string) ConfigOpts
WithStripeWebhookSecret sets the stripe webhook secret
func WithStripeWebhookURL ¶ added in v0.5.0
func WithStripeWebhookURL(stripeWebhookURL string) ConfigOpts
WithStripeWebhookURL sets the stripe webhook URL
func WithTrialSubscriptionPriceID ¶
func WithTrialSubscriptionPriceID(trialSubscriptionPriceID string) ConfigOpts
WithTrialSubscriptionPriceID sets the trial subscription price ID
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 }
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"` }
Feature are part of a product
type OrganizationCustomer ¶ added in v0.5.0
type OrganizationCustomer struct { OrganizationID string `json:"organization_id"` OrganizationSettingsID string `json:"organization_settings_id"` StripeCustomerID string `json:"stripe_customer_id"` BillingEmail string `json:"billing_email"` BillingPhone string `json:"billing_phone"` OrganizationName string `json:"organization_name"` Features []string Subscription }
OrganizationCustomer is a struct which holds both internal organization infos and external stripe infos
func (*OrganizationCustomer) MapToStripeCustomer ¶ added in v0.5.0
func (o *OrganizationCustomer) MapToStripeCustomer() *stripe.CustomerParams
MapToStripeCustomer maps the OrganizationCustomer to a stripe customer for more easy querying
func (*OrganizationCustomer) Validate ¶ added in v0.5.0
func (o *OrganizationCustomer) Validate() error
Validate checks if the OrganizationCustomer contains necessary fields
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:"-"` 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,omitempty" yaml:"description,omitempty"` 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 QueryBuilder ¶ added in v0.5.0
type QueryBuilder struct {
// contains filtered or unexported fields
}
QueryBuilder is a struct that holds the query builder
func NewQueryBuilder ¶ added in v0.5.0
func NewQueryBuilder(options ...func(*QueryBuilder)) *QueryBuilder
NewQueryBuilder creates a new query builder with included options
func (*QueryBuilder) BuildQuery ¶ added in v0.5.0
func (qb *QueryBuilder) BuildQuery() []string
BuildQuery builds the query from the keys
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 // 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)
CreateBillingPortalUpdateSession generates an update session in stripe's billing portal which displays the customers current subscription tier and allows them to upgrade or downgrade
func (*StripeClient) CreateCustomer ¶
func (sc *StripeClient) CreateCustomer(c *OrganizationCustomer) (*stripe.Customer, error)
CreateCustomer creates a customer leveraging the openlane organization ID as the organization name, and the email provided as the billing email we assume that the billing email will be changed, so lookups are performed by the organization ID
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) FindorCreateCustomer ¶ added in v0.5.0
func (sc *StripeClient) FindorCreateCustomer(ctx context.Context, o *OrganizationCustomer) (*OrganizationCustomer, error)
FindorCreateCustomer attempts to lookup a customer by the organization ID which is set in both the name field attribute as well as in the object metadata field
func (*StripeClient) GetCustomerByStripeID ¶ added in v0.5.0
func (sc *StripeClient) GetCustomerByStripeID(ctx context.Context, customerID string) (*stripe.Customer, error)
GetCustomerByStripeID 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) SearchCustomers ¶ added in v0.5.0
func (sc *StripeClient) SearchCustomers(ctx context.Context, query string) (customers []*stripe.Customer, err error)
SearchCustomers searches for customers with a structured stripe query as input leverage QueryBuilder to construct more complex queries, otherwise see: https://docs.stripe.com/search#search-query-language
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 WithConfig ¶ added in v0.5.0
func WithConfig(config Config) StripeOptions
WithConfig sets the config for the Stripe client
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