2019-11-04 10:54:25 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package mockpayments
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-03-04 13:23:10 +00:00
|
|
|
"time"
|
2019-11-04 10:54:25 +00:00
|
|
|
|
|
|
|
"github.com/skyrings/skyring-common/tools/uuid"
|
2019-11-08 20:40:39 +00:00
|
|
|
"github.com/spacemonkeygo/monkit/v3"
|
2019-11-04 10:54:25 +00:00
|
|
|
"github.com/zeebo/errs"
|
|
|
|
|
2020-01-18 02:34:06 +00:00
|
|
|
"storj.io/common/memory"
|
2019-11-04 10:54:25 +00:00
|
|
|
"storj.io/storj/satellite/payments"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// Error defines mock payment service error.
|
|
|
|
Error = errs.Class("mock payment service error")
|
|
|
|
|
|
|
|
mon = monkit.Package()
|
|
|
|
)
|
|
|
|
|
2019-11-12 11:14:34 +00:00
|
|
|
var _ payments.Accounts = (*accounts)(nil)
|
|
|
|
|
2019-11-04 10:54:25 +00:00
|
|
|
// accounts is a mock implementation of payments.Accounts.
|
2020-01-29 00:57:15 +00:00
|
|
|
//
|
|
|
|
// architecture: Service
|
2019-11-04 10:54:25 +00:00
|
|
|
type accounts struct{}
|
|
|
|
|
2019-11-12 11:14:34 +00:00
|
|
|
var _ payments.CreditCards = (*creditCards)(nil)
|
|
|
|
|
2019-11-04 10:54:25 +00:00
|
|
|
// creditCards is a mock implementation of payments.CreditCards.
|
2020-01-29 00:57:15 +00:00
|
|
|
//
|
|
|
|
// architecture: Service
|
2019-11-04 10:54:25 +00:00
|
|
|
type creditCards struct{}
|
|
|
|
|
2019-11-12 11:14:34 +00:00
|
|
|
var _ payments.Invoices = (*invoices)(nil)
|
|
|
|
|
2019-11-04 10:54:25 +00:00
|
|
|
// invoices is a mock implementation of payments.Invoices.
|
2020-01-29 00:57:15 +00:00
|
|
|
//
|
|
|
|
// architecture: Service
|
2019-11-04 10:54:25 +00:00
|
|
|
type invoices struct{}
|
|
|
|
|
2019-11-12 11:14:34 +00:00
|
|
|
var _ payments.StorjTokens = (*storjTokens)(nil)
|
|
|
|
|
2019-11-04 10:54:25 +00:00
|
|
|
// storjTokens is a mock implementation of payments.StorjTokens.
|
2020-01-29 00:57:15 +00:00
|
|
|
//
|
|
|
|
// architecture: Service
|
2019-11-04 10:54:25 +00:00
|
|
|
type storjTokens struct{}
|
|
|
|
|
2020-01-29 00:57:15 +00:00
|
|
|
// ensures that coupons implements payments.Coupons.
|
|
|
|
var _ payments.Coupons = (*coupons)(nil)
|
|
|
|
|
|
|
|
// coupons is an implementation of payments.Coupons.
|
|
|
|
//
|
|
|
|
// architecture: Service
|
|
|
|
type coupons struct{}
|
|
|
|
|
2020-01-24 13:38:53 +00:00
|
|
|
// ensures that credits implements payments.Credits.
|
|
|
|
var _ payments.Credits = (*credits)(nil)
|
|
|
|
|
|
|
|
// credits is an implementation of payments.Credits.
|
|
|
|
//
|
|
|
|
// architecture: Service
|
|
|
|
type credits struct{}
|
|
|
|
|
2019-11-04 10:54:25 +00:00
|
|
|
// Accounts exposes all needed functionality to manage payment accounts.
|
|
|
|
func Accounts() payments.Accounts {
|
|
|
|
return &accounts{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreditCards exposes all needed functionality to manage account credit cards.
|
|
|
|
func (accounts *accounts) CreditCards() payments.CreditCards {
|
|
|
|
return &creditCards{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Invoices exposes all needed functionality to manage account invoices.
|
|
|
|
func (accounts *accounts) Invoices() payments.Invoices {
|
|
|
|
return &invoices{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// StorjTokens exposes all storj token related functionality.
|
|
|
|
func (accounts *accounts) StorjTokens() payments.StorjTokens {
|
|
|
|
return &storjTokens{}
|
|
|
|
}
|
|
|
|
|
2020-01-29 00:57:15 +00:00
|
|
|
// Coupons exposes all needed functionality to manage coupons.
|
|
|
|
func (accounts *accounts) Coupons() payments.Coupons {
|
|
|
|
return &coupons{}
|
|
|
|
}
|
|
|
|
|
2020-01-24 13:38:53 +00:00
|
|
|
// Credits exposes all needed functionality to manage coupons.
|
|
|
|
func (accounts *accounts) Credits() payments.Credits {
|
|
|
|
return &credits{}
|
|
|
|
}
|
|
|
|
|
2019-11-04 10:54:25 +00:00
|
|
|
// Setup creates a payment account for the user.
|
|
|
|
// If account is already set up it will return nil.
|
|
|
|
func (accounts *accounts) Setup(ctx context.Context, userID uuid.UUID, email string) (err error) {
|
|
|
|
defer mon.Task()(&ctx, userID, email)(&err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Balance returns an integer amount in cents that represents the current balance of payment account.
|
|
|
|
func (accounts *accounts) Balance(ctx context.Context, userID uuid.UUID) (_ int64, err error) {
|
|
|
|
defer mon.Task()(&ctx, userID)(&err)
|
|
|
|
|
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
|
2019-11-15 14:27:44 +00:00
|
|
|
// ProjectCharges returns how much money current user will be charged for each project.
|
2020-03-04 13:23:10 +00:00
|
|
|
func (accounts *accounts) ProjectCharges(ctx context.Context, userID uuid.UUID, since, before time.Time) (charges []payments.ProjectCharge, err error) {
|
|
|
|
defer mon.Task()(&ctx, userID, since, before)(&err)
|
2019-11-15 14:27:44 +00:00
|
|
|
|
|
|
|
return []payments.ProjectCharge{}, nil
|
2020-01-03 14:21:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Charges returns empty charges list.
|
|
|
|
func (accounts accounts) Charges(ctx context.Context, userID uuid.UUID) (_ []payments.Charge, err error) {
|
|
|
|
defer mon.Task()(&ctx, userID)(&err)
|
|
|
|
return []payments.Charge{}, nil
|
2019-11-15 14:27:44 +00:00
|
|
|
}
|
|
|
|
|
2019-11-04 10:54:25 +00:00
|
|
|
// List returns a list of credit cards for a given payment account.
|
|
|
|
func (creditCards *creditCards) List(ctx context.Context, userID uuid.UUID) (_ []payments.CreditCard, err error) {
|
|
|
|
defer mon.Task()(&ctx, userID)(&err)
|
|
|
|
|
2020-03-16 19:34:15 +00:00
|
|
|
return []payments.CreditCard{{
|
|
|
|
ID: "pm_card_mastercard",
|
|
|
|
ExpMonth: 12,
|
|
|
|
ExpYear: 2050,
|
|
|
|
Brand: "Mastercard",
|
|
|
|
Last4: "4444",
|
|
|
|
IsDefault: true,
|
|
|
|
}}, nil
|
2019-11-04 10:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add is used to save new credit card, attach it to payment account and make it default.
|
|
|
|
func (creditCards *creditCards) Add(ctx context.Context, userID uuid.UUID, cardToken string) (err error) {
|
|
|
|
defer mon.Task()(&ctx, userID, cardToken)(&err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// MakeDefault makes a credit card default payment method.
|
|
|
|
func (creditCards *creditCards) MakeDefault(ctx context.Context, userID uuid.UUID, cardID string) (err error) {
|
|
|
|
defer mon.Task()(&ctx, userID, cardID)(&err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove is used to remove credit card from payment account.
|
|
|
|
func (creditCards *creditCards) Remove(ctx context.Context, userID uuid.UUID, cardID string) (err error) {
|
|
|
|
defer mon.Task()(&ctx, cardID)(&err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// List returns a list of invoices for a given payment account.
|
|
|
|
func (invoices *invoices) List(ctx context.Context, userID uuid.UUID) (_ []payments.Invoice, err error) {
|
|
|
|
defer mon.Task()(&ctx, userID)(&err)
|
|
|
|
|
|
|
|
return []payments.Invoice{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deposit creates new deposit transaction.
|
2019-11-21 14:25:37 +00:00
|
|
|
func (tokens *storjTokens) Deposit(ctx context.Context, userID uuid.UUID, amount int64) (_ *payments.Transaction, err error) {
|
2019-11-04 10:54:25 +00:00
|
|
|
defer mon.Task()(&ctx, userID, amount)(&err)
|
|
|
|
|
|
|
|
return nil, Error.Wrap(errs.New("can not make deposit"))
|
|
|
|
}
|
2019-11-12 11:14:34 +00:00
|
|
|
|
|
|
|
// ListTransactionInfos returns empty transaction infos slice.
|
|
|
|
func (tokens *storjTokens) ListTransactionInfos(ctx context.Context, userID uuid.UUID) (_ []payments.TransactionInfo, err error) {
|
|
|
|
defer mon.Task()(&ctx, userID)(&err)
|
|
|
|
return ([]payments.TransactionInfo)(nil), nil
|
|
|
|
}
|
2020-01-29 00:57:15 +00:00
|
|
|
|
|
|
|
// Create attaches a coupon for payment account.
|
|
|
|
func (coupons *coupons) Create(ctx context.Context, coupon payments.Coupon) (err error) {
|
|
|
|
defer mon.Task()(&ctx, coupon)(&err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListByUserID return list of all coupons of specified payment account.
|
|
|
|
func (coupons *coupons) ListByUserID(ctx context.Context, userID uuid.UUID) (_ []payments.Coupon, err error) {
|
|
|
|
defer mon.Task()(&ctx, userID)(&err)
|
|
|
|
|
|
|
|
return ([]payments.Coupon)(nil), Error.Wrap(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// PopulatePromotionalCoupons is used to populate promotional coupons through all active users who already have
|
|
|
|
// a project, payment method and do not have a promotional coupon yet.
|
|
|
|
// And updates project limits to selected size.
|
|
|
|
func (coupons *coupons) PopulatePromotionalCoupons(ctx context.Context, duration int, amount int64, projectLimit memory.Size) (err error) {
|
|
|
|
defer mon.Task()(&ctx, duration, amount, projectLimit)(&err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddPromotionalCoupon is used to add a promotional coupon for specified users who already have
|
|
|
|
// a project and do not have a promotional coupon yet.
|
|
|
|
// And updates project limits to selected size.
|
2020-03-16 19:34:15 +00:00
|
|
|
func (coupons *coupons) AddPromotionalCoupon(ctx context.Context, userID uuid.UUID) (err error) {
|
|
|
|
defer mon.Task()(&ctx, userID)(&err)
|
2020-01-29 00:57:15 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2020-01-24 13:38:53 +00:00
|
|
|
|
|
|
|
// Create attaches a credit for payment account.
|
|
|
|
func (credits *credits) Create(ctx context.Context, credit payments.Credit) (err error) {
|
|
|
|
defer mon.Task()(&ctx, credit)(&err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListByUserID return list of all credits of specified payment account.
|
|
|
|
func (credits *credits) ListByUserID(ctx context.Context, userID uuid.UUID) (_ []payments.Credit, err error) {
|
|
|
|
defer mon.Task()(&ctx, userID)(&err)
|
|
|
|
|
|
|
|
return ([]payments.Credit)(nil), Error.Wrap(err)
|
|
|
|
}
|