payment

package
v0.0.0-...-4df811a Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorNotAStripeEvent = errors.New("not a stripe event")

Functions

This section is empty.

Types

type CustomerID

type CustomerID string

type Event

type Event struct {
	Type           EventType      `json:"type"`
	OrganizationID uint           `json:"organization_id"`
	SessionID      string         `json:"session_id"`
	CustomerID     CustomerID     `json:"customer_id"`
	SubscriptionID SubscriptionID `json:"subscription_id"`
}

type EventType

type EventType string
const (
	EventNothing              EventType = "nothing"
	EventCheckoutComplete     EventType = "checkout.complete"
	EventSubscriptionPaid     EventType = "subscription.paid"
	EventSubscriptionUnpaid   EventType = "subscription.unpaid"
	EventSubscriptionCanceled EventType = "subscription.canceled"
)

type Payment

type Payment interface {
	// StartCheckout should start a checkout process
	// the quantity params should be the number of
	// unique users associated with the organization
	// that subscription is for
	// returns a session id, a url for the user proceed, and an error
	StartCheckout(
		organization *models.Organization,
		seats int64,
	) (string, string, string, error)
	GetManagementLink(organization *models.Organization) (string, error)
	// For webhooks, returns a unified event from a request
	HandleEvent(r *http.Request) (Event, error)
	// returns subscription information
	GetSubscription(subscriptionID SubscriptionID) (Subscription, error)
	// Updates the subscription (changes the number of seats
	UpdateSubscription(subscriptionID SubscriptionID, seats int64) error
	// Cancels the subscription
	CancelSubscription(subscriptionID SubscriptionID) error
}

func NewStripePayment

func NewStripePayment() Payment

type Subscription

type Subscription struct {
	ID                 SubscriptionID
	CustomerID         CustomerID
	Seats              int
	Status             SubscriptionStatus
	CurrentPeriodStart time.Time
	CurrentPeriodEnd   time.Time
}

type SubscriptionID

type SubscriptionID string

type SubscriptionStatus

type SubscriptionStatus string
const (
	SubscriptionStatusUnpaid   SubscriptionStatus = "unpaid"
	SubscriptionStatusPaid     SubscriptionStatus = "paid"
	SubscriptionStatusCanceled SubscriptionStatus = "canceled"
)

Jump to

Keyboard shortcuts

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