stripecoinpayments

package
v1.70.0-rc Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: AGPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StripeDepositTransactionDescription is the description for Stripe
	// balance transactions representing STORJ deposits.
	StripeDepositTransactionDescription = "STORJ deposit"

	// StripeDepositBonusTransactionDescription is the description for Stripe
	// balance transactions representing bonuses received for STORJ deposits.
	StripeDepositBonusTransactionDescription = "STORJ deposit bonus"
)

Variables

View Source
var (
	// Error defines stripecoinpayments service error.
	Error = errs.Class("stripecoinpayments service")

	// ErrInvalidCoupon defines invalid coupon code error.
	ErrInvalidCoupon = errs.Class("invalid coupon code")
)
View Source
var ErrNoCustomer = Error.New("customer doesn't exist")

ErrNoCustomer is error class defining that there is no customer for user.

View Source
var ErrProjectRecordExists = Error.New("invoice project record already exists")

ErrProjectRecordExists is error class defining that such project record already exists.

Functions

This section is empty.

Types

type Config

type Config struct {
	StripeSecretKey        string `help:"stripe API secret key" default:""`
	StripePublicKey        string `help:"stripe API public key" default:""`
	StripeFreeTierCouponID string `help:"stripe free tier coupon ID" default:""`
	AutoAdvance            bool   `help:"toggle autoadvance feature for invoice creation" default:"false"`
	ListingLimit           int    `help:"sets the maximum amount of items before we start paging on requests" default:"100" hidden:"true"`
	SkipEmptyInvoices      bool   `help:"if set, skips the creation of empty invoices for customers with zero usage for the billing period" default:"true"`
}

Config stores needed information for payment service initialization.

type CreateProjectRecord added in v0.25.0

type CreateProjectRecord struct {
	ProjectID uuid.UUID
	Storage   float64
	Egress    int64
	Segments  float64
}

CreateProjectRecord holds info needed for creation new invoice project record.

type Customer added in v0.25.0

type Customer struct {
	ID     string
	UserID uuid.UUID
}

Customer holds customer id and user id.

type CustomersDB

type CustomersDB interface {
	// Insert inserts a stripe customer into the database.
	Insert(ctx context.Context, userID uuid.UUID, customerID string) error
	// GetCustomerID return stripe customers id.
	GetCustomerID(ctx context.Context, userID uuid.UUID) (string, error)
	// List returns page with customers ids created before specified date.
	List(ctx context.Context, offset int64, limit int, before time.Time) (CustomersPage, error)

	// TODO: get rid of this.
	Raw() *dbx.DB
}

CustomersDB is interface for working with stripe customers table.

architecture: Database

type CustomersPage added in v0.25.0

type CustomersPage struct {
	Customers  []Customer
	Next       bool
	NextOffset int64
}

CustomersPage holds customers and indicates if there is more data available and provides next offset.

type DB added in v0.25.0

type DB interface {
	// Customers is getter for customers db.
	Customers() CustomersDB
	// Transactions is getter for transactions db.
	Transactions() TransactionsDB
	// ProjectRecords is getter for invoice project records db.
	ProjectRecords() ProjectRecordsDB
}

DB is stripecoinpayments DB interface.

architecture: Database

type ProjectRecord added in v0.25.0

type ProjectRecord struct {
	ID          uuid.UUID
	ProjectID   uuid.UUID
	Storage     float64
	Egress      int64
	Segments    float64
	PeriodStart time.Time
	PeriodEnd   time.Time
	State       int
}

ProjectRecord holds project usage particular for billing period.

type ProjectRecordsDB added in v0.25.0

type ProjectRecordsDB interface {
	// Create creates new invoice project record with credits spendings in the DB.
	Create(ctx context.Context, records []CreateProjectRecord, start, end time.Time) error
	// Check checks if invoice project record for specified project and billing period exists.
	Check(ctx context.Context, projectID uuid.UUID, start, end time.Time) error
	// Get returns record for specified project and billing period.
	Get(ctx context.Context, projectID uuid.UUID, start, end time.Time) (*ProjectRecord, error)
	// Consume consumes invoice project record.
	Consume(ctx context.Context, id uuid.UUID) error
	// ListUnapplied returns project records page with unapplied project records.
	ListUnapplied(ctx context.Context, offset int64, limit int, start, end time.Time) (ProjectRecordsPage, error)
}

ProjectRecordsDB is interface for working with invoice project records.

architecture: Database

type ProjectRecordsPage added in v0.25.0

type ProjectRecordsPage struct {
	Records    []ProjectRecord
	Next       bool
	NextOffset int64
}

ProjectRecordsPage holds project records and indicates if there is more data available and provides next offset.

type ProjectUsagePriceModel added in v1.70.1

