Documentation ¶
Index ¶
- Constants
- Variables
- type Config
- type CreateProjectRecord
- type Customer
- type CustomersDB
- type CustomersPage
- type DB
- type ProjectRecord
- type ProjectRecordsDB
- type ProjectRecordsPage
- type Service
- func (service *Service) Accounts() payments.Accounts
- func (service *Service) ApplyFreeTierCoupons(ctx context.Context) (err error)
- func (service *Service) CreateInvoices(ctx context.Context, period time.Time) (err error)
- func (service *Service) FinalizeInvoices(ctx context.Context) (err error)
- func (service *Service) GenerateInvoices(ctx context.Context, period time.Time) (err error)
- func (service *Service) InvoiceApplyProjectRecords(ctx context.Context, period time.Time) (err error)
- func (service *Service) InvoiceApplyTokenBalance(ctx context.Context, createdOnAfter time.Time) (err error)
- func (service *Service) InvoiceItemsFromProjectUsage(projName string, partnerUsages map[string]accounting.ProjectUsage) (result []*stripe.InvoiceItemParams)
- func (service *Service) PayInvoices(ctx context.Context, createdOnAfter time.Time) (err error)
- func (service *Service) PrepareInvoiceProjectRecords(ctx context.Context, period time.Time) (err error)
- func (service *Service) SetNow(now func() time.Time)
- type StripeCharges
- type StripeClient
- type StripeCreditNotes
- type StripeCustomerBalanceTransactions
- type StripeCustomers
- type StripeInvoiceItems
- type StripeInvoices
- type StripePaymentMethods
- type StripePromoCodes
- type Transaction
- type TransactionsDB
Constants ¶
const ( // MockCouponID1 is a coupon that stripe mock is aware of. Applying unknown coupons results in failure. MockCouponID1 = "c1" // MockCouponID2 is a coupon that stripe mock is aware of. Applying unknown coupons results in failure. MockCouponID2 = "c2" // MockCouponID3 is a coupon that stripe mock is aware of. Applying unknown coupons results in failure. MockCouponID3 = "c3" // MockInvoicesNewFailure can be passed to mockInvoices.New as `desc` argument to cause it to return // an error. MockInvoicesNewFailure = "mock_invoices_new_failure" // MockInvoicesPayFailure can be passed to mockInvoices.Pay as params.PaymentMethod to cause it to return // an error. MockInvoicesPayFailure = "mock_invoices_pay_failure" // TestPaymentMethodsNewFailure can be passed to creditCards.Add as the cardToken arg to cause // mockPaymentMethods.New to return an error. TestPaymentMethodsNewFailure = "test_payment_methods_new_failure" // TestPaymentMethodsAttachFailure can be passed to creditCards.Add as the cardToken arg to cause // mockPaymentMethods.Attach to return an error. TestPaymentMethodsAttachFailure = "test_payment_methods_attach_failure" )
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 ¶
var ErrNoCustomer = Error.New("customer doesn't exist")
ErrNoCustomer is error class defining that there is no customer for user.
var ErrProjectRecordExists = Error.New("invoice project record already exists")
ErrProjectRecordExists is error class defining that such project record already exists.
var ( // Error defines stripecoinpayments service error. Error = errs.Class("stripecoinpayments service") )
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 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) // GetUserID return userID given stripe customer id. GetUserID(ctx context.Context, customerID string) (uuid.UUID, 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
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 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, usersDB console.Users, usageDB accounting.ProjectAccounting, usagePrices payments.ProjectUsagePriceModel, usagePriceOverrides map[string]payments.ProjectUsagePriceModel, packagePlans map[string]payments.PackagePlan, bonusRate int64) (*Service, error)
NewService creates a Service instance.
func (*Service) ApplyFreeTierCoupons ¶ added in v1.37.1
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
CreateInvoices lists through all customers and creates invoices.
func (*Service) FinalizeInvoices ¶ added in v1.7.1
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
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) InvoiceItemsFromProjectUsage ¶ added in v1.74.1
func (service *Service) InvoiceItemsFromProjectUsage(projName string, partnerUsages map[string]accounting.ProjectUsage) (result []*stripe.InvoiceItemParams)
InvoiceItemsFromProjectUsage calculates Stripe invoice item from project usage.
func (*Service) PayInvoices ¶ added in v1.65.1
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.
type StripeCharges ¶ added in v1.5.2
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(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) Del(id string, params *stripe.InvoiceParams) (*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