db

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const CName = "any-pp.db"

Variables

This section is empty.

Functions

func New

func New() app.Component

Types

type AnyppDB

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

func (*AnyppDB) Close

func (anyppdb *AnyppDB) Close(ctx context.Context) (err error)

TODO: check if it is even called, this is not a app.ComponentRunnable instance so maybe it won't be called

func (*AnyppDB) CreateOrUpdateSubscription

func (anyppdb *AnyppDB) CreateOrUpdateSubscription(ctx context.Context, sub *Subscription, userAnyID string) (err error)

func (*AnyppDB) GetAllSubscriptionsInStatus

func (anyppdb *AnyppDB) GetAllSubscriptionsInStatus(ctx context.Context, status proto.SubscriptionStatus) (subsIds []string, err error)

func (*AnyppDB) GetPaymentRequest

func (anyppdb *AnyppDB) GetPaymentRequest(ctx context.Context, billingID string) (pr *PaymentRequest, err error)

func (*AnyppDB) GetPaymentRequest_TestData

func (anyppdb *AnyppDB) GetPaymentRequest_TestData() (*PaymentRequest, error)

func (*AnyppDB) GetSubscription

func (anyppdb *AnyppDB) GetSubscription(ctx context.Context, subID string) (sub *Subscription, err error)

func (*AnyppDB) GetSubscriptionForUser

func (anyppdb *AnyppDB) GetSubscriptionForUser(ctx context.Context, userAnyID string) (sub *Subscription, err error)

func (*AnyppDB) Init

func (anyppdb *AnyppDB) Init(a *app.App) (err error)

func (*AnyppDB) Name

func (anyppdb *AnyppDB) Name() (name string)

func (*AnyppDB) SaveNewPaymentRequest

func (anyppdb *AnyppDB) SaveNewPaymentRequest(ctx context.Context, bsr *proto.BuySubscriptionRequest, billingID string) (err error)

func (*AnyppDB) UpdatePaymentRequest

func (anyppdb *AnyppDB) UpdatePaymentRequest(ctx context.Context, pr *PaymentRequest, billingID string) (err error)

type DBService

type DBService interface {
	// A PaymentRequest is created first by the user
	SaveNewPaymentRequest(ctx context.Context, bsr *proto.BuySubscriptionRequest, billingID string) (err error)
	GetPaymentRequest(ctx context.Context, billingID string) (pr *PaymentRequest, err error)
	UpdatePaymentRequest(ctx context.Context, pr *PaymentRequest, billingID string) (err error)

	// When payment is completed, we create a new subscription
	// with []payments array (do not confuse with PaymentRequest)
	GetSubscriptionForUser(ctx context.Context, userAnyID string) (sub *Subscription, err error)
	GetSubscription(ctx context.Context, subID string) (sub *Subscription, err error)
	// max output - 100 items
	GetAllSubscriptionsInStatus(ctx context.Context, status proto.SubscriptionStatus) (subsIds []string, err error)
	CreateOrUpdateSubscription(ctx context.Context, sub *Subscription, userAnyID string) (err error)

	app.Component
}

type NSOperation

type NSOperation struct {
	OperationType  NSOperationType          `bson:"OperationType"`
	OperationId    string                   `bson:"OperationId"`
	OperationState anyns_api.OperationState `bson:"OperationState"`
}

type NSOperationType

type NSOperationType uint8
const (
	NSOperationTypeUnknown         NSOperationType = 0
	NSOperationTypeFundUserAccount NSOperationType = 1
)

type Payment

type Payment struct {
	Id              primitive.ObjectID `bson:"_id"`
	PaymentState    ReqState           `bson:"PaymentState"`
	PaymentProvider PaymentProvider    `bson:"PaymentProvider"`

	// If through Stripe
	StripePaymentMethod uint8 `bson:"StripePaymentMethod"`
}

type PaymentProvider

type PaymentProvider uint8
const (
	PaymentProviderUnknown PaymentProvider = 0
	PaymentProviderStripe  PaymentProvider = 1
)

type PaymentRequest

type PaymentRequest struct {
	Id primitive.ObjectID `bson:"_id"`

	// random generated string
	BillingID     string                 `bson:"BillingID"`
	RequestedTier proto.SubscriptionTier `bson:"RequestedTier"`

	OwnerAnyID      string `bson:"OwnerAnyID"`
	OwnerEthAddress string `bson:"OwnerEthAddress"`

	PaymentMethod       proto.PaymentMethod `bson:"PaymentMethod"`
	PaymentRequestState ReqState            `bson:"PaymentRequestState"`
}

type ReqState

type ReqState uint8
const (
	ReqStateNew       ReqState = 0
	ReqStateCompleted ReqState = 1
)

type Subscription

type Subscription struct {
	Id primitive.ObjectID `bson:"_id"`

	OwnerAnyID      string                 `bson:"OwnerAnyID"`
	OwnerEthAddress string                 `bson:"OwnerEthAddress"`
	CurrentTier     proto.SubscriptionTier `bson:"CurrentTier"`

	Started uint64 `bson:"Started"`
	Ends    uint64 `bson:"Ends"`

	SubscriptionStatus proto.SubscriptionStatus `bson:"SubscriptionStatus"`
	IsAutoRenew        bool                     `bson:"IsAutoRenew"`

	// if through Stripe
	StripeSessionId      string `bson:"StripeSessionId"`
	StripeSubscriptionID string `bson:"StripeSubscriptionID"`

	Payments              []Payment     `bson:"Payments"`
	NameServiceOperations []NSOperation `bson:"NameServiceOperations"`
}

Directories

Path Synopsis
Code generated by MockGen.
Code generated by MockGen.

Jump to

Keyboard shortcuts

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