type ProjectUsagePriceModel struct {
	StorageMBMonthCents decimal.Decimal
	EgressMBCents       decimal.Decimal
	SegmentMonthCents   decimal.Decimal
}

ProjectUsagePriceModel represents price model for project usage.

type Service

type Service struct {

	// BonusRate amount of percents
	BonusRate int64
	// Coupon Values
	StripeFreeTierCouponID string

	// Stripe Extended Features
	AutoAdvance bool
	// contains filtered or unexported fields
}

Service is an implementation for payment service via Stripe and Coinpayments.

architecture: Service

func NewService

func NewService(log *zap.Logger, stripeClient StripeClient, config Config, db DB, walletsDB storjscan.WalletsDB, billingDB billing.TransactionsDB, projectsDB console.Projects, usageDB accounting.ProjectAccounting, usagePrices ProjectUsagePriceModel, usagePriceOverrides map[string]ProjectUsagePriceModel, bonusRate int64) (*Service, error)

NewService creates a Service instance.

func (*Service) Accounts

func (service *Service) Accounts() payments.Accounts

Accounts exposes all needed functionality to manage payment accounts.

func (*Service) ApplyFreeTierCoupons added in v1.37.1

func (service *Service) ApplyFreeTierCoupons(ctx context.Context) (err error)

ApplyFreeTierCoupons iterates through all customers in Stripe. For each customer, if that customer does not currently have a Stripe coupon, the free tier Stripe coupon is applied.

func (*Service) CreateInvoices added in v0.25.0

func (service *Service) CreateInvoices(ctx context.Context, period time.Time) (err error)

CreateInvoices lists through all customers and creates invoices.

func (*Service) FinalizeInvoices added in v1.7.1

func (service *Service) FinalizeInvoices(ctx context.Context) (err error)

FinalizeInvoices transitions all draft invoices to open finalized invoices in stripe. No payment is to be collected yet.

func (*Service) GenerateInvoices added in v1.66.1

func (service *Service) GenerateInvoices(ctx context.Context, period time.Time) (err error)

GenerateInvoices performs all tasks necessary to generate Stripe invoices. This is equivalent to invoking ApplyFreeTierCoupons, PrepareInvoiceProjectRecords, InvoiceApplyProjectRecords, and CreateInvoices in order.

func (*Service) InvoiceApplyProjectRecords added in v0.25.0

func (service *Service) InvoiceApplyProjectRecords(ctx context.Context, period time.Time) (err error)

InvoiceApplyProjectRecords iterates through unapplied invoice project records and creates invoice line items for stripe customer.

func (*Service) InvoiceApplyTokenBalance added in v1.62.1

func (service *Service) InvoiceApplyTokenBalance(ctx context.Context, createdOnAfter time.Time) (err error)

InvoiceApplyTokenBalance iterates through customer storjscan wallets and creates invoice credit notes for stripe customers with invoices on or after the given date.

func (*Service) InvoiceItemsFromProjectRecord added in v1.8.1

func (service *Service) InvoiceItemsFromProjectRecord(projName string, record ProjectRecord) (result []*stripe.InvoiceItemParams)

InvoiceItemsFromProjectRecord calculates Stripe invoice item from project record.

func (*Service) PayInvoices added in v1.65.1

func (service *Service) PayInvoices(ctx context.Context, createdOnAfter time.Time) (err error)

PayInvoices attempts to transition all open finalized invoices created on or after a certain time to "paid" by charging the customer according to subscriptions settings.

func (*Service) PrepareInvoiceProjectRecords added in v0.25.0

func (service *Service) PrepareInvoiceProjectRecords(ctx context.Context, period time.Time) (err error)

PrepareInvoiceProjectRecords iterates through all projects and creates invoice records if none exist.

func (*Service) SetNow added in v1.6.1

func (service *Service) SetNow(now func() time.Time)

SetNow allows tests to have the Service act as if the current time is whatever they want. This avoids races and sleeping, making tests more reliable and efficient.

type StripeCharges added in v1.5.2

type StripeCharges interface {
	List(listParams *stripe.ChargeListParams) *charge.Iter
}

StripeCharges Stripe Charges interface.

type StripeClient added in v1.5.2

type StripeClient interface {
	Customers() StripeCustomers
	PaymentMethods() StripePaymentMethods
	Invoices() StripeInvoices
	InvoiceItems() StripeInvoiceItems
	CustomerBalanceTransactions() StripeCustomerBalanceTransactions
	Charges() StripeCharges
	PromoCodes() StripePromoCodes
	CreditNotes() StripeCreditNotes
}

StripeClient Stripe client interface.

func NewStripeClient added in v1.5.2

