checkout

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SessionValidity = time.Hour * 24

	MinimumProductQuantity = 1
	MaximumProductQuantity = 100000 // max: 999999

	// ProductQuantityMetadataKey is the metadata key for the quantity of the product
	// it's necessary to cast as this properly because while storing metadata, it's serialized as json
	// and when retrieved, it's always an interface{} of float64 type
	ProductQuantityMetadataKey = "product_quantity"
	// AmountTotalMetadataKey is the metadata key for the total amount of the checkout
	// same goes for this as well, it's always an interface{} of float64 type
	AmountTotalMetadataKey = "amount_total"
	// ProcessedMetadataKey is the metadata key to indicate that the checkout has been processed
	// in the system
	ProcessedMetadataKey = "processed"

	CurrencyMetadataKey               = "currency"
	ProviderIDSubscriptionMetadataKey = "provider_subscription_id"
	InitiatorIDMetadataKey            = "initiated_by"
	CheckoutIDMetadataKey             = "checkout_id"
)

Variables

View Source
var (
	ErrNotFound      = errors.New("checkout not found")
	ErrInvalidUUID   = errors.New("invalid syntax of uuid")
	ErrInvalidID     = errors.New("invalid checkout id")
	ErrInvalidDetail = errors.New("invalid checkout detail")
)

Functions

This section is empty.

Types

type AuthnService added in v0.8.34

type AuthnService interface {
	GetPrincipal(ctx context.Context, assertions ...authenticate.ClientAssertion) (authenticate.Principal, error)
}

type Checkout

type Checkout struct {
	ID         string
	ProviderID string // identifier set by the billing engine provider
	CustomerID string

	PlanID           string // uuid of plan if resource type is subscription
	SkipTrial        bool   // if set, no trial period
	CancelAfterTrial bool   // if set, cancel subscription after trial period
	ProviderCouponID string // coupon identifier set by the billing engine provider
	ProductID        string
	Quantity         int64 // product quantity if any

	// CancelUrl is the URL to which provider sends customers when payment is canceled
	CancelUrl string
	// SuccessUrl is the URL to which provider sends customers when payment is complete
	SuccessUrl string
	// CheckoutUrl is the URL to which provider sends customers to finish payment
	CheckoutUrl string

	State         string
	PaymentStatus string

	Metadata  metadata.Metadata
	CreatedAt time.Time
	UpdatedAt time.Time
	ExpireAt  time.Time
}

type CreditService

type CreditService interface {
	Add(ctx context.Context, cred credit.Credit) error
}

type CustomerService

type CustomerService interface {
	GetByID(ctx context.Context, id string) (customer.Customer, error)
	List(ctx context.Context, filter customer.Filter) ([]customer.Customer, error)
	RegisterToProviderIfRequired(ctx context.Context, customerID string) (customer.Customer, error)
}

type Filter

type Filter struct {
	CustomerID string
	ProviderID string
}

type OrganizationService added in v0.8.13

type OrganizationService interface {
	MemberCount(ctx context.Context, orgID string) (int64, error)
}

type PlanService

type PlanService interface {
	List(ctx context.Context, filter plan.Filter) ([]plan.Plan, error)
	GetByID(ctx context.Context, id string) (plan.Plan, error)
}

type ProductService added in v0.8.14

type ProductService interface {
	GetByID(ctx context.Context, id string) (product.Product, error)
}

type Repository

type Repository interface {
	GetByID(ctx context.Context, id string) (Checkout, error)
	Create(ctx context.Context, ch Checkout) (Checkout, error)
	UpdateByID(ctx context.Context, ch Checkout) (Checkout, error)
	List(ctx context.Context, filter Filter) ([]Checkout, error)
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(stripeClient *client.API, cfg billing.Config, repository Repository,
	customerService CustomerService, planService PlanService,
	subscriptionService SubscriptionService, productService ProductService,
	creditService CreditService, orgService OrganizationService,
	authnService AuthnService) *Service

func (*Service) Apply added in v0.8.16

Apply applies the actual request directly without creating a checkout session for example when a request is created for a plan, it will directly subscribe without actually paying for it

func (*Service) Close

func (s *Service) Close() error

func (*Service) Create

func (s *Service) Create(ctx context.Context, ch Checkout) (Checkout, error)

func (*Service) CreateSessionForCustomerPortal added in v0.10.0

func (s *Service) CreateSessionForCustomerPortal(ctx context.Context, ch Checkout) (Checkout, error)

func (*Service) CreateSessionForPaymentMethod added in v0.8.16

func (s *Service) CreateSessionForPaymentMethod(ctx context.Context, ch Checkout) (Checkout, error)

func (*Service) GetByID

func (s *Service) GetByID(ctx context.Context, id string) (Checkout, error)

func (*Service) Init

func (s *Service) Init(ctx context.Context) error

func (*Service) List

func (s *Service) List(ctx context.Context, filter Filter) ([]Checkout, error)

func (*Service) SyncWithProvider

func (s *Service) SyncWithProvider(ctx context.Context, customerID string) error

SyncWithProvider syncs the subscription state with the billing provider

func (*Service) TriggerSyncByProviderID added in v0.13.0

func (s *Service) TriggerSyncByProviderID(ctx context.Context, id string) error

type State

type State string
const (
	StatePending  State = "pending"
	StateExpired  State = "expired"
	StateComplete State = "complete"
)

func (State) String

func (s State) String() string

type SubscriptionService

type SubscriptionService interface {
	List(ctx context.Context, filter subscription.Filter) ([]subscription.Subscription, error)
	Create(ctx context.Context, sub subscription.Subscription) (subscription.Subscription, error)
	GetByProviderID(ctx context.Context, id string) (subscription.Subscription, error)
	Cancel(ctx context.Context, id string, immediate bool) (subscription.Subscription, error)
	HasUserSubscribedBefore(ctx context.Context, customerID string, planID string) (bool, error)
}

Jump to

Keyboard shortcuts

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