Documentation
¶
Overview ¶
Package entitlements is a wrapper package for the entitlements service and a basic stripe integration
Index ¶
- Variables
- func GetOrganizationIDFromMetadata(metadata map[string]string) string
- func GetOrganizationNameFromMetadata(metadata map[string]string) string
- func GetOrganizationSettingsIDFromMetadata(metadata map[string]string) string
- func GetOrganizationSubscriptionIDFromMetadata(metadata map[string]string) string
- func GetUpdatedFields(props map[string]interface{}, orgCustomer *OrganizationCustomer) (params *stripe.CustomerParams)
- func WithKeys(keys map[string]string) func(*QueryBuilder)
- func WithOperator(operator string) func(*QueryBuilder)
- func WritePlansToYAML(product []Product, filename string) error
- type BillingPortalSession
- type Checkout
- type Config
- type ConfigOpts
- func WithEnabled(enabled bool) ConfigOpts
- func WithPersonalOrgSubscriptionPriceID(personalOrgSubscriptionPriceID string) ConfigOpts
- func WithPrivateStripeKey(privateStripeKey string) ConfigOpts
- func WithPublicStripeKey(publicStripeKey string) ConfigOpts
- func WithStripeBillingPortalSuccessURL(stripeBillingPortalSuccessURL string) ConfigOpts
- func WithStripeCancellationReturnURL(stripeCancellationReturnURL string) ConfigOpts
- func WithStripeWebhookSecret(stripeWebhookSecret string) ConfigOpts
- func WithStripeWebhookURL(stripeWebhookURL string) ConfigOpts
- func WithTrialSubscriptionPriceID(trialSubscriptionPriceID string) ConfigOpts
- type ContactInfo
- 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) CancellationBillingPortalSession(subsID, custID string) (*BillingPortalSession, error)
- func (sc *StripeClient) CreateBillingPortalPaymentMethods(subsID, custID string) (*BillingPortalSession, error)
- func (sc *StripeClient) CreateBillingPortalUpdateSession(subsID, custID string) (*Checkout, error)
- func (sc *StripeClient) CreateCustomer(c *OrganizationCustomer) (*stripe.Customer, error)
- func (sc *StripeClient) CreatePersonalOrgFreeTierSubs(customerID string) (*Subscription, error)
- func (sc *StripeClient) CreateSubscription(params *stripe.SubscriptionParams) (*stripe.Subscription, error)
- func (sc *StripeClient) CreateTrialSubscription(cust *stripe.Customer) (*Subscription, error)
- func (sc *StripeClient) DeleteCustomer(id string) error
- func (sc *StripeClient) FindOrCreateCustomer(ctx context.Context, o *OrganizationCustomer) error
- func (sc *StripeClient) GetCustomerByStripeID(ctx context.Context, customerID string) (*stripe.Customer, error)
- func (sc *StripeClient) GetPrices() []Price
- func (sc *StripeClient) GetProductByID(id string) (*stripe.Product, error)
- 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) MapStripeSubscription(subs *stripe.Subscription) *Subscription
- 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") // ErrMissingAPIKey is returned when the API key is missing ErrMissingAPIKey = errors.New("missing API key") )
Functions ¶
func GetOrganizationIDFromMetadata ¶ added in v0.7.4
GetOrganizationIDFromMetadata gets the organization ID from the metadata if it exists, otherwise returns an empty string
func GetOrganizationNameFromMetadata ¶ added in v0.7.4
GetOrganizationNameFromMetadata gets the organization name from the metadata if it exists, otherwise returns an empty string
func GetOrganizationSettingsIDFromMetadata ¶ added in v0.7.4
GetOrganizationSettingsIDFromMetadata gets the organization settings ID from the metadata if it exists, otherwise returns an empty string
func GetOrganizationSubscriptionIDFromMetadata ¶ added in v0.7.4
GetOrganizationSubscriptionIDFromMetadata gets the organization subscription ID from the metadata if it exists, otherwise returns an empty string
func GetUpdatedFields ¶ added in v0.7.4
func GetUpdatedFields(props map[string]interface{}, orgCustomer *OrganizationCustomer) (params *stripe.CustomerParams)
GetUpdatedFields 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 BillingPortalSession ¶ added in v0.7.4
type BillingPortalSession struct {
ManageSubscription string `json:"manage_subscription"`
PaymentMethods string `json:"payment_methods"`
Cancellation string `json:"cancellation"`
HomePage string `json:"home_page"`
}
BillingPortalSession holds the billing portal session 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"`
// PersonalOrgSubscriptionPriceID is the price ID for the personal org subscription
PersonalOrgSubscriptionPriceID string `json:"personalOrgSubscriptionPriceID" koanf:"personalOrgSubscriptionPriceID" default:"price_1QycPyBvxky1R7Svz0gOWnNh"`
// 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"`
StripeCancellationReturnURL string `` /* 163-byte string literal not displayed */
}
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 WithPersonalOrgSubscriptionPriceID ¶ added in v0.7.3
func WithPersonalOrgSubscriptionPriceID(personalOrgSubscriptionPriceID string) ConfigOpts
WithPersonalOrgSubscriptionPriceID sets the personal org subscription price ID
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 WithStripeCancellationReturnURL ¶ added in v0.7.4
func WithStripeCancellationReturnURL(stripeCancellationReturnURL string) ConfigOpts
WithStripeCancellationReturnURL sets the stripe cancellation return 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 ContactInfo ¶ added in v0.6.5
type ContactInfo struct {
Email string `json:"email"`
Phone string `json:"phone"`
City *string `form:"city"`
Country *string `form:"country"`
Line1 *string `form:"line1"`
Line2 *string `form:"line2"`
PostalCode *string `form:"postal_code"`
State *string `form:"state"`
}
ContactInfo holds the contact information for the organization
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"`
Metadata map[string]string
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"`
OrganizationName string `json:"organization_name"`
PersonalOrg bool `json:"personal_org"`
OrganizationSubscriptionID string `json:"organization_subscription_id"`
StripeSubscriptionID string `json:"stripe_subscription_id"`
PaymentMethodAdded bool `json:"payment_method_added"`
Features []string
FeatureNames []string
Subscription
ContactInfo
}
OrganizationCustomer is a struct which holds both internal organization infos and external stripe infos
func MapStripeCustomer ¶ added in v0.7.4
func MapStripeCustomer(c *stripe.Customer) *OrganizationCustomer
MapStripeCustomer maps a stripe customer to an organization customer this is used to convert the stripe customer object to our internal customer object we use the metadata to store the organization ID, settings ID, and subscription ID
func (*OrganizationCustomer) MapToStripeCustomer ¶ added in v0.5.0
func (o *OrganizationCustomer) MapToStripeCustomer() *stripe.CustomerParams
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"`
Currency string `json:"currency" yaml:"currency"`
ProductID string `json:"product_id" yaml:"-"`
ProductName string `json:"product_name" yaml:"product_name"`
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
// config is the configuration for the Stripe client
Config Config
// contains filtered or unexported fields
}
StripeClient is a client for the Stripe API
func NewStripeClient ¶
func NewStripeClient(opts ...StripeOptions) (*StripeClient, error)
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) CancellationBillingPortalSession ¶ added in v0.7.4
func (sc *StripeClient) CancellationBillingPortalSession(subsID, custID string) (*BillingPortalSession, error)
CreateBillingPortalPaymentMethods generates a session in stripe's billing portal which allows the customer to add / update payment methods
func (*StripeClient) CreateBillingPortalPaymentMethods ¶ added in v0.7.4
func (sc *StripeClient) CreateBillingPortalPaymentMethods(subsID, custID string) (*BillingPortalSession, error)
CreateBillingPortalPaymentMethods generates a session in stripe's billing portal which allows the customer to add / update payment methods
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) CreatePersonalOrgFreeTierSubs ¶ added in v0.7.3
func (sc *StripeClient) CreatePersonalOrgFreeTierSubs(customerID string) (*Subscription, error)
CreatePersonalOrgFreeTierSubs creates a subscription with the configured $0 price used for personal organizations only
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(cust *stripe.Customer) (*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 by ID from stripe
func (*StripeClient) FindOrCreateCustomer ¶ added in v0.6.7
func (sc *StripeClient) FindOrCreateCustomer(ctx context.Context, o *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) GetProductByID ¶ added in v0.6.7
func (sc *StripeClient) GetProductByID(id string) (*stripe.Product, error)
GetProductByID gets a product by ID
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) MapStripeSubscription ¶ added in v0.7.4
func (sc *StripeClient) MapStripeSubscription(subs *stripe.Subscription) *Subscription
MapStripeSubscription maps a stripe.Subscription to a "internal" subscription struct
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 in stripe with the provided params and ID
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 WithBackends ¶ added in v0.7.4
func WithBackends(backends *stripe.Backends) StripeOptions
WithBackends sets the backends 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"`
ProductID string `json:"product_id" yaml:"product_id"`
PriceID 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
Metadata map[string]string
}
Subscription is the recurring context that holds the payment information