satellite/payments: rename 'stripecoinpayments' package to 'stripe'

Automatic rename. May require some more cleanups later.

Change-Id: I18220a4278056d25c41fb137832bb81f2b876ac1
This commit is contained in:
Michal Niewrzal 2023-04-06 13:41:14 +02:00 committed by Storj Robot
parent 31f5e2cb65
commit 8a50a3baa3
47 changed files with 222 additions and 222 deletions

View File

@ -14,11 +14,11 @@ import (
"storj.io/common/uuid"
"storj.io/private/process"
"storj.io/storj/satellite"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
"storj.io/storj/satellite/satellitedb"
)
func runBillingCmd(ctx context.Context, cmdFunc func(context.Context, *stripecoinpayments.Service, satellite.DB) error) error {
func runBillingCmd(ctx context.Context, cmdFunc func(context.Context, *stripe.Service, satellite.DB) error) error {
// Open SatelliteDB for the Payment Service
logger := zap.L()
db, err := satellitedb.Open(ctx, logger.Named("db"), runCfg.Database, satellitedb.Options{ApplicationName: "satellite-billing"})
@ -37,18 +37,18 @@ func runBillingCmd(ctx context.Context, cmdFunc func(context.Context, *stripecoi
return cmdFunc(ctx, payments, db)
}
func setupPayments(log *zap.Logger, db satellite.DB) (*stripecoinpayments.Service, error) {
func setupPayments(log *zap.Logger, db satellite.DB) (*stripe.Service, error) {
pc := runCfg.Payments
var stripeClient stripecoinpayments.StripeClient
var stripeClient stripe.Client
switch pc.Provider {
case "": // just new mock, only used in testing binaries
stripeClient = stripecoinpayments.NewStripeMock(
stripeClient = stripe.NewStripeMock(
db.StripeCoinPayments().Customers(),
db.Console().Users(),
)
case "stripecoinpayments":
stripeClient = stripecoinpayments.NewStripeClient(log, pc.StripeCoinPayments)
stripeClient = stripe.NewStripeClient(log, pc.StripeCoinPayments)
default:
return nil, errs.New("invalid stripe coin payments provider %q", pc.Provider)
}
@ -63,7 +63,7 @@ func setupPayments(log *zap.Logger, db satellite.DB) (*stripecoinpayments.Servic
return nil, err
}
return stripecoinpayments.NewService(
return stripe.NewService(
log.Named("payments.stripe:service"),
stripeClient,
pc.StripeCoinPayments,
@ -99,7 +99,7 @@ type userData struct {
// generateStripeCustomers creates missing stripe-customers for users in our database.
func generateStripeCustomers(ctx context.Context) (err error) {
return runBillingCmd(ctx, func(ctx context.Context, payments *stripecoinpayments.Service, db satellite.DB) error {
return runBillingCmd(ctx, func(ctx context.Context, payments *stripe.Service, db satellite.DB) error {
accounts := payments.Accounts()
cusDB := db.StripeCoinPayments().Customers().Raw()
@ -137,7 +137,7 @@ func generateStripeCustomers(ctx context.Context) (err error) {
func cmdApplyFreeTierCoupons(cmd *cobra.Command, args []string) (err error) {
ctx, _ := process.Ctx(cmd)
return runBillingCmd(ctx, func(ctx context.Context, payments *stripecoinpayments.Service, _ satellite.DB) error {
return runBillingCmd(ctx, func(ctx context.Context, payments *stripe.Service, _ satellite.DB) error {
return payments.ApplyFreeTierCoupons(ctx)
})
}

View File

@ -41,7 +41,7 @@ import (
"storj.io/storj/satellite/compensation"
"storj.io/storj/satellite/metabase"
"storj.io/storj/satellite/overlay"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
"storj.io/storj/satellite/satellitedb"
)
@ -754,7 +754,7 @@ func cmdPrepareCustomerInvoiceRecords(cmd *cobra.Command, args []string) (err er
return err
}
return runBillingCmd(ctx, func(ctx context.Context, payments *stripecoinpayments.Service, _ satellite.DB) error {
return runBillingCmd(ctx, func(ctx context.Context, payments *stripe.Service, _ satellite.DB) error {
return payments.PrepareInvoiceProjectRecords(ctx, periodStart)
})
}
@ -767,7 +767,7 @@ func cmdCreateCustomerProjectInvoiceItems(cmd *cobra.Command, args []string) (er
return err
}
return runBillingCmd(ctx, func(ctx context.Context, payments *stripecoinpayments.Service, _ satellite.DB) error {
return runBillingCmd(ctx, func(ctx context.Context, payments *stripe.Service, _ satellite.DB) error {
return payments.InvoiceApplyProjectRecords(ctx, periodStart)
})
}
@ -780,7 +780,7 @@ func cmdCreateCustomerInvoices(cmd *cobra.Command, args []string) (err error) {
return err
}
return runBillingCmd(ctx, func(ctx context.Context, payments *stripecoinpayments.Service, _ satellite.DB) error {
return runBillingCmd(ctx, func(ctx context.Context, payments *stripe.Service, _ satellite.DB) error {
return payments.CreateInvoices(ctx, periodStart)
})
}
@ -793,7 +793,7 @@ func cmdGenerateCustomerInvoices(cmd *cobra.Command, args []string) (err error)
return err
}
return runBillingCmd(ctx, func(ctx context.Context, payments *stripecoinpayments.Service, _ satellite.DB) error {
return runBillingCmd(ctx, func(ctx context.Context, payments *stripe.Service, _ satellite.DB) error {
return payments.GenerateInvoices(ctx, periodStart)
})
}
@ -801,7 +801,7 @@ func cmdGenerateCustomerInvoices(cmd *cobra.Command, args []string) (err error)
func cmdFinalizeCustomerInvoices(cmd *cobra.Command, args []string) (err error) {
ctx, _ := process.Ctx(cmd)
return runBillingCmd(ctx, func(ctx context.Context, payments *stripecoinpayments.Service, _ satellite.DB) error {
return runBillingCmd(ctx, func(ctx context.Context, payments *stripe.Service, _ satellite.DB) error {
return payments.FinalizeInvoices(ctx)
})
}
@ -814,7 +814,7 @@ func cmdPayCustomerInvoices(cmd *cobra.Command, args []string) (err error) {
return err
}
return runBillingCmd(ctx, func(ctx context.Context, payments *stripecoinpayments.Service, _ satellite.DB) error {
return runBillingCmd(ctx, func(ctx context.Context, payments *stripe.Service, _ satellite.DB) error {
err := payments.InvoiceApplyTokenBalance(ctx, periodStart)
if err != nil {
return errs.New("error applying native token payments: %v", err)

View File

@ -58,7 +58,7 @@ import (
"storj.io/storj/satellite/overlay"
"storj.io/storj/satellite/overlay/offlinenodes"
"storj.io/storj/satellite/overlay/straynodes"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
"storj.io/storj/satellite/repair/checker"
"storj.io/storj/satellite/repair/repairer"
"storj.io/storj/satellite/reputation"
@ -522,7 +522,7 @@ func (planet *Planet) newSatellite(ctx context.Context, prefix string, index int
planet.databases = append(planet.databases, liveAccounting)
config.Payments.Provider = "mock"
config.Payments.MockProvider = stripecoinpayments.NewStripeMock(db.StripeCoinPayments().Customers(), db.Console().Users())
config.Payments.MockProvider = stripe.NewStripeMock(db.StripeCoinPayments().Customers(), db.Console().Users())
peer, err := satellite.New(log, identity, db, metabaseDB, revocationDB, liveAccounting, versionInfo, &config, nil)
if err != nil {

View File

@ -27,7 +27,7 @@ import (
"storj.io/storj/satellite/console/restkeys"
"storj.io/storj/satellite/metabase"
"storj.io/storj/satellite/payments"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
)
// Admin is the satellite core process that runs chores.
@ -55,8 +55,8 @@ type Admin struct {
Payments struct {
Accounts payments.Accounts
Service *stripecoinpayments.Service
Stripe stripecoinpayments.StripeClient
Service *stripe.Service
Stripe stripe.Client
}
Admin struct {
@ -138,17 +138,17 @@ func NewAdmin(log *zap.Logger, full *identity.FullIdentity, db DB, metabaseDB *m
{ // setup payments
pc := config.Payments
var stripeClient stripecoinpayments.StripeClient
var stripeClient stripe.Client
switch pc.Provider {
case "": // just new mock, only used in testing binaries
stripeClient = stripecoinpayments.NewStripeMock(
stripeClient = stripe.NewStripeMock(
peer.DB.StripeCoinPayments().Customers(),
peer.DB.Console().Users(),
)
case "mock":
stripeClient = pc.MockProvider
case "stripecoinpayments":
stripeClient = stripecoinpayments.NewStripeClient(log, pc.StripeCoinPayments)
stripeClient = stripe.NewStripeClient(log, pc.StripeCoinPayments)
default:
return nil, errs.New("invalid stripe coin payments provider %q", pc.Provider)
}
@ -163,7 +163,7 @@ func NewAdmin(log *zap.Logger, full *identity.FullIdentity, db DB, metabaseDB *m
return nil, errs.Combine(err, peer.Close())
}
peer.Payments.Service, err = stripecoinpayments.NewService(
peer.Payments.Service, err = stripe.NewService(
peer.Log.Named("payments.stripe:service"),
stripeClient,
pc.StripeCoinPayments,

View File

@ -21,7 +21,7 @@ import (
"storj.io/common/storj"
"storj.io/common/uuid"
"storj.io/storj/satellite/console"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
)
func (server *Server) checkProjectUsage(w http.ResponseWriter, r *http.Request) {
@ -508,7 +508,7 @@ func (server *Server) checkInvoicing(ctx context.Context, w http.ResponseWriter,
// Check if an invoice project record exists already
err := server.db.StripeCoinPayments().ProjectRecords().Check(ctx, projectID, firstOfMonth.AddDate(0, -1, 0), firstOfMonth)
if errors.Is(err, stripecoinpayments.ErrProjectRecordExists) {
if errors.Is(err, stripe.ErrProjectRecordExists) {
record, err := server.db.StripeCoinPayments().ProjectRecords().Get(ctx, projectID, firstOfMonth.AddDate(0, -1, 0), firstOfMonth)
if err != nil {
sendJSONError(w, "unable to get project records", err.Error(), http.StatusInternalServerError)
@ -569,7 +569,7 @@ func (server *Server) checkUsage(ctx context.Context, w http.ResponseWriter, pro
}
if lastMonthUsage.Storage > 0 || lastMonthUsage.Egress > 0 || lastMonthUsage.SegmentCount > 0 {
err = server.db.StripeCoinPayments().ProjectRecords().Check(ctx, projectID, firstOfMonth.AddDate(0, -1, 0), firstOfMonth)
if !errors.Is(err, stripecoinpayments.ErrProjectRecordExists) {
if !errors.Is(err, stripe.ErrProjectRecordExists) {
sendJSONError(w, "usage for last month exist, but is not billed yet", "", http.StatusConflict)
return true
}

View File

@ -25,7 +25,7 @@ import (
"storj.io/storj/satellite"
"storj.io/storj/satellite/accounting"
"storj.io/storj/satellite/console"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
)
func TestProjectGet(t *testing.T) {
@ -840,7 +840,7 @@ func TestProjectDelete_withUsagePreviousMonthCharged(t *testing.T) {
// Create Invoice Record for last month.
firstOfMonth := time.Date(now.Year(), now.Month()-1, 1, 0, 0, 0, 0, time.UTC)
err = planet.Satellites[0].DB.StripeCoinPayments().ProjectRecords().Create(ctx,
[]stripecoinpayments.CreateProjectRecord{{
[]stripe.CreateProjectRecord{{
ProjectID: projectID,
Storage: 100,
Egress: 100,

View File

@ -27,7 +27,7 @@ import (
"storj.io/storj/satellite/console/restkeys"
"storj.io/storj/satellite/oidc"
"storj.io/storj/satellite/payments"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
)
// Config defines configuration for debug server.
@ -54,7 +54,7 @@ type DB interface {
// OIDC returns the database for OIDC and OAuth information.
OIDC() oidc.DB
// StripeCoinPayments returns database for satellite stripe coin payments
StripeCoinPayments() stripecoinpayments.DB
StripeCoinPayments() stripe.DB
}
// Server provides endpoints for administrative tasks.

View File

@ -50,7 +50,7 @@ import (
"storj.io/storj/satellite/overlay"
"storj.io/storj/satellite/payments"
"storj.io/storj/satellite/payments/storjscan"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
"storj.io/storj/satellite/reputation"
"storj.io/storj/satellite/snopayouts"
)
@ -138,8 +138,8 @@ type API struct {
StorjscanService *storjscan.Service
StorjscanClient *storjscan.Client
StripeService *stripecoinpayments.Service
StripeClient stripecoinpayments.StripeClient
StripeService *stripe.Service
StripeClient stripe.Client
}
REST struct {
@ -519,17 +519,17 @@ func NewAPI(log *zap.Logger, full *identity.FullIdentity, db DB,
{ // setup payments
pc := config.Payments
var stripeClient stripecoinpayments.StripeClient
var stripeClient stripe.Client
switch pc.Provider {
case "": // just new mock, only used in testing binaries
stripeClient = stripecoinpayments.NewStripeMock(
stripeClient = stripe.NewStripeMock(
peer.DB.StripeCoinPayments().Customers(),
peer.DB.Console().Users(),
)
case "mock":
stripeClient = pc.MockProvider
case "stripecoinpayments":
stripeClient = stripecoinpayments.NewStripeClient(log, pc.StripeCoinPayments)
stripeClient = stripe.NewStripeClient(log, pc.StripeCoinPayments)
default:
return nil, errs.New("invalid stripe coin payments provider %q", pc.Provider)
}
@ -544,7 +544,7 @@ func NewAPI(log *zap.Logger, full *identity.FullIdentity, db DB,
return nil, errs.Combine(err, peer.Close())
}
peer.Payments.StripeService, err = stripecoinpayments.NewService(
peer.Payments.StripeService, err = stripe.NewService(
peer.Log.Named("payments.stripe:service"),
stripeClient,
pc.StripeCoinPayments,

View File

@ -20,7 +20,7 @@ import (
"storj.io/storj/satellite"
"storj.io/storj/satellite/console"
"storj.io/storj/satellite/payments"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
)
func Test_PurchasePackage(t *testing.T) {
@ -32,7 +32,7 @@ func Test_PurchasePackage(t *testing.T) {
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
config.Console.OpenRegistrationEnabled = true
config.Console.RateLimit.Burst = 10
config.Payments.StripeCoinPayments.StripeFreeTierCouponID = stripecoinpayments.MockCouponID1
config.Payments.StripeCoinPayments.StripeFreeTierCouponID = stripe.MockCouponID1
config.Payments.PackagePlans.Packages = map[string]payments.PackagePlan{
partner: {Credit: 2000, Price: 1000},
}
@ -52,11 +52,11 @@ func Test_PurchasePackage(t *testing.T) {
http.StatusNotFound,
},
{
"Add credit card fails", stripecoinpayments.TestPaymentMethodsNewFailure, partner,
"Add credit card fails", stripe.TestPaymentMethodsNewFailure, partner,
http.StatusInternalServerError,
},
{
"Purchase fails", stripecoinpayments.MockInvoicesPayFailure, partner,
"Purchase fails", stripe.MockInvoicesPayFailure, partner,
http.StatusInternalServerError,
},
{

View File

@ -29,7 +29,7 @@ import (
"storj.io/storj/satellite/mailservice"
"storj.io/storj/satellite/payments"
"storj.io/storj/satellite/payments/paymentsconfig"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
)
// discardSender discard sending of an actual email.
@ -79,9 +79,9 @@ func TestGraphqlMutation(t *testing.T) {
priceOverrides, err := pc.UsagePriceOverrides.ToModels()
require.NoError(t, err)
paymentsService, err := stripecoinpayments.NewService(
paymentsService, err := stripe.NewService(
log.Named("payments.stripe:service"),
stripecoinpayments.NewStripeMock(
stripe.NewStripeMock(
db.StripeCoinPayments().Customers(),
db.Console().Users(),
),

View File

@ -26,7 +26,7 @@ import (
"storj.io/storj/satellite/mailservice"
"storj.io/storj/satellite/payments"
"storj.io/storj/satellite/payments/paymentsconfig"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
)
func TestGraphqlQuery(t *testing.T) {
@ -63,9 +63,9 @@ func TestGraphqlQuery(t *testing.T) {
priceOverrides, err := pc.UsagePriceOverrides.ToModels()
require.NoError(t, err)
paymentsService, err := stripecoinpayments.NewService(
paymentsService, err := stripe.NewService(
log.Named("payments.stripe:service"),
stripecoinpayments.NewStripeMock(
stripe.NewStripeMock(
db.StripeCoinPayments().Customers(),
db.Console().Users(),
),

View File

@ -33,7 +33,7 @@ import (
"storj.io/storj/satellite/payments/coinpayments"
"storj.io/storj/satellite/payments/storjscan"
"storj.io/storj/satellite/payments/storjscan/blockchaintest"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
)
func TestService(t *testing.T) {
@ -41,7 +41,7 @@ func TestService(t *testing.T) {
SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 2,
Reconfigure: testplanet.Reconfigure{
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
config.Payments.StripeCoinPayments.StripeFreeTierCouponID = stripecoinpayments.MockCouponID1
config.Payments.StripeCoinPayments.StripeFreeTierCouponID = stripe.MockCouponID1
},
},
},
@ -109,7 +109,7 @@ func TestService(t *testing.T) {
// stripecoinpayments.TestPaymentMethodsAttachFailure triggers the underlying mock stripe client to return an error
// when attaching a payment method to a customer.
_, err = service.Payments().AddCreditCard(userCtx1, stripecoinpayments.TestPaymentMethodsAttachFailure)
_, err = service.Payments().AddCreditCard(userCtx1, stripe.TestPaymentMethodsAttachFailure)
require.Error(t, err)
// user still in free tier
@ -465,7 +465,7 @@ func TestService(t *testing.T) {
// testplanet applies the free tier coupon first, so we need to change it in order
// to verify that ApplyFreeTierCoupon really works.
freeTier := sat.Config.Payments.StripeCoinPayments.StripeFreeTierCouponID
coupon3, err := service.Payments().ApplyCoupon(userCtx1, stripecoinpayments.MockCouponID3)
coupon3, err := service.Payments().ApplyCoupon(userCtx1, stripe.MockCouponID3)
require.NoError(t, err)
require.NotNil(t, coupon3)
require.NotEqual(t, freeTier, coupon3.ID)
@ -486,7 +486,7 @@ func TestService(t *testing.T) {
require.Nil(t, coupon)
})
t.Run("ApplyCoupon", func(t *testing.T) {
id := stripecoinpayments.MockCouponID2
id := stripe.MockCouponID2
coupon, err := service.Payments().ApplyCoupon(userCtx2, id)
require.NoError(t, err)
require.NotNil(t, coupon)
@ -497,7 +497,7 @@ func TestService(t *testing.T) {
require.Equal(t, id, coupon.ID)
})
t.Run("ApplyCoupon fails with unknown user", func(t *testing.T) {
id := stripecoinpayments.MockCouponID2
id := stripe.MockCouponID2
coupon, err := service.Payments().ApplyCoupon(ctx, id)
require.Error(t, err)
require.Nil(t, coupon)
@ -531,7 +531,7 @@ func TestService(t *testing.T) {
check()
})
t.Run("ApplyCredit fails when payments.Balances.ApplyCredit returns an error", func(t *testing.T) {
require.Error(t, service.Payments().ApplyCredit(userCtx1, 1000, stripecoinpayments.MockCBTXsNewFailure))
require.Error(t, service.Payments().ApplyCredit(userCtx1, 1000, stripe.MockCBTXsNewFailure))
btxs, err := sat.API.Payments.Accounts.Balances().ListTransactions(ctx, up1Pro1.OwnerID)
require.NoError(t, err)
require.Zero(t, len(btxs))
@ -1492,9 +1492,9 @@ func TestPaymentsWalletPayments(t *testing.T) {
err = sat.DB.Wallets().Add(ctx, user.ID, wallet)
require.NoError(t, err)
var transactions []stripecoinpayments.Transaction
var transactions []stripe.Transaction
for i := 0; i < 5; i++ {
tx := stripecoinpayments.Transaction{
tx := stripe.Transaction{
ID: coinpayments.TransactionID(fmt.Sprintf("%d", i)),
AccountID: user.ID,
Address: blockchaintest.NewAddress().Hex(),
@ -1606,7 +1606,7 @@ func TestPaymentsPurchase(t *testing.T) {
},
{
"Purchase returns error when underlying payments.Invoices.New returns error",
stripecoinpayments.MockInvoicesNewFailure,
stripe.MockInvoicesNewFailure,
testPaymentMethod,
true,
userCtx,
@ -1614,7 +1614,7 @@ func TestPaymentsPurchase(t *testing.T) {
{
"Purchase returns error when underlying payments.Invoices.Pay returns error",
testDesc,
stripecoinpayments.MockInvoicesPayFailure,
stripe.MockInvoicesPayFailure,
true,
userCtx,
},
@ -1691,7 +1691,7 @@ func TestPaymentsPurchasePreexistingInvoice(t *testing.T) {
openInv := inv.ID
// attempting to pay a draft invoice changes it to open if payment fails
_, err = sat.API.Payments.StripeService.Accounts().Invoices().Pay(ctx, inv.ID, stripecoinpayments.MockInvoicesPayFailure)
_, err = sat.API.Payments.StripeService.Accounts().Invoices().Pay(ctx, inv.ID, stripe.MockInvoicesPayFailure)
require.Error(t, err)
invs, err = sat.API.Payments.StripeService.Accounts().Invoices().List(ctx, user.ID)

View File

@ -49,7 +49,7 @@ import (
"storj.io/storj/satellite/payments/accountfreeze"
"storj.io/storj/satellite/payments/billing"
"storj.io/storj/satellite/payments/storjscan"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
"storj.io/storj/satellite/repair/checker"
"storj.io/storj/satellite/reputation"
)
@ -502,17 +502,17 @@ func New(log *zap.Logger, full *identity.FullIdentity, db DB,
{ // setup payments
pc := config.Payments
var stripeClient stripecoinpayments.StripeClient
var stripeClient stripe.Client
switch pc.Provider {
case "": // just new mock, only used in testing binaries
stripeClient = stripecoinpayments.NewStripeMock(
stripeClient = stripe.NewStripeMock(
peer.DB.StripeCoinPayments().Customers(),
peer.DB.Console().Users(),
)
case "mock":
stripeClient = pc.MockProvider
case "stripecoinpayments":
stripeClient = stripecoinpayments.NewStripeClient(log, pc.StripeCoinPayments)
stripeClient = stripe.NewStripeClient(log, pc.StripeCoinPayments)
default:
return nil, errs.New("invalid stripe coin payments provider %q", pc.Provider)
}
@ -527,7 +527,7 @@ func New(log *zap.Logger, full *identity.FullIdentity, db DB,
return nil, errs.Combine(err, peer.Close())
}
service, err := stripecoinpayments.NewService(
service, err := stripe.NewService(
peer.Log.Named("payments.stripe:service"),
stripeClient,
pc.StripeCoinPayments,

View File

@ -16,7 +16,7 @@ import (
"storj.io/storj/satellite/analytics"
"storj.io/storj/satellite/console"
"storj.io/storj/satellite/payments"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
)
var (
@ -40,14 +40,14 @@ type Chore struct {
analytics *analytics.Service
usersDB console.Users
payments payments.Accounts
accounts stripecoinpayments.DB
accounts stripe.DB
config Config
nowFn func() time.Time
Loop *sync2.Cycle
}
// NewChore is a constructor for Chore.
func NewChore(log *zap.Logger, accounts stripecoinpayments.DB, payments payments.Accounts, usersDB console.Users, freezeService *console.AccountFreezeService, analytics *analytics.Service, config Config) *Chore {
func NewChore(log *zap.Logger, accounts stripe.DB, payments payments.Accounts, usersDB console.Users, freezeService *console.AccountFreezeService, analytics *analytics.Service, config Config) *Chore {
return &Chore{
log: log,
freezeService: freezeService,

View File

@ -15,7 +15,7 @@ import (
"storj.io/storj/private/testplanet"
"storj.io/storj/satellite"
"storj.io/storj/satellite/console"
"storj.io/storj/satellite/payments/stripecoinpayments"
stripe1 "storj.io/storj/satellite/payments/stripe"
)
func TestAutoFreezeChore(t *testing.T) {
@ -126,7 +126,7 @@ func TestAutoFreezeChore(t *testing.T) {
})
require.NoError(t, err)
paymentMethod := stripecoinpayments.MockInvoicesPayFailure
paymentMethod := stripe1.MockInvoicesPayFailure
inv, err = stripeClient.Invoices().Pay(inv.ID, &stripe.InvoicePayParams{
Params: stripe.Params{Context: ctx},
PaymentMethod: &paymentMethod,

View File

@ -16,7 +16,7 @@ import (
"storj.io/storj/satellite/payments"
"storj.io/storj/satellite/payments/billing"
"storj.io/storj/satellite/payments/storjscan"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
)
// Error is payments config err class.
@ -24,11 +24,11 @@ var Error = errs.Class("payments config")
// Config defines global payments config.
type Config struct {
Provider string `help:"payments provider to use" default:""`
MockProvider stripecoinpayments.StripeClient `internal:"true"`
Provider string `help:"payments provider to use" default:""`
MockProvider stripe.Client `internal:"true"`
BillingConfig billing.Config
StripeCoinPayments stripecoinpayments.Config
StripeCoinPayments stripe.Config
Storjscan storjscan.Config
UsagePrice ProjectUsagePrice
BonusRate int64 `help:"amount of percents that user will earn as bonus credits by depositing in STORJ tokens" default:"10"`

View File

@ -1,7 +1,7 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments
package stripe
import (
"context"

View File

@ -1,7 +1,7 @@
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments_test
package stripe_test
import (
"testing"
@ -21,7 +21,7 @@ import (
"storj.io/storj/satellite/console/restkeys"
"storj.io/storj/satellite/payments"
"storj.io/storj/satellite/payments/paymentsconfig"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
)
func TestSignupCouponCodes(t *testing.T) {
@ -57,9 +57,9 @@ func TestSignupCouponCodes(t *testing.T) {
priceOverrides, err := pc.UsagePriceOverrides.ToModels()
require.NoError(t, err)
paymentsService, err := stripecoinpayments.NewService(
paymentsService, err := stripe.NewService(
log.Named("payments.stripe:service"),
stripecoinpayments.NewStripeMock(
stripe.NewStripeMock(
db.StripeCoinPayments().Customers(),
db.Console().Users(),
),

View File

@ -1,7 +1,7 @@
// Copyright (C) 2023 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments
package stripe
import (
"context"

View File

@ -1,7 +1,7 @@
// Copyright (C) 2023 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments_test
package stripe_test
import (
"testing"
@ -11,7 +11,7 @@ import (
"storj.io/common/testcontext"
"storj.io/storj/private/testplanet"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
)
func TestBalances(t *testing.T) {
@ -65,7 +65,7 @@ func TestBalances(t *testing.T) {
require.Equal(t, tx3Amount, list[2].Amount)
require.Equal(t, tx3Desc, list[2].Description)
b, err = balances.ApplyCredit(ctx, userID, tx2Amount, stripecoinpayments.MockCBTXsNewFailure)
b, err = balances.ApplyCredit(ctx, userID, tx2Amount, stripe.MockCBTXsNewFailure)
require.Error(t, err)
require.Nil(t, b)

View File

@ -1,7 +1,7 @@
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments
package stripe
import (
"bytes"
@ -26,35 +26,35 @@ import (
"storj.io/common/time2"
)
// StripeClient Stripe client interface.
type StripeClient interface {
Customers() StripeCustomers
PaymentMethods() StripePaymentMethods
Invoices() StripeInvoices
InvoiceItems() StripeInvoiceItems
CustomerBalanceTransactions() StripeCustomerBalanceTransactions
Charges() StripeCharges
PromoCodes() StripePromoCodes
CreditNotes() StripeCreditNotes
// Client Stripe client interface.
type Client interface {
Customers() Customers
PaymentMethods() PaymentMethods
Invoices() Invoices
InvoiceItems() InvoiceItems
CustomerBalanceTransactions() CustomerBalanceTransactions
Charges() Charges
PromoCodes() PromoCodes
CreditNotes() CreditNotes
}
// StripeCustomers Stripe Customers interface.
type StripeCustomers interface {
// Customers Stripe Customers interface.
type Customers 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)
}
// StripePaymentMethods Stripe PaymentMethods interface.
type StripePaymentMethods interface {
// PaymentMethods Stripe PaymentMethods interface.
type PaymentMethods 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)
}
// StripeInvoices Stripe Invoices interface.
type StripeInvoices interface {
// Invoices Stripe Invoices interface.
type Invoices interface {
New(params *stripe.InvoiceParams) (*stripe.Invoice, error)
List(listParams *stripe.InvoiceListParams) *invoice.Iter
Update(id string, params *stripe.InvoiceParams) (*stripe.Invoice, error)
@ -63,32 +63,32 @@ type StripeInvoices interface {
Del(id string, params *stripe.InvoiceParams) (*stripe.Invoice, error)
}
// StripeInvoiceItems Stripe InvoiceItems interface.
type StripeInvoiceItems interface {
// InvoiceItems Stripe InvoiceItems interface.
type InvoiceItems 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)
}
// StripeCharges Stripe Charges interface.
type StripeCharges interface {
// Charges Stripe Charges interface.
type Charges interface {
List(listParams *stripe.ChargeListParams) *charge.Iter
}
// StripePromoCodes is the Stripe PromoCodes interface.
type StripePromoCodes interface {
// PromoCodes is the Stripe PromoCodes interface.
type PromoCodes interface {
List(params *stripe.PromotionCodeListParams) *promotioncode.Iter
}
// StripeCustomerBalanceTransactions Stripe CustomerBalanceTransactions interface.
type StripeCustomerBalanceTransactions interface {
// CustomerBalanceTransactions Stripe CustomerBalanceTransactions interface.
type CustomerBalanceTransactions interface {
New(params *stripe.CustomerBalanceTransactionParams) (*stripe.CustomerBalanceTransaction, error)
List(listParams *stripe.CustomerBalanceTransactionListParams) *customerbalancetransaction.Iter
}
// StripeCreditNotes Stripe CreditNotes interface.
type StripeCreditNotes interface {
// CreditNotes Stripe CreditNotes interface.
type CreditNotes interface {
New(params *stripe.CreditNoteParams) (*stripe.CreditNote, error)
}
@ -96,40 +96,40 @@ type stripeClient struct {
client *client.API
}
func (s *stripeClient) Customers() StripeCustomers {
func (s *stripeClient) Customers() Customers {
return s.client.Customers
}
func (s *stripeClient) PaymentMethods() StripePaymentMethods {
func (s *stripeClient) PaymentMethods() PaymentMethods {
return s.client.PaymentMethods
}
func (s *stripeClient) Invoices() StripeInvoices {
func (s *stripeClient) Invoices() Invoices {
return s.client.Invoices
}
func (s *stripeClient) InvoiceItems() StripeInvoiceItems {
func (s *stripeClient) InvoiceItems() InvoiceItems {
return s.client.InvoiceItems
}
func (s *stripeClient) CustomerBalanceTransactions() StripeCustomerBalanceTransactions {
func (s *stripeClient) CustomerBalanceTransactions() CustomerBalanceTransactions {
return s.client.CustomerBalanceTransactions
}
func (s *stripeClient) Charges() StripeCharges {
func (s *stripeClient) Charges() Charges {
return s.client.Charges
}
func (s *stripeClient) PromoCodes() StripePromoCodes {
func (s *stripeClient) PromoCodes() PromoCodes {
return s.client.PromotionCodes
}
func (s *stripeClient) CreditNotes() StripeCreditNotes {
func (s *stripeClient) CreditNotes() CreditNotes {
return s.client.CreditNotes
}
// NewStripeClient creates Stripe client from configuration.
func NewStripeClient(log *zap.Logger, config Config) StripeClient {
func NewStripeClient(log *zap.Logger, config Config) Client {
sClient := client.New(config.StripeSecretKey,
&stripe.Backends{
API: NewBackendWrapper(log, stripe.APIBackend, config.Retries),

View File

@ -1,7 +1,7 @@
// Copyright (C) 2023 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments_test
package stripe_test
import (
"bytes"
@ -17,7 +17,7 @@ import (
"storj.io/common/testcontext"
"storj.io/common/time2"
"storj.io/storj/satellite/payments/stripecoinpayments"
stripe1 "storj.io/storj/satellite/payments/stripe"
)
var backendError = &stripe.Error{
@ -56,13 +56,13 @@ func (b *mockBackend) SetMaxNetworkRetries(max int64) {}
func TestBackendWrapper(t *testing.T) {
tm := time2.NewMachine()
retryCfg := stripecoinpayments.RetryConfig{
retryCfg := stripe1.RetryConfig{
InitialBackoff: time.Millisecond,
MaxBackoff: 3 * time.Millisecond,
Multiplier: 2,
MaxRetries: 5,
}
backend := stripecoinpayments.NewBackendWrapper(zaptest.NewLogger(t), stripe.APIBackend, retryCfg)
backend := stripe1.NewBackendWrapper(zaptest.NewLogger(t), stripe.APIBackend, retryCfg)
mock := &mockBackend{}
backend.TestSwapBackend(mock)
backend.TestSwapClock(tm.Clock())

View File

@ -1,7 +1,7 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments
package stripe
import (
"github.com/shopspring/decimal"

View File

@ -1,7 +1,7 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments
package stripe
import (
"context"

View File

@ -1,7 +1,7 @@
// Copyright (C) 2023 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments_test
package stripe_test
import (
"testing"
@ -13,7 +13,7 @@ import (
"storj.io/common/testrand"
"storj.io/storj/private/testplanet"
"storj.io/storj/satellite"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
)
func TestCoupons(t *testing.T) {
@ -21,7 +21,7 @@ func TestCoupons(t *testing.T) {
SatelliteCount: 1, StorageNodeCount: 0, UplinkCount: 1,
Reconfigure: testplanet.Reconfigure{
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
config.Payments.StripeCoinPayments.StripeFreeTierCouponID = stripecoinpayments.MockCouponID1
config.Payments.StripeCoinPayments.StripeFreeTierCouponID = stripe.MockCouponID1
},
},
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
@ -35,12 +35,12 @@ func TestCoupons(t *testing.T) {
require.Nil(t, coupon)
})
t.Run("ApplyCoupon fails with no matching customer", func(t *testing.T) {
coupon, err := c.ApplyCoupon(ctx, testrand.UUID(), stripecoinpayments.MockCouponID2)
coupon, err := c.ApplyCoupon(ctx, testrand.UUID(), stripe.MockCouponID2)
require.Error(t, err)
require.Nil(t, coupon)
})
t.Run("ApplyCoupon, GetByUserID succeeds", func(t *testing.T) {
id := stripecoinpayments.MockCouponID1
id := stripe.MockCouponID1
coupon, err := c.ApplyCoupon(ctx, userID, id)
require.NoError(t, err)
require.NotNil(t, coupon)

View File

@ -1,7 +1,7 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments
package stripe
import (
"context"

View File

@ -1,7 +1,7 @@
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments_test
package stripe_test
import (
"fmt"
@ -12,7 +12,7 @@ import (
"storj.io/common/testcontext"
"storj.io/storj/private/testplanet"
"storj.io/storj/satellite/console"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
)
func TestCreditCards_List(t *testing.T) {
@ -46,12 +46,12 @@ func TestCreditCards_Add(t *testing.T) {
},
{
"Add returns error when StripePaymentMethods.New fails",
stripecoinpayments.TestPaymentMethodsNewFailure,
stripe.TestPaymentMethodsNewFailure,
true,
},
{
"Add returns error when StripePaymentMethods.Attach fails",
stripecoinpayments.TestPaymentMethodsAttachFailure,
stripe.TestPaymentMethodsAttachFailure,
true,
},
}

View File

@ -1,7 +1,7 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments
package stripe
import (
"context"

View File

@ -1,7 +1,7 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments_test
package stripe_test
import (
"strconv"
@ -14,7 +14,7 @@ import (
"storj.io/common/testcontext"
"storj.io/common/uuid"
"storj.io/storj/satellite"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
"storj.io/storj/satellite/satellitedb/satellitedbtest"
)
@ -54,7 +54,7 @@ func TestCustomersRepositoryList(t *testing.T) {
userID, err := uuid.New()
require.NoError(t, err)
cus := stripecoinpayments.Customer{
cus := stripe.Customer{
ID: "customerID" + strconv.Itoa(i),
UserID: userID,
}

View File

@ -1,7 +1,7 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments
package stripe
// DB is stripecoinpayments DB interface.
//

View File

@ -1,7 +1,7 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments
package stripe
import (
"context"

View File

@ -1,7 +1,7 @@
// Copyright (C) 2023 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments_test
package stripe_test
import (
"testing"
@ -12,7 +12,7 @@ import (
"storj.io/common/testcontext"
"storj.io/common/testrand"
"storj.io/storj/private/testplanet"
"storj.io/storj/satellite/payments/stripecoinpayments"
stripe1 "storj.io/storj/satellite/payments/stripe"
)
func TestInvoices(t *testing.T) {
@ -30,7 +30,7 @@ func TestInvoices(t *testing.T) {
require.Nil(t, pi)
})
t.Run("Create returns error when underlying StripeInvoices.Create returns error", func(t *testing.T) {
pi, err := satellite.API.Payments.Accounts.Invoices().Create(ctx, testrand.UUID(), price, stripecoinpayments.MockInvoicesNewFailure)
pi, err := satellite.API.Payments.Accounts.Invoices().Create(ctx, testrand.UUID(), price, stripe1.MockInvoicesNewFailure)
require.Error(t, err)
require.Nil(t, pi)
})
@ -54,7 +54,7 @@ func TestInvoices(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, pi)
confirmedPI, err := satellite.API.Payments.Accounts.Invoices().Pay(ctx, pi.ID, stripecoinpayments.MockInvoicesPayFailure)
confirmedPI, err := satellite.API.Payments.Accounts.Invoices().Pay(ctx, pi.ID, stripe1.MockInvoicesPayFailure)
require.Error(t, err)
require.Nil(t, confirmedPI)
})

View File

@ -1,7 +1,7 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments
package stripe
import (
"context"

View File

@ -1,7 +1,7 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments_test
package stripe_test
import (
"testing"
@ -13,7 +13,7 @@ import (
"storj.io/common/testcontext"
"storj.io/common/uuid"
"storj.io/storj/satellite"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
"storj.io/storj/satellite/satellitedb/satellitedbtest"
)
@ -31,7 +31,7 @@ func TestProjectRecords(t *testing.T) {
t.Run("create", func(t *testing.T) {
err = projectRecordsDB.Create(ctx,
[]stripecoinpayments.CreateProjectRecord{
[]stripe.CreateProjectRecord{
{
ProjectID: prjID,
Storage: 1,
@ -47,7 +47,7 @@ func TestProjectRecords(t *testing.T) {
t.Run("check", func(t *testing.T) {
err = projectRecordsDB.Check(ctx, prjID, start, end)
require.Error(t, err)
assert.Equal(t, stripecoinpayments.ErrProjectRecordExists, err)
assert.Equal(t, stripe.ErrProjectRecordExists, err)
})
page, err := projectRecordsDB.ListUnapplied(ctx, 0, 1, start, end)
@ -77,13 +77,13 @@ func TestProjectRecordsList(t *testing.T) {
const limit = 5
const recordsLen = limit * 4
var createProjectRecords []stripecoinpayments.CreateProjectRecord
var createProjectRecords []stripe.CreateProjectRecord
for i := 0; i < recordsLen; i++ {
projID, err := uuid.New()
require.NoError(t, err)
createProjectRecords = append(createProjectRecords,
stripecoinpayments.CreateProjectRecord{
stripe.CreateProjectRecord{
ProjectID: projID,
Storage: float64(i) + 1,
Egress: int64(i) + 2,

View File

@ -1,7 +1,7 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments
package stripe
import (
"context"
@ -65,7 +65,7 @@ type Service struct {
projectsDB console.Projects
usersDB console.Users
usageDB accounting.ProjectAccounting
stripeClient StripeClient
stripeClient Client
usagePrices payments.ProjectUsagePriceModel
usagePriceOverrides map[string]payments.ProjectUsagePriceModel
@ -86,7 +86,7 @@ type Service struct {
}
// NewService creates a Service instance.
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) {
func NewService(log *zap.Logger, stripeClient Client, 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) {
var partners []string
for partner := range usagePriceOverrides {
partners = append(partners, partner)

View File

@ -1,7 +1,7 @@
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments_test
package stripe_test
import (
"context"
@ -32,7 +32,7 @@ import (
"storj.io/storj/satellite/payments"
"storj.io/storj/satellite/payments/billing"
"storj.io/storj/satellite/payments/paymentsconfig"
"storj.io/storj/satellite/payments/stripecoinpayments"
stripe1 "storj.io/storj/satellite/payments/stripe"
)
func TestService_InvoiceElementsProcessing(t *testing.T) {
@ -413,7 +413,7 @@ func TestService_GenerateInvoice(t *testing.T) {
Reconfigure: testplanet.Reconfigure{
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
config.Payments.StripeCoinPayments.SkipEmptyInvoices = testCase.skipEmptyInvoices
config.Payments.StripeCoinPayments.StripeFreeTierCouponID = stripecoinpayments.MockCouponID1
config.Payments.StripeCoinPayments.StripeFreeTierCouponID = stripe1.MockCouponID1
},
},
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
@ -465,7 +465,7 @@ func TestService_GenerateInvoice(t *testing.T) {
// ensure project record was generated
err = satellite.DB.StripeCoinPayments().ProjectRecords().Check(ctx, proj.ID, start, end)
require.ErrorIs(t, stripecoinpayments.ErrProjectRecordExists, err)
require.ErrorIs(t, stripe1.ErrProjectRecordExists, err)
rec, err := satellite.DB.StripeCoinPayments().ProjectRecords().Get(ctx, proj.ID, start, end)
require.NotNil(t, rec)
@ -497,7 +497,7 @@ func TestService_GenerateInvoice(t *testing.T) {
}
}
func getCustomerInvoice(ctx context.Context, stripeClient stripecoinpayments.StripeClient, cusID string) (*stripe.Invoice, bool) {
func getCustomerInvoice(ctx context.Context, stripeClient stripe1.Client, cusID string) (*stripe.Invoice, bool) {
iter := stripeClient.Invoices().List(&stripe.InvoiceListParams{
ListParams: stripe.ListParams{Context: ctx},
Customer: &cusID,
@ -508,7 +508,7 @@ func getCustomerInvoice(ctx context.Context, stripeClient stripecoinpayments.Str
return nil, false
}
func getCustomerInvoiceItems(ctx context.Context, stripeClient stripecoinpayments.StripeClient, cusID string) (items []*stripe.InvoiceItem) {
func getCustomerInvoiceItems(ctx context.Context, stripeClient stripe1.Client, cusID string) (items []*stripe.InvoiceItem) {
iter := stripeClient.InvoiceItems().List(&stripe.InvoiceItemListParams{
ListParams: stripe.ListParams{Context: ctx},
Customer: &cusID,

View File

@ -1,7 +1,7 @@
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments
package stripe
import (
"context"
@ -127,7 +127,7 @@ var mockEmptyQuery = stripe.Query(func(*stripe.Params, *form.Values) ([]interfac
// 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().
func NewStripeMock(customersDB CustomersDB, usersDB console.Users) StripeClient {
func NewStripeMock(customersDB CustomersDB, usersDB console.Users) Client {
state := &mockStripeState{}
state.customers = &mockCustomersState{}
state.paymentMethods = newMockPaymentMethods(state)
@ -144,7 +144,7 @@ func NewStripeMock(customersDB CustomersDB, usersDB console.Users) StripeClient
}
}
func (m *mockStripeClient) Customers() StripeCustomers {
func (m *mockStripeClient) Customers() Customers {
m.mu.Lock()
defer m.mu.Unlock()
return &mockCustomers{
@ -157,31 +157,31 @@ func (m *mockStripeClient) Customers() StripeCustomers {
}
}
func (m *mockStripeClient) PaymentMethods() StripePaymentMethods {
func (m *mockStripeClient) PaymentMethods() PaymentMethods {
return m.paymentMethods
}
func (m *mockStripeClient) Invoices() StripeInvoices {
func (m *mockStripeClient) Invoices() Invoices {
return m.invoices
}
func (m *mockStripeClient) InvoiceItems() StripeInvoiceItems {
func (m *mockStripeClient) InvoiceItems() InvoiceItems {
return m.invoiceItems
}
func (m *mockStripeClient) CustomerBalanceTransactions() StripeCustomerBalanceTransactions {
func (m *mockStripeClient) CustomerBalanceTransactions() CustomerBalanceTransactions {
return m.customerBalanceTransactions
}
func (m *mockStripeClient) Charges() StripeCharges {
func (m *mockStripeClient) Charges() Charges {
return m.charges
}
func (m *mockStripeClient) PromoCodes() StripePromoCodes {
func (m *mockStripeClient) PromoCodes() PromoCodes {
return m.promoCodes
}
func (m *mockStripeClient) CreditNotes() StripeCreditNotes {
func (m *mockStripeClient) CreditNotes() CreditNotes {
return m.creditNotes
}

View File

@ -1,7 +1,7 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments
package stripe
import (
"context"

View File

@ -1,7 +1,7 @@
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments_test
package stripe_test
import (
"encoding/base64"
@ -18,7 +18,7 @@ import (
"storj.io/storj/private/testplanet"
"storj.io/storj/satellite/payments"
"storj.io/storj/satellite/payments/coinpayments"
"storj.io/storj/satellite/payments/stripecoinpayments"
stripe1 "storj.io/storj/satellite/payments/stripe"
)
func TestTokens_ListDepositBonuses(t *testing.T) {
@ -43,7 +43,7 @@ func TestTokens_ListDepositBonuses(t *testing.T) {
Params: stripe.Params{Context: ctx},
Customer: stripe.String(customerID),
Amount: stripe.Int64(-1000),
Description: stripe.String(stripecoinpayments.StripeDepositTransactionDescription),
Description: stripe.String(stripe1.StripeDepositTransactionDescription),
}
txParams.AddMetadata("txID", txID)
_, err = satellite.API.Payments.StripeClient.CustomerBalanceTransactions().New(&txParams)
@ -54,7 +54,7 @@ func TestTokens_ListDepositBonuses(t *testing.T) {
Params: stripe.Params{Context: ctx},
Customer: stripe.String(customerID),
Amount: stripe.Int64(-130),
Description: stripe.String(stripecoinpayments.StripeDepositBonusTransactionDescription),
Description: stripe.String(stripe1.StripeDepositBonusTransactionDescription),
}
txParams.AddMetadata("txID", txID)
txParams.AddMetadata("percentage", "13")

View File

@ -1,7 +1,7 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments
package stripe
import (
"context"

View File

@ -1,7 +1,7 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package stripecoinpayments_test
package stripe_test
import (
"encoding/base64"
@ -19,7 +19,7 @@ import (
"storj.io/common/uuid"
"storj.io/storj/satellite"
"storj.io/storj/satellite/payments/coinpayments"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
"storj.io/storj/satellite/satellitedb/satellitedbtest"
)
@ -33,7 +33,7 @@ func TestTransactionsDB(t *testing.T) {
require.NoError(t, err)
userID := testrand.UUID()
createTx := stripecoinpayments.Transaction{
createTx := stripe.Transaction{
ID: "testID",
AccountID: userID,
Address: "testAddress",
@ -79,13 +79,13 @@ func TestTransactionsDBList(t *testing.T) {
received, err := currency.AmountFromString("5.0000000000000000003", currency.StorjToken)
require.NoError(t, err)
var txs []stripecoinpayments.Transaction
var txs []stripe.Transaction
for i := 0; i < transactionCount; i++ {
id := base64.StdEncoding.EncodeToString(testrand.Bytes(4 * memory.B))
addr := base64.StdEncoding.EncodeToString(testrand.Bytes(4 * memory.B))
key := base64.StdEncoding.EncodeToString(testrand.Bytes(4 * memory.B))
createTX := stripecoinpayments.Transaction{
createTX := stripe.Transaction{
ID: coinpayments.TransactionID(id),
AccountID: uuid.UUID{},
Address: addr,
@ -141,7 +141,7 @@ func TestTransactionsDBRates(t *testing.T) {
// compareTransactions is a helper method to compare tx used to create db entry,
// with the tx returned from the db. Method doesn't compare created at field, but
// ensures that is not empty.
func compareTransactions(t *testing.T, exp, act stripecoinpayments.Transaction) {
func compareTransactions(t *testing.T, exp, act stripe.Transaction) {
assert.Equal(t, exp.ID, act.ID)
assert.Equal(t, exp.AccountID, act.AccountID)
assert.Equal(t, exp.Address, act.Address)

View File

@ -62,7 +62,7 @@ import (
"storj.io/storj/satellite/payments/billing"
"storj.io/storj/satellite/payments/paymentsconfig"
"storj.io/storj/satellite/payments/storjscan"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
"storj.io/storj/satellite/repair/checker"
"storj.io/storj/satellite/repair/queue"
"storj.io/storj/satellite/repair/repairer"
@ -121,7 +121,7 @@ type DB interface {
// GracefulExit returns database for graceful exit
GracefulExit() gracefulexit.DB
// StripeCoinPayments returns stripecoinpayments database.
StripeCoinPayments() stripecoinpayments.DB
StripeCoinPayments() stripe.DB
// Billing returns storjscan transactions database.
Billing() billing.TransactionsDB
// Wallets returns storjscan wallets database.

View File

@ -13,12 +13,12 @@ import (
"storj.io/common/currency"
"storj.io/common/uuid"
"storj.io/storj/satellite/payments/coinpayments"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
"storj.io/storj/satellite/satellitedb/dbx"
)
// ensure that coinpaymentsTransactions implements stripecoinpayments.TransactionsDB.
var _ stripecoinpayments.TransactionsDB = (*coinPaymentsTransactions)(nil)
var _ stripe.TransactionsDB = (*coinPaymentsTransactions)(nil)
// coinPaymentsTransactions is CoinPayments transactions DB.
//
@ -43,7 +43,7 @@ func (db *coinPaymentsTransactions) GetLockedRate(ctx context.Context, id coinpa
}
// ListAccount returns all transaction for specific user.
func (db *coinPaymentsTransactions) ListAccount(ctx context.Context, userID uuid.UUID) (_ []stripecoinpayments.Transaction, err error) {
func (db *coinPaymentsTransactions) ListAccount(ctx context.Context, userID uuid.UUID) (_ []stripe.Transaction, err error) {
defer mon.Task()(&ctx)(&err)
dbxTXs, err := db.db.All_CoinpaymentsTransaction_By_UserId_OrderBy_Desc_CreatedAt(ctx,
@ -53,7 +53,7 @@ func (db *coinPaymentsTransactions) ListAccount(ctx context.Context, userID uuid
return nil, err
}
var txs []stripecoinpayments.Transaction
var txs []stripe.Transaction
for _, dbxTX := range dbxTXs {
tx, err := fromDBXCoinpaymentsTransaction(dbxTX)
if err != nil {
@ -67,7 +67,7 @@ func (db *coinPaymentsTransactions) ListAccount(ctx context.Context, userID uuid
}
// TestInsert inserts new coinpayments transaction into DB.
func (db *coinPaymentsTransactions) TestInsert(ctx context.Context, tx stripecoinpayments.Transaction) (createTime time.Time, err error) {
func (db *coinPaymentsTransactions) TestInsert(ctx context.Context, tx stripe.Transaction) (createTime time.Time, err error) {
defer mon.Task()(&ctx)(&err)
dbxCPTX, err := db.db.Create_CoinpaymentsTransaction(ctx,
@ -127,7 +127,7 @@ func (db *coinPaymentsTransactions) TestLockRate(ctx context.Context, id coinpay
}
// fromDBXCoinpaymentsTransaction converts *dbx.CoinpaymentsTransaction to *stripecoinpayments.Transaction.
func fromDBXCoinpaymentsTransaction(dbxCPTX *dbx.CoinpaymentsTransaction) (*stripecoinpayments.Transaction, error) {
func fromDBXCoinpaymentsTransaction(dbxCPTX *dbx.CoinpaymentsTransaction) (*stripe.Transaction, error) {
userID, err := uuid.FromBytes(dbxCPTX.UserId)
if err != nil {
return nil, errs.Wrap(err)
@ -136,7 +136,7 @@ func fromDBXCoinpaymentsTransaction(dbxCPTX *dbx.CoinpaymentsTransaction) (*stri
// TODO: the currency here should be passed in to this function or stored
// in the database.
return &stripecoinpayments.Transaction{
return &stripe.Transaction{
ID: coinpayments.TransactionID(dbxCPTX.Id),
AccountID: userID,
Address: dbxCPTX.Address,

View File

@ -10,12 +10,12 @@ import (
"time"
"storj.io/common/uuid"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
"storj.io/storj/satellite/satellitedb/dbx"
)
// ensures that customers implements stripecoinpayments.CustomersDB.
var _ stripecoinpayments.CustomersDB = (*customers)(nil)
var _ stripe.CustomersDB = (*customers)(nil)
// customers is an implementation of stripecoinpayments.CustomersDB.
//
@ -50,7 +50,7 @@ func (customers *customers) GetCustomerID(ctx context.Context, userID uuid.UUID)
idRow, err := customers.db.Get_StripeCustomer_CustomerId_By_UserId(ctx, dbx.StripeCustomer_UserId(userID[:]))
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return "", stripecoinpayments.ErrNoCustomer
return "", stripe.ErrNoCustomer
}
return "", err
@ -66,7 +66,7 @@ func (customers *customers) GetUserID(ctx context.Context, customerID string) (_
idRow, err := customers.db.Get_StripeCustomer_UserId_By_CustomerId(ctx, dbx.StripeCustomer_CustomerId(customerID))
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return uuid.UUID{}, stripecoinpayments.ErrNoCustomer
return uuid.UUID{}, stripe.ErrNoCustomer
}
return uuid.UUID{}, err
@ -76,10 +76,10 @@ func (customers *customers) GetUserID(ctx context.Context, customerID string) (_
}
// List returns paginated customers id list, with customers created before specified date.
func (customers *customers) List(ctx context.Context, offset int64, limit int, before time.Time) (_ stripecoinpayments.CustomersPage, err error) {
func (customers *customers) List(ctx context.Context, offset int64, limit int, before time.Time) (_ stripe.CustomersPage, err error) {
defer mon.Task()(&ctx)(&err)
var page stripecoinpayments.CustomersPage
var page stripe.CustomersPage
dbxCustomers, err := customers.db.Limited_StripeCustomer_By_CreatedAt_LessOrEqual_OrderBy_Desc_CreatedAt(ctx,
dbx.StripeCustomer_CreatedAt(before),
@ -87,7 +87,7 @@ func (customers *customers) List(ctx context.Context, offset int64, limit int, b
offset,
)
if err != nil {
return stripecoinpayments.CustomersPage{}, err
return stripe.CustomersPage{}, err
}
if len(dbxCustomers) == limit+1 {
@ -100,7 +100,7 @@ func (customers *customers) List(ctx context.Context, offset int64, limit int, b
for _, dbxCustomer := range dbxCustomers {
cus, err := fromDBXCustomer(dbxCustomer)
if err != nil {
return stripecoinpayments.CustomersPage{}, err
return stripe.CustomersPage{}, err
}
page.Customers = append(page.Customers, *cus)
@ -110,7 +110,7 @@ func (customers *customers) List(ctx context.Context, offset int64, limit int, b
}
// UpdatePackage updates the customer's package plan and purchase time.
func (customers *customers) UpdatePackage(ctx context.Context, userID uuid.UUID, packagePlan *string, timestamp *time.Time) (c *stripecoinpayments.Customer, err error) {
func (customers *customers) UpdatePackage(ctx context.Context, userID uuid.UUID, packagePlan *string, timestamp *time.Time) (c *stripe.Customer, err error) {
defer mon.Task()(&ctx)(&err)
updateFields := dbx.StripeCustomer_Update_Fields{
@ -146,13 +146,13 @@ func (customers *customers) GetPackageInfo(ctx context.Context, userID uuid.UUID
}
// fromDBXCustomer converts *dbx.StripeCustomer to *stripecoinpayments.Customer.
func fromDBXCustomer(dbxCustomer *dbx.StripeCustomer) (*stripecoinpayments.Customer, error) {
func fromDBXCustomer(dbxCustomer *dbx.StripeCustomer) (*stripe.Customer, error) {
userID, err := uuid.FromBytes(dbxCustomer.UserId)
if err != nil {
return nil, err
}
return &stripecoinpayments.Customer{
return &stripe.Customer{
ID: dbxCustomer.CustomerId,
UserID: userID,
PackagePlan: dbxCustomer.PackagePlan,

View File

@ -30,7 +30,7 @@ import (
"storj.io/storj/satellite/overlay"
"storj.io/storj/satellite/payments/billing"
"storj.io/storj/satellite/payments/storjscan"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
"storj.io/storj/satellite/repair/queue"
"storj.io/storj/satellite/reputation"
"storj.io/storj/satellite/revocation"
@ -270,7 +270,7 @@ func (dbc *satelliteDBCollection) GracefulExit() gracefulexit.DB {
}
// StripeCoinPayments returns database for stripecoinpayments.
func (dbc *satelliteDBCollection) StripeCoinPayments() stripecoinpayments.DB {
func (dbc *satelliteDBCollection) StripeCoinPayments() stripe.DB {
return &stripeCoinPaymentsDB{db: dbc.getByName("stripecoinpayments")}
}

View File

@ -12,12 +12,12 @@ import (
"github.com/zeebo/errs"
"storj.io/common/uuid"
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
"storj.io/storj/satellite/satellitedb/dbx"
)
// ensure that invoiceProjectRecords implements stripecoinpayments.ProjectRecordsDB.
var _ stripecoinpayments.ProjectRecordsDB = (*invoiceProjectRecords)(nil)
var _ stripe.ProjectRecordsDB = (*invoiceProjectRecords)(nil)
// invoiceProjectRecordState defines states of the invoice project record.
type invoiceProjectRecordState int
@ -42,7 +42,7 @@ type invoiceProjectRecords struct {
}
// Create creates new invoice project record in the DB.
func (db *invoiceProjectRecords) Create(ctx context.Context, records []stripecoinpayments.CreateProjectRecord, start, end time.Time) (err error) {
func (db *invoiceProjectRecords) Create(ctx context.Context, records []stripe.CreateProjectRecord, start, end time.Time) (err error) {
defer mon.Task()(&ctx)(&err)
return db.db.WithTx(ctx, func(ctx context.Context, tx *dbx.Tx) error {
@ -91,11 +91,11 @@ func (db *invoiceProjectRecords) Check(ctx context.Context, projectID uuid.UUID,
return err
}
return stripecoinpayments.ErrProjectRecordExists
return stripe.ErrProjectRecordExists
}
// Get returns record for specified project and billing period.
func (db *invoiceProjectRecords) Get(ctx context.Context, projectID uuid.UUID, start, end time.Time) (record *stripecoinpayments.ProjectRecord, err error) {
func (db *invoiceProjectRecords) Get(ctx context.Context, projectID uuid.UUID, start, end time.Time) (record *stripe.ProjectRecord, err error) {
defer mon.Task()(&ctx)(&err)
dbxRecord, err := db.db.Get_StripecoinpaymentsInvoiceProjectRecord_By_ProjectId_And_PeriodStart_And_PeriodEnd(ctx,
@ -129,10 +129,10 @@ func (db *invoiceProjectRecords) Consume(ctx context.Context, id uuid.UUID) (err
}
// ListUnapplied returns project records page with unapplied project records.
func (db *invoiceProjectRecords) ListUnapplied(ctx context.Context, offset int64, limit int, start, end time.Time) (_ stripecoinpayments.ProjectRecordsPage, err error) {
func (db *invoiceProjectRecords) ListUnapplied(ctx context.Context, offset int64, limit int, start, end time.Time) (_ stripe.ProjectRecordsPage, err error) {
defer mon.Task()(&ctx)(&err)
var page stripecoinpayments.ProjectRecordsPage
var page stripe.ProjectRecordsPage
dbxRecords, err := db.db.Limited_StripecoinpaymentsInvoiceProjectRecord_By_PeriodStart_And_PeriodEnd_And_State(ctx,
dbx.StripecoinpaymentsInvoiceProjectRecord_PeriodStart(start),
@ -142,7 +142,7 @@ func (db *invoiceProjectRecords) ListUnapplied(ctx context.Context, offset int64
offset,
)
if err != nil {
return stripecoinpayments.ProjectRecordsPage{}, err
return stripe.ProjectRecordsPage{}, err
}
if len(dbxRecords) == limit+1 {
@ -155,7 +155,7 @@ func (db *invoiceProjectRecords) ListUnapplied(ctx context.Context, offset int64
for _, dbxRecord := range dbxRecords {
record, err := fromDBXInvoiceProjectRecord(dbxRecord)
if err != nil {
return stripecoinpayments.ProjectRecordsPage{}, err
return stripe.ProjectRecordsPage{}, err
}
page.Records = append(page.Records, *record)
@ -165,7 +165,7 @@ func (db *invoiceProjectRecords) ListUnapplied(ctx context.Context, offset int64
}
// fromDBXInvoiceProjectRecord converts *dbx.StripecoinpaymentsInvoiceProjectRecord to *stripecoinpayments.ProjectRecord.
func fromDBXInvoiceProjectRecord(dbxRecord *dbx.StripecoinpaymentsInvoiceProjectRecord) (*stripecoinpayments.ProjectRecord, error) {
func fromDBXInvoiceProjectRecord(dbxRecord *dbx.StripecoinpaymentsInvoiceProjectRecord) (*stripe.ProjectRecord, error) {
id, err := uuid.FromBytes(dbxRecord.Id)
if err != nil {
return nil, errs.Wrap(err)
@ -180,7 +180,7 @@ func fromDBXInvoiceProjectRecord(dbxRecord *dbx.StripecoinpaymentsInvoiceProject
segments = float64(*dbxRecord.Segments)
}
return &stripecoinpayments.ProjectRecord{
return &stripe.ProjectRecord{
ID: id,
ProjectID: projectID,
Storage: dbxRecord.Storage,

View File

@ -4,11 +4,11 @@
package satellitedb
import (
"storj.io/storj/satellite/payments/stripecoinpayments"
"storj.io/storj/satellite/payments/stripe"
)
// ensures that *stripeCoinPaymentsDB implements stripecoinpayments.DB.
var _ stripecoinpayments.DB = (*stripeCoinPaymentsDB)(nil)
var _ stripe.DB = (*stripeCoinPaymentsDB)(nil)
// stripeCoinPaymentsDB is stripecoinpayments DB.
//
@ -18,16 +18,16 @@ type stripeCoinPaymentsDB struct {
}
// Customers is getter for customers db.
func (db *stripeCoinPaymentsDB) Customers() stripecoinpayments.CustomersDB {
func (db *stripeCoinPaymentsDB) Customers() stripe.CustomersDB {
return &customers{db: db.db}
}
// Transactions is getter for transactions db.
func (db *stripeCoinPaymentsDB) Transactions() stripecoinpayments.TransactionsDB {
func (db *stripeCoinPaymentsDB) Transactions() stripe.TransactionsDB {
return &coinPaymentsTransactions{db: db.db}
}
// ProjectRecords is getter for invoice project records db.
func (db *stripeCoinPaymentsDB) ProjectRecords() stripecoinpayments.ProjectRecordsDB {
func (db *stripeCoinPaymentsDB) ProjectRecords() stripe.ProjectRecordsDB {
return &invoiceProjectRecords{db: db.db}
}