func NewStripeClient(log *zap.Logger, config Config) StripeClient

NewStripeClient creates Stripe client from configuration.

func NewStripeMock added in v1.5.2

func NewStripeMock(id storj.NodeID, customersDB CustomersDB, usersDB console.Users) StripeClient

NewStripeMock creates new Stripe client mock.

A new mock is returned for each unique id. If this method is called multiple times with the same id, it will return the same mock instance for that id.

If called by satellite component, the id param should be the peer.ID(). If called by CLI tool, the id param should be a zero value, i.e. storj.NodeID{}. If called by satellitedb test case, the id param should be a random value, i.e. testrand.NodeID().

type StripeCreditNotes added in v1.65.1

type StripeCreditNotes interface {
	New(params *stripe.CreditNoteParams) (*stripe.CreditNote, error)
}

StripeCreditNotes Stripe CreditNotes interface.

type StripeCustomerBalanceTransactions added in v1.5.2

type StripeCustomerBalanceTransactions interface {
	New(params *stripe.CustomerBalanceTransactionParams) (*stripe.CustomerBalanceTransaction, error)
	List(listParams *stripe.CustomerBalanceTransactionListParams) *customerbalancetransaction.Iter
}

StripeCustomerBalanceTransactions Stripe CustomerBalanceTransactions interface.

type StripeCustomers added in v1.5.2

type StripeCustomers interface {
	New(params *stripe.CustomerParams) (*stripe.Customer, error)
	Get(id string, params *stripe.CustomerParams) (*stripe.Customer, error)
	Update(id string, params *stripe.CustomerParams) (*stripe.Customer, error)
}

StripeCustomers Stripe Customers interface.

type StripeInvoiceItems added in v1.5.2

type StripeInvoiceItems interface {
	New(params *stripe.InvoiceItemParams) (*stripe.InvoiceItem, error)
	Update(id string, params *stripe.InvoiceItemParams) (*stripe.InvoiceItem, error)
	List(listParams *stripe.InvoiceItemListParams) *invoiceitem.Iter
	Del(id string, params *stripe.InvoiceItemParams) (*stripe.InvoiceItem, error)
}

StripeInvoiceItems Stripe InvoiceItems interface.

type StripeInvoices added in v1.5.2

type StripeInvoices interface {
	New(params *stripe.InvoiceParams) (*stripe.Invoice, error)
	List(listParams *stripe.InvoiceListParams) *invoice.Iter
	Update(id string, params *stripe.InvoiceParams) (*stripe.Invoice, error)
	FinalizeInvoice(id string, params *stripe.InvoiceFinalizeParams) (*stripe.Invoice, error)
	Pay(id string, params *stripe.InvoicePayParams) (*stripe.Invoice, error)
}

StripeInvoices Stripe Invoices interface.

type StripePaymentMethods added in v1.5.2

type StripePaymentMethods interface {
	List(listParams *stripe.PaymentMethodListParams) *paymentmethod.Iter
	New(params *stripe.PaymentMethodParams) (*stripe.PaymentMethod, error)
	Attach(id string, params *stripe.PaymentMethodAttachParams) (*stripe.PaymentMethod, error)
	Detach(id string, params *stripe.PaymentMethodDetachParams) (*stripe.PaymentMethod, error)
}

StripePaymentMethods Stripe PaymentMethods interface.

type StripePromoCodes added in v1.35.2

type StripePromoCodes interface {
	List(params *stripe.PromotionCodeListParams) *promotioncode.Iter
}

StripePromoCodes is the Stripe PromoCodes interface.

type Transaction

type Transaction struct {
	ID        coinpayments.TransactionID
	AccountID uuid.UUID
	Address   string
	Amount    currency.Amount
	Received  currency.Amount
	Status    coinpayments.Status
	Key       string
	Timeout   time.Duration
	CreatedAt time.Time
}

Transaction defines coinpayments transaction info that is stored in the DB.

type TransactionsDB

type TransactionsDB interface {
	// GetLockedRate returns locked conversion rate for transaction or error if non exists.
	GetLockedRate(ctx context.Context, id coinpayments.TransactionID) (decimal.Decimal, error)
	// ListAccount returns all transaction for specific user.
	ListAccount(ctx context.Context, userID uuid.UUID) ([]Transaction, error)
	// TestInsert inserts new coinpayments transaction into DB.
	TestInsert(ctx context.Context, tx Transaction) (time.Time, error)
	// TestLockRate locks conversion rate for transaction.
	TestLockRate(ctx context.Context, id coinpayments.TransactionID, rate decimal.Decimal) error
}

TransactionsDB is an interface which defines functionality of DB which stores coinpayments transactions.

architecture: Database

Jump to

Keyboard shortcuts

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