Documentation ¶
Index ¶
- Constants
- Variables
- func NewClientAPI(stripeConfig *portalconfig.StripeConfig, logger Logger) *client.API
- func NewPriceFromProductOfProductList(stripeProduct *stripe.Product) (price *model.Price, err error)
- func NewPriceFromProductOfSubscription(stripeProduct *stripe.Product, stripePrice *stripe.Price) (price *model.Price, err error)
- type Cache
- type CheckoutSession
- type CheckoutSessionCompletedEvent
- type CustomerSubscriptionCreatedEvent
- type CustomerSubscriptionDeletedEvent
- type CustomerSubscriptionEvent
- type CustomerSubscriptionUpdatedEvent
- type EndpointsProvider
- type Event
- type EventType
- type Logger
- type PlanService
- type Service
- func (s *Service) CancelSubscriptionImmediately(ctx context.Context, subscriptionID string) error
- func (s *Service) ConstructEvent(r *http.Request) (Event, error)
- func (s *Service) CreateCheckoutSession(ctx context.Context, appID string, customerEmail string, ...) (*CheckoutSession, error)
- func (s *Service) CreateSubscriptionIfNotExists(ctx context.Context, checkoutSessionID string, ...) error
- func (s *Service) FetchCheckoutSession(ctx context.Context, checkoutSessionID string) (*CheckoutSession, error)
- func (s *Service) FetchSubscriptionPlans(ctx context.Context) (subscriptionPlans []*model.SubscriptionPlan, err error)
- func (s *Service) GenerateCustomerPortalSession(appID string, customerID string) (*stripe.BillingPortalSession, error)
- func (s *Service) GetLastPaymentError(ctx context.Context, stripeCustomerID string) (*stripe.Error, error)
- func (s *Service) GetSubscription(ctx context.Context, stripeCustomerID string) (*stripe.Subscription, error)
- func (s *Service) GetSubscriptionPlan(ctx context.Context, planName string) (*model.SubscriptionPlan, error)
- func (s *Service) PreviewUpdateSubscription(ctx context.Context, stripeSubscriptionID string, ...) (preview *model.SubscriptionUpdatePreview, err error)
- func (s *Service) SetSubscriptionCancelAtPeriodEnd(stripeSubscriptionID string, cancelAtPeriodEnd bool) (*time.Time, error)
- func (s *Service) UpdateSubscription(ctx context.Context, stripeSubscriptionID string, ...) (err error)
- type StripeCache
Constants ¶
View Source
const ( MetadataKeyAppID = "app_id" MetadataKeyPlanName = "plan_name" MetadataKeyVersion = "version" MetadataKeyPriceType = "price_type" MetadataKeyUsageType = "usage_type" MetadatakeySMSRegion = "sms_region" MetadatakeyWhatsappRegion = "whatsapp_region" MetadataKeyFreeQuantity = "free_quantity" )
View Source
const RedisCacheKeySubscriptionPlans = "cache:portal:subscription-plans"
Variables ¶
View Source
var DependencySet = wire.NewSet( NewLogger, NewClientAPI, NewStripeCache, wire.Struct(new(Service), "*"), wire.Bind(new(Cache), new(*StripeCache)), )
View Source
var ErrAppAlreadySubscribed = errors.New("app already subscribed")
View Source
var ErrCustomerAlreadySubscribed = errors.New("custom already subscribed")
View Source
var ErrNoInvoice = errors.New("subscription has no invoice")
View Source
var ErrNoPaymentIntent = errors.New("invoice has no payment intent")
View Source
var ErrNoSubscription = errors.New("customer has no subscription")
View Source
var ErrUnknownEvent = errors.New("unknown stripe event")
Functions ¶
func NewClientAPI ¶
func NewClientAPI(stripeConfig *portalconfig.StripeConfig, logger Logger) *client.API
Types ¶
type CheckoutSession ¶
type CheckoutSession struct { StripeCheckoutSessionID string StripeCustomerID *string AppID string URL string ExpiresAt int64 Status stripe.CheckoutSessionStatus }
func NewCheckoutSession ¶
func NewCheckoutSession(checkoutSession *stripe.CheckoutSession) *CheckoutSession
func (*CheckoutSession) IsCompleted ¶
func (cs *CheckoutSession) IsCompleted() bool
type CheckoutSessionCompletedEvent ¶
type CheckoutSessionCompletedEvent struct { AppID string PlanName string StripeCustomerID string StripeCheckoutSessionID string }
func (*CheckoutSessionCompletedEvent) EventType ¶
func (e *CheckoutSessionCompletedEvent) EventType() EventType
type CustomerSubscriptionCreatedEvent ¶
type CustomerSubscriptionCreatedEvent struct {
*CustomerSubscriptionEvent
}
func (*CustomerSubscriptionCreatedEvent) EventType ¶
func (e *CustomerSubscriptionCreatedEvent) EventType() EventType
type CustomerSubscriptionDeletedEvent ¶
type CustomerSubscriptionDeletedEvent struct {
*CustomerSubscriptionEvent
}
func (*CustomerSubscriptionDeletedEvent) EventType ¶
func (e *CustomerSubscriptionDeletedEvent) EventType() EventType
type CustomerSubscriptionEvent ¶
type CustomerSubscriptionEvent struct { StripeSubscriptionID string StripeCustomerID string AppID string PlanName string StripeSubscriptionStatus stripe.SubscriptionStatus }
func (*CustomerSubscriptionEvent) IsSubscriptionActive ¶
func (e *CustomerSubscriptionEvent) IsSubscriptionActive() bool
func (*CustomerSubscriptionEvent) IsSubscriptionCanceled ¶
func (e *CustomerSubscriptionEvent) IsSubscriptionCanceled() bool
func (*CustomerSubscriptionEvent) IsSubscriptionIncompleteExpired ¶
func (e *CustomerSubscriptionEvent) IsSubscriptionIncompleteExpired() bool
type CustomerSubscriptionUpdatedEvent ¶
type CustomerSubscriptionUpdatedEvent struct {
*CustomerSubscriptionEvent
}
func (*CustomerSubscriptionUpdatedEvent) EventType ¶
func (e *CustomerSubscriptionUpdatedEvent) EventType() EventType
type EndpointsProvider ¶
type EventType ¶
type EventType string
const ( EventTypeCheckoutSessionCompleted EventType = "checkout.session.completed" EventTypeCustomerSubscriptionCreated EventType = "customer.subscription.created" EventTypeCustomerSubscriptionUpdated EventType = "customer.subscription.updated" EventTypeCustomerSubscriptionDeleted EventType = "customer.subscription.deleted" )
type PlanService ¶
type Service ¶
type Service struct { ClientAPI *client.API Logger Logger Plans PlanService GlobalRedisHandle *globalredis.Handle Cache Cache Clock clock.Clock StripeConfig *portalconfig.StripeConfig Endpoints EndpointsProvider }
func (*Service) CancelSubscriptionImmediately ¶
CancelSubscriptionImmediately removes the subscription immediately It should be used only for failed subscriptions To cancel normal subscription, SetSubscriptionCancelAtPeriodEnd should be used
func (*Service) CreateCheckoutSession ¶
func (s *Service) CreateCheckoutSession(ctx context.Context, appID string, customerEmail string, subscriptionPlan *model.SubscriptionPlan) (*CheckoutSession, error)
func (*Service) CreateSubscriptionIfNotExists ¶
func (*Service) FetchCheckoutSession ¶
func (*Service) FetchSubscriptionPlans ¶
func (*Service) GenerateCustomerPortalSession ¶
func (*Service) GetLastPaymentError ¶
func (*Service) GetSubscription ¶
func (*Service) GetSubscriptionPlan ¶
func (*Service) PreviewUpdateSubscription ¶
func (s *Service) PreviewUpdateSubscription(ctx context.Context, stripeSubscriptionID string, subscriptionPlan *model.SubscriptionPlan) (preview *model.SubscriptionUpdatePreview, err error)
func (*Service) SetSubscriptionCancelAtPeriodEnd ¶
func (*Service) UpdateSubscription ¶
type StripeCache ¶
func NewStripeCache ¶
func NewStripeCache() *StripeCache
Click to show internal directories.
Click to hide internal directories.