customer

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SyncDelay = time.Second * 60
)

Variables

View Source
var (
	ErrNotFound      = errors.New("customer not found")
	ErrInvalidUUID   = errors.New("invalid syntax of uuid")
	ErrInvalidID     = errors.New("billing customer id is invalid")
	ErrConflict      = errors.New("customer already exist")
	ErrInvalidDetail = errors.New("invalid billing customer detail")
	ErrDisabled      = errors.New("billing customer is disabled")
)

Functions

func GetStripeTestClockFromContext added in v0.8.29

func GetStripeTestClockFromContext(ctx context.Context) (string, bool)

GetStripeTestClockFromContext returns the stripe test clock id from the context

func SetStripeTestClockInContext added in v0.8.29

func SetStripeTestClockInContext(ctx context.Context, s string) context.Context

SetStripeTestClockInContext sets the stripe test clock id in the context

Types

type Address

type Address struct {
	City       string `json:"city"`
	Country    string `json:"country"`
	Line1      string `json:"line1"`
	Line2      string `json:"line2"`
	PostalCode string `json:"postal_code"`
	State      string `json:"state"`
}

type Customer

type Customer struct {
	ID         string
	OrgID      string
	ProviderID string // identifier set by the billing engine provider

	Name    string
	Email   string
	Phone   string
	Address Address
	TaxData []Tax
	// Currency Three-letter ISO 4217 currency code in lower case
	Currency string `default:"usd"`
	Metadata metadata.Metadata

	// Stripe specific fields
	// StripeTestClockID is used for testing purposes only to simulate a subscription
	StripeTestClockID *string

	State     State
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time
}

type Filter

type Filter struct {
	OrgID string
	State State
}

type PaymentMethod added in v0.8.13

type PaymentMethod struct {
	ID         string
	CustomerID string
	ProviderID string
	Type       string

	CardLast4       string
	CardBrand       string
	CardExpiryYear  int64
	CardExpiryMonth int64

	Metadata  metadata.Metadata
	CreatedAt time.Time
}

type Provider

type Provider string
const (
	ProviderStripe Provider = "stripe"
)

type Repository

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

type Service

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

func NewService

func NewService(stripeClient *client.API, repository Repository) *Service

func (*Service) Close added in v0.9.0

func (s *Service) Close() error

func (*Service) Create

func (s *Service) Create(ctx context.Context, customer Customer) (Customer, error)

func (*Service) Delete

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

func (*Service) GetByID

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

func (*Service) GetByOrgID

func (s *Service) GetByOrgID(ctx context.Context, orgID string) (Customer, error)

func (*Service) Init added in v0.9.0

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

func (*Service) List

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

func (*Service) ListPaymentMethods added in v0.8.13

func (s *Service) ListPaymentMethods(ctx context.Context, id string) ([]PaymentMethod, error)

func (*Service) SyncWithProvider added in v0.9.0

func (s *Service) SyncWithProvider(ctx context.Context, customr Customer) error

SyncWithProvider syncs the customer state with the billing provider

func (*Service) Update added in v0.8.15

func (s *Service) Update(ctx context.Context, customer Customer) (Customer, error)

type State added in v0.8.38

type State string
const (
	ActiveState   State = "active"
	DisabledState State = "disabled"
)

func (State) String added in v0.8.38

func (s State) String() string

type Tax added in v0.9.0

type Tax struct {
	// Type like "vat", "gst", "sales_tax" or if it's
	// provider specific us_ein, uk_vat, in_gst, etc
	Type string
	// ID is the tax identifier
	ID string
}

Jump to

Keyboard shortcuts

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