Documentation
¶
Index ¶
- Constants
- Variables
- type CheckoutRequest
- type Customer
- type Migration
- type Plan
- type Price
- type PricingSchedule
- type Repo
- func (r *Repo) AddMigrations(migrations []Migration)
- func (r *Repo) AddSubscriptionUser(su *SubscriptionUser) error
- func (r *Repo) CountSubscriptionUsers(subID int64) (int64, error)
- func (r *Repo) Destroy(ctx context.Context) error
- func (r *Repo) GetCustomerByEmail(email string) (*Customer, error)
- func (r *Repo) GetCustomerByID(id int64) (*Customer, error)
- func (r *Repo) GetCustomerByProvider(provider, providerID string) (*Customer, error)
- func (r *Repo) GetPlanByID(id int64) (*Plan, error)
- func (r *Repo) GetPlanByName(name string) (*Plan, error)
- func (r *Repo) GetPlanByPriceID(priceID int64) (*Plan, error)
- func (r *Repo) GetPlanByProviderID(provider, providerID string) (*Plan, error)
- func (r *Repo) GetPlanBySubscriptionID(subID int64) (*Plan, error)
- func (r *Repo) GetPlansByUsername(username string) (plans []Plan, err error)
- func (r *Repo) GetPriceByID(priceID int64) (*Price, error)
- func (r *Repo) GetPriceByProvider(provider, providerID string) (*Price, error)
- func (r *Repo) GetSubscriptionByID(id int64) (*Subscription, error)
- func (r *Repo) GetSubscriptionByProvider(provider, providerID string) (*Subscription, error)
- func (r *Repo) Init() error
- func (r *Repo) ListActivePlans() ([]Plan, error)
- func (r *Repo) ListAllCustomers() ([]Customer, error)
- func (r *Repo) ListAllPrices() ([]Price, error)
- func (r *Repo) ListAllSubscriptions() ([]Subscription, error)
- func (r *Repo) ListAllWebhookEvents() ([]WebhookEvent, error)
- func (r *Repo) ListPlans() ([]Plan, error)
- func (r *Repo) ListPricesByPlanID(planID int64) ([]Price, error)
- func (r *Repo) ListSubscriptionsByCustomerID(customerID int64) ([]Subscription, error)
- func (r *Repo) ListSubscriptionsByPlanID(planID int64) ([]Subscription, error)
- func (r *Repo) ListSubscriptionsByUsername(username string) ([]Subscription, error)
- func (r *Repo) ListUsernames(subID int64) ([]string, error)
- func (e *Repo) OnCustomerAdded(cb func(*Customer))
- func (e *Repo) OnCustomerRemoved(cb func(*Customer))
- func (e *Repo) OnCustomerUpdated(cb func(*Customer, *Customer))
- func (e *Repo) OnPlanAdded(cb func(*Plan))
- func (e *Repo) OnPlanRemoved(cb func(*Plan))
- func (e *Repo) OnPlanUpdated(cb func(*Plan, *Plan))
- func (e *Repo) OnPriceAdded(cb func(*Price))
- func (e *Repo) OnPriceRemoved(cb func(*Price))
- func (e *Repo) OnPriceUpdated(cb func(*Price, *Price))
- func (e *Repo) OnSubscriptionAdded(cb func(*Subscription))
- func (e *Repo) OnSubscriptionRemoved(cb func(*Subscription))
- func (e *Repo) OnSubscriptionUpdated(cb func(*Subscription, *Subscription))
- func (r *Repo) RemoveSubscriptionUser(su *SubscriptionUser) error
- func (r *Repo) SetMigrationsTable(table string)
- func (r *Repo) SetSchema(schema string)
- type StripeConfig
- type StripeProvider
- func (s *StripeProvider) AddCustomer(c *Customer) error
- func (s *StripeProvider) AddPlan(p *Plan) error
- func (s *StripeProvider) AddPrice(p *Price) error
- func (s *StripeProvider) Checkout(request *CheckoutRequest) (url string, err error)
- func (e StripeProvider) OnCustomerAdded(cb func(*Customer))
- func (e StripeProvider) OnCustomerRemoved(cb func(*Customer))
- func (e StripeProvider) OnCustomerUpdated(cb func(*Customer, *Customer))
- func (e StripeProvider) OnPlanAdded(cb func(*Plan))
- func (e StripeProvider) OnPlanRemoved(cb func(*Plan))
- func (e StripeProvider) OnPlanUpdated(cb func(*Plan, *Plan))
- func (e StripeProvider) OnPriceAdded(cb func(*Price))
- func (e StripeProvider) OnPriceRemoved(cb func(*Price))
- func (e StripeProvider) OnPriceUpdated(cb func(*Price, *Price))
- func (e StripeProvider) OnSubscriptionAdded(cb func(*Subscription))
- func (e StripeProvider) OnSubscriptionRemoved(cb func(*Subscription))
- func (e StripeProvider) OnSubscriptionUpdated(cb func(*Subscription, *Subscription))
- func (s *StripeProvider) RemoveCustomerByProviderID(providerID string) error
- func (s *StripeProvider) RemovePlanByProviderID(providerID string) error
- func (s *StripeProvider) Sync() error
- func (s *StripeProvider) VerifyCheckout(sessionID string) error
- func (s *StripeProvider) Webhook() http.HandlerFunc
- type Subscription
- type SubscriptionUser
- type WebhookEvent
Constants ¶
const DefaultSchema = "pay"
DefaultSchema where tables will be stored can be overriden using
const ProviderStripe = "stripe"
Variables ¶
var ( ErrSubscriptionNotFound = errors.New("subscription not found") ErrSubscriptionNotActive = errors.New("subscription not active") )
var ErrCheckoutFailed = errors.New("checkout failed")
Functions ¶
This section is empty.
Types ¶
type CheckoutRequest ¶
CheckoutRequest
type Customer ¶
type Customer struct { ID int64 // internal (to this service) ProviderID string // external providers id Provider string // the provider for this customer Name string // customers name Email string // customers email }
Customer from a provider like stripe or paypal
type Plan ¶
type Plan struct { ID int64 Name string Description string Provider string ProviderID string Active bool }
Plan that customers will subscribe to
type Price ¶
type PricingSchedule ¶
type PricingSchedule = string
const ( PricingAnnual PricingSchedule = "annual" PricingMonthly PricingSchedule = "monthly" PricingOnce PricingSchedule = "once" )
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo contains methods for storing entities within an sql database
func (*Repo) AddMigrations ¶
AddMigrations adds migrations to the execute after the base migrations
func (*Repo) AddSubscriptionUser ¶
func (r *Repo) AddSubscriptionUser(su *SubscriptionUser) error
func (*Repo) CountSubscriptionUsers ¶
func (*Repo) GetCustomerByEmail ¶
GetCustomerByEmail returns the customer with a given email
func (*Repo) GetCustomerByID ¶
GetCustomerByID returns the customer by its id field
func (*Repo) GetCustomerByProvider ¶
GetCustomerByProvider returns the customer with provider id. Provider id refers to the id given to the customer by an external provider such as stripe or paypal.
func (*Repo) GetPlanByID ¶
GetPlanByID returns the plan matching the internal id
func (*Repo) GetPlanByName ¶
GetPlanByName returns the plan with given name
func (*Repo) GetPlanByProviderID ¶
GetPlanByProvider returns the plan which matches provider and provider id
func (*Repo) GetPlanBySubscriptionID ¶
func (*Repo) GetPlansByUsername ¶
func (*Repo) GetPriceByID ¶
GetPriceByID returns the price by a given id
func (*Repo) GetPriceByProvider ¶
GetPriceByID returns the price by a given id
func (*Repo) GetSubscriptionByID ¶
func (r *Repo) GetSubscriptionByID(id int64) (*Subscription, error)
func (*Repo) GetSubscriptionByProvider ¶
func (r *Repo) GetSubscriptionByProvider(provider, providerID string) (*Subscription, error)
func (*Repo) Init ¶
Init creates the required tables and migrations for entities. The call to init is idempotent and can therefore be called many times acheiving the same result.
func (*Repo) ListActivePlans ¶
ListActivePlans returns a list of all active plans in alphabetic order
func (*Repo) ListAllCustomers ¶
ListAllCustomers returns a list of prices
func (*Repo) ListAllPrices ¶
ListAllPrices returns a list of prices
func (*Repo) ListAllSubscriptions ¶
func (r *Repo) ListAllSubscriptions() ([]Subscription, error)
func (*Repo) ListAllWebhookEvents ¶
func (r *Repo) ListAllWebhookEvents() ([]WebhookEvent, error)
ListAllWebhookEvents returns a list of all webhook events
func (*Repo) ListPricesByPlanID ¶
ListPrices returns a list of prices
func (*Repo) ListSubscriptionsByCustomerID ¶
func (r *Repo) ListSubscriptionsByCustomerID(customerID int64) ([]Subscription, error)
func (*Repo) ListSubscriptionsByPlanID ¶
func (r *Repo) ListSubscriptionsByPlanID(planID int64) ([]Subscription, error)
func (*Repo) ListSubscriptionsByUsername ¶
func (r *Repo) ListSubscriptionsByUsername(username string) ([]Subscription, error)
ListSubscriptionsByUsername returns all subscriptions that have a user with given username
func (*Repo) ListUsernames ¶
ListUsername returns a list of all usernames attached to subscription
func (*Repo) OnCustomerAdded ¶
func (e *Repo) OnCustomerAdded(cb func(*Customer))
func (*Repo) OnCustomerRemoved ¶
func (e *Repo) OnCustomerRemoved(cb func(*Customer))
func (*Repo) OnCustomerUpdated ¶
func (*Repo) OnPlanAdded ¶
func (e *Repo) OnPlanAdded(cb func(*Plan))
func (*Repo) OnPlanRemoved ¶
func (e *Repo) OnPlanRemoved(cb func(*Plan))
func (*Repo) OnPlanUpdated ¶
func (*Repo) OnPriceAdded ¶
func (e *Repo) OnPriceAdded(cb func(*Price))
func (*Repo) OnPriceRemoved ¶
func (e *Repo) OnPriceRemoved(cb func(*Price))
func (*Repo) OnPriceUpdated ¶
func (*Repo) OnSubscriptionAdded ¶
func (e *Repo) OnSubscriptionAdded(cb func(*Subscription))
func (*Repo) OnSubscriptionRemoved ¶
func (e *Repo) OnSubscriptionRemoved(cb func(*Subscription))
func (*Repo) OnSubscriptionUpdated ¶
func (e *Repo) OnSubscriptionUpdated(cb func(*Subscription, *Subscription))
func (*Repo) RemoveSubscriptionUser ¶
func (r *Repo) RemoveSubscriptionUser(su *SubscriptionUser) error
func (*Repo) SetMigrationsTable ¶
SetMigrationsTable for setting up migrations during init
type StripeConfig ¶
StripeConfig configures StripeService with necessary credentials and callbacks
type StripeProvider ¶
type StripeProvider struct { *Repo // contains filtered or unexported fields }
StripeProvider interfaces with stripe for customer, plan and subscription data
func NewStripeProvider ¶
func NewStripeProvider(config *StripeConfig) *StripeProvider
NewStripeProvider creates a provider service for interacting with stripe
func (*StripeProvider) AddCustomer ¶
func (s *StripeProvider) AddCustomer(c *Customer) error
AddCustomer directly in stripe
func (*StripeProvider) AddPlan ¶
func (s *StripeProvider) AddPlan(p *Plan) error
AddPlan directly in stripe
func (*StripeProvider) AddPrice ¶
func (s *StripeProvider) AddPrice(p *Price) error
AddPrice directly in stripe
func (*StripeProvider) Checkout ¶
func (s *StripeProvider) Checkout(request *CheckoutRequest) (url string, err error)
Checkout returns the url that a user has to visit in order to complete payment it registers the customer if it was unavailable
func (StripeProvider) OnCustomerAdded ¶
func (e StripeProvider) OnCustomerAdded(cb func(*Customer))
func (StripeProvider) OnCustomerRemoved ¶
func (e StripeProvider) OnCustomerRemoved(cb func(*Customer))
func (StripeProvider) OnCustomerUpdated ¶
func (StripeProvider) OnPlanAdded ¶
func (e StripeProvider) OnPlanAdded(cb func(*Plan))
func (StripeProvider) OnPlanRemoved ¶
func (e StripeProvider) OnPlanRemoved(cb func(*Plan))
func (StripeProvider) OnPlanUpdated ¶
func (StripeProvider) OnPriceAdded ¶
func (e StripeProvider) OnPriceAdded(cb func(*Price))
func (StripeProvider) OnPriceRemoved ¶
func (e StripeProvider) OnPriceRemoved(cb func(*Price))
func (StripeProvider) OnPriceUpdated ¶
func (StripeProvider) OnSubscriptionAdded ¶
func (e StripeProvider) OnSubscriptionAdded(cb func(*Subscription))
func (StripeProvider) OnSubscriptionRemoved ¶
func (e StripeProvider) OnSubscriptionRemoved(cb func(*Subscription))
func (StripeProvider) OnSubscriptionUpdated ¶
func (e StripeProvider) OnSubscriptionUpdated(cb func(*Subscription, *Subscription))
func (*StripeProvider) RemoveCustomerByProviderID ¶
func (s *StripeProvider) RemoveCustomerByProviderID(providerID string) error
RemoveCustomer directly in stripe
func (*StripeProvider) RemovePlanByProviderID ¶
func (s *StripeProvider) RemovePlanByProviderID(providerID string) error
RemovePlan from stripe
func (*StripeProvider) Sync ¶
func (s *StripeProvider) Sync() error
Sync repository data with stripe
func (*StripeProvider) VerifyCheckout ¶
func (s *StripeProvider) VerifyCheckout(sessionID string) error
Verify that the checkout was completed
func (*StripeProvider) Webhook ¶
func (s *StripeProvider) Webhook() http.HandlerFunc
Webhook returns the http handler that is responsible for handling any event received from stripe
type Subscription ¶
type Subscription struct { ID int64 Provider string ProviderID string CustomerID int64 PriceID int64 Active bool CreatedAt time.Time }
Subscription represents a customers subscription to a Plan
func (*Subscription) TableName ¶
func (s *Subscription) TableName() string
type SubscriptionUser ¶
func (SubscriptionUser) TableName ¶
func (SubscriptionUser) TableName() string