libstripe

package
v0.0.0-...-81dc835 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

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 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

func NewPriceFromProductOfProductList

func NewPriceFromProductOfProductList(stripeProduct *stripe.Product) (price *model.Price, err error)

func NewPriceFromProductOfSubscription

func NewPriceFromProductOfSubscription(stripeProduct *stripe.Product, stripePrice *stripe.Price) (price *model.Price, err error)

Types

type Cache

type Cache interface {
	Get(context.Context, redisutil.SimpleCmdable, redisutil.Item) ([]byte, error)
}

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

type CustomerSubscriptionCreatedEvent

type CustomerSubscriptionCreatedEvent struct {
	*CustomerSubscriptionEvent
}

func (*CustomerSubscriptionCreatedEvent) EventType

type CustomerSubscriptionDeletedEvent

type CustomerSubscriptionDeletedEvent struct {
	*CustomerSubscriptionEvent
}

func (*CustomerSubscriptionDeletedEvent) 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

type EndpointsProvider

type EndpointsProvider interface {
	BillingEndpointURL(relayGlobalAppID string) *url.URL
	BillingRedirectEndpointURL(relayGlobalAppID string) *url.URL
}

type Event

type Event interface {
	EventType() EventType
}

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 Logger

type Logger struct{ *log.Logger }

func NewLogger

func NewLogger(lf *log.Factory) Logger

type PlanService

type PlanService interface {
	ListPlans(ctx context.Context) ([]*plan.Plan, error)
}

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

func (s *Service) CancelSubscriptionImmediately(ctx context.Context, subscriptionID string) error

CancelSubscriptionImmediately removes the subscription immediately It should be used only for failed subscriptions To cancel normal subscription, SetSubscriptionCancelAtPeriodEnd should be used

func (*Service) ConstructEvent

func (s *Service) ConstructEvent(r *http.Request) (Event, error)

func (*Service) CreateCheckoutSession

func (s *Service) CreateCheckoutSession(ctx context.Context, appID string, customerEmail string, subscriptionPlan *model.SubscriptionPlan) (*CheckoutSession, error)

func (*Service) CreateSubscriptionIfNotExists

func (s *Service) CreateSubscriptionIfNotExists(ctx context.Context, checkoutSessionID string, subscriptionPlans []*model.SubscriptionPlan) error

func (*Service) FetchCheckoutSession

func (s *Service) FetchCheckoutSession(ctx context.Context, checkoutSessionID string) (*CheckoutSession, error)

func (*Service) FetchSubscriptionPlans

func (s *Service) FetchSubscriptionPlans(ctx context.Context) (subscriptionPlans []*model.SubscriptionPlan, err error)

func (*Service) GenerateCustomerPortalSession

func (s *Service) GenerateCustomerPortalSession(appID string, customerID string) (*stripe.BillingPortalSession, error)

func (*Service) GetLastPaymentError

func (s *Service) GetLastPaymentError(ctx context.Context, stripeCustomerID string) (*stripe.Error, error)

func (*Service) GetSubscription

func (s *Service) GetSubscription(ctx context.Context, stripeCustomerID string) (*stripe.Subscription, error)

func (*Service) GetSubscriptionPlan

func (s *Service) GetSubscriptionPlan(ctx context.Context, planName string) (*model.SubscriptionPlan, error)

func (*Service) PreviewUpdateSubscription

func (s *Service) PreviewUpdateSubscription(ctx context.Context, stripeSubscriptionID string, subscriptionPlan *model.SubscriptionPlan) (preview *model.SubscriptionUpdatePreview, err error)

func (*Service) SetSubscriptionCancelAtPeriodEnd

func (s *Service) SetSubscriptionCancelAtPeriodEnd(stripeSubscriptionID string, cancelAtPeriodEnd bool) (*time.Time, error)

func (*Service) UpdateSubscription

func (s *Service) UpdateSubscription(ctx context.Context, stripeSubscriptionID string, subscriptionPlan *model.SubscriptionPlan) (err error)

type StripeCache

type StripeCache struct {
	*redisutil.Cache
}

func NewStripeCache

func NewStripeCache() *StripeCache

Jump to

Keyboard shortcuts

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