customer

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: Apache-2.0 Imports: 14 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 GetStripeWebhookSignatureFromContext added in v0.13.0

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

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

func SetStripeWebhookSignatureInContext added in v0.13.0

func SetStripeWebhookSignatureInContext(ctx context.Context, s string) context.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
	// Provider id identifier set by the billing engine provider
	// could be empty if the customer is created as offline
	ProviderID string

	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
}

func (Customer) IsOffline added in v0.17.0

func (c Customer) IsOffline() bool

type Filter

type Filter struct {
	OrgID      string
	ProviderID 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, offline bool) (Customer, error)

func (*Service) Delete

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

func (*Service) Disable added in v0.17.0

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

func (*Service) Enable added in v0.17.0

func (s *Service) Enable(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) RegisterToProvider added in v0.17.0

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

func (*Service) RegisterToProviderIfRequired added in v0.17.0

func (s *Service) RegisterToProviderIfRequired(ctx context.Context, customerID string) (Customer, 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) TriggerSyncByProviderID added in v0.13.0

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

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