satellite/payments: mock payment service created, api calls from frontend returned (#3448)
This commit is contained in:
parent
3a842bf53f
commit
5cb46d2ce3
@ -42,6 +42,7 @@ import (
|
|||||||
"storj.io/storj/satellite/orders"
|
"storj.io/storj/satellite/orders"
|
||||||
"storj.io/storj/satellite/overlay"
|
"storj.io/storj/satellite/overlay"
|
||||||
"storj.io/storj/satellite/payments"
|
"storj.io/storj/satellite/payments"
|
||||||
|
"storj.io/storj/satellite/payments/mockpayments"
|
||||||
"storj.io/storj/satellite/payments/paymentsconfig"
|
"storj.io/storj/satellite/payments/paymentsconfig"
|
||||||
"storj.io/storj/satellite/payments/stripecoinpayments"
|
"storj.io/storj/satellite/payments/stripecoinpayments"
|
||||||
"storj.io/storj/satellite/repair/irreparable"
|
"storj.io/storj/satellite/repair/irreparable"
|
||||||
@ -364,6 +365,10 @@ func NewAPI(log *zap.Logger, full *identity.FullIdentity, db DB, pointerDB metai
|
|||||||
{ // setup payments
|
{ // setup payments
|
||||||
config := paymentsconfig.Config{}
|
config := paymentsconfig.Config{}
|
||||||
|
|
||||||
|
switch config.Provider {
|
||||||
|
default:
|
||||||
|
peer.Payments.Accounts = mockpayments.Accounts()
|
||||||
|
case "stripecoinpayments":
|
||||||
service := stripecoinpayments.NewService(
|
service := stripecoinpayments.NewService(
|
||||||
peer.Log.Named("stripecoinpayments service"),
|
peer.Log.Named("stripecoinpayments service"),
|
||||||
config.StripeCoinPayments,
|
config.StripeCoinPayments,
|
||||||
@ -377,6 +382,7 @@ func NewAPI(log *zap.Logger, full *identity.FullIdentity, db DB, pointerDB metai
|
|||||||
config.StripeCoinPayments.TransactionUpdateInterval,
|
config.StripeCoinPayments.TransactionUpdateInterval,
|
||||||
config.StripeCoinPayments.AccountBalanceUpdateInterval)
|
config.StripeCoinPayments.AccountBalanceUpdateInterval)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // setup console
|
{ // setup console
|
||||||
log.Debug("Satellite API Process setting up console")
|
log.Debug("Satellite API Process setting up console")
|
||||||
|
111
satellite/payments/mockpayments/mockpayments.go
Normal file
111
satellite/payments/mockpayments/mockpayments.go
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
// Copyright (C) 2019 Storj Labs, Inc.
|
||||||
|
// See LICENSE for copying information.
|
||||||
|
|
||||||
|
package mockpayments
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
|
"github.com/skyrings/skyring-common/tools/uuid"
|
||||||
|
"github.com/zeebo/errs"
|
||||||
|
monkit "gopkg.in/spacemonkeygo/monkit.v2"
|
||||||
|
|
||||||
|
"storj.io/storj/satellite/payments"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Error defines mock payment service error.
|
||||||
|
Error = errs.Class("mock payment service error")
|
||||||
|
|
||||||
|
mon = monkit.Package()
|
||||||
|
)
|
||||||
|
|
||||||
|
// accounts is a mock implementation of payments.Accounts.
|
||||||
|
type accounts struct{}
|
||||||
|
|
||||||
|
// creditCards is a mock implementation of payments.CreditCards.
|
||||||
|
type creditCards struct{}
|
||||||
|
|
||||||
|
// invoices is a mock implementation of payments.Invoices.
|
||||||
|
type invoices struct{}
|
||||||
|
|
||||||
|
// storjTokens is a mock implementation of payments.StorjTokens.
|
||||||
|
type storjTokens struct{}
|
||||||
|
|
||||||
|
// 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{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
|
||||||
|
return []payments.CreditCard{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
func (tokens *storjTokens) Deposit(ctx context.Context, userID uuid.UUID, amount big.Float) (_ *payments.Transaction, err error) {
|
||||||
|
defer mon.Task()(&ctx, userID, amount)(&err)
|
||||||
|
|
||||||
|
return nil, Error.Wrap(errs.New("can not make deposit"))
|
||||||
|
}
|
@ -17,10 +17,12 @@ import (
|
|||||||
"storj.io/storj/satellite/payments/coinpayments"
|
"storj.io/storj/satellite/payments/coinpayments"
|
||||||
)
|
)
|
||||||
|
|
||||||
var mon = monkit.Package()
|
var (
|
||||||
|
|
||||||
// Error defines stripecoinpayments service error.
|
// Error defines stripecoinpayments service error.
|
||||||
var Error = errs.Class("stripecoinpayments service error")
|
Error = errs.Class("stripecoinpayments service error")
|
||||||
|
|
||||||
|
mon = monkit.Package()
|
||||||
|
)
|
||||||
|
|
||||||
// Config stores needed information for payment service initialization.
|
// Config stores needed information for payment service initialization.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
@ -41,6 +41,7 @@ import (
|
|||||||
"storj.io/storj/satellite/orders"
|
"storj.io/storj/satellite/orders"
|
||||||
"storj.io/storj/satellite/overlay"
|
"storj.io/storj/satellite/overlay"
|
||||||
"storj.io/storj/satellite/payments"
|
"storj.io/storj/satellite/payments"
|
||||||
|
"storj.io/storj/satellite/payments/mockpayments"
|
||||||
"storj.io/storj/satellite/payments/paymentsconfig"
|
"storj.io/storj/satellite/payments/paymentsconfig"
|
||||||
"storj.io/storj/satellite/payments/stripecoinpayments"
|
"storj.io/storj/satellite/payments/stripecoinpayments"
|
||||||
"storj.io/storj/satellite/repair/checker"
|
"storj.io/storj/satellite/repair/checker"
|
||||||
@ -384,9 +385,14 @@ func New(log *zap.Logger, full *identity.FullIdentity, db DB, pointerDB metainfo
|
|||||||
peer.Accounting.Rollup = rollup.New(peer.Log.Named("rollup"), peer.DB.StoragenodeAccounting(), config.Rollup.Interval, config.Rollup.DeleteTallies)
|
peer.Accounting.Rollup = rollup.New(peer.Log.Named("rollup"), peer.DB.StoragenodeAccounting(), config.Rollup.Interval, config.Rollup.DeleteTallies)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: remove in future, should be in API
|
||||||
{ // setup payments
|
{ // setup payments
|
||||||
config := paymentsconfig.Config{}
|
config := paymentsconfig.Config{}
|
||||||
|
|
||||||
|
switch config.Provider {
|
||||||
|
default:
|
||||||
|
peer.Payments.Accounts = mockpayments.Accounts()
|
||||||
|
case "stripecoinpayments":
|
||||||
service := stripecoinpayments.NewService(
|
service := stripecoinpayments.NewService(
|
||||||
peer.Log.Named("stripecoinpayments service"),
|
peer.Log.Named("stripecoinpayments service"),
|
||||||
config.StripeCoinPayments,
|
config.StripeCoinPayments,
|
||||||
@ -400,6 +406,7 @@ func New(log *zap.Logger, full *identity.FullIdentity, db DB, pointerDB metainfo
|
|||||||
config.StripeCoinPayments.TransactionUpdateInterval,
|
config.StripeCoinPayments.TransactionUpdateInterval,
|
||||||
config.StripeCoinPayments.AccountBalanceUpdateInterval)
|
config.StripeCoinPayments.AccountBalanceUpdateInterval)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // setup graceful exit
|
{ // setup graceful exit
|
||||||
if config.GracefulExit.Enabled {
|
if config.GracefulExit.Enabled {
|
||||||
|
@ -57,7 +57,7 @@ const {
|
|||||||
export default class AccountBalance extends Vue {
|
export default class AccountBalance extends Vue {
|
||||||
public mounted() {
|
public mounted() {
|
||||||
try {
|
try {
|
||||||
// this.$store.dispatch(GET_BALANCE);
|
this.$store.dispatch(GET_BALANCE);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.$store.dispatch(NOTIFICATION_ACTIONS.ERROR, error.message);
|
this.$store.dispatch(NOTIFICATION_ACTIONS.ERROR, error.message);
|
||||||
}
|
}
|
||||||
|
@ -29,21 +29,21 @@ export default class CardDialog extends Vue {
|
|||||||
this.$store.dispatch(CLEAR_CARDS_SELECTION);
|
this.$store.dispatch(CLEAR_CARDS_SELECTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public async onMakeDefaultClick(): Promise<void> {
|
public async onMakeDefaultClick(): Promise<void> {
|
||||||
// try {
|
try {
|
||||||
// await this.$store.dispatch(MAKE_CARD_DEFAULT, this.cardId);
|
await this.$store.dispatch(MAKE_CARD_DEFAULT, this.cardId);
|
||||||
// } catch (error) {
|
} catch (error) {
|
||||||
// await this.$store.dispatch(NOTIFICATION_ACTIONS.ERROR, error.message);
|
await this.$store.dispatch(NOTIFICATION_ACTIONS.ERROR, error.message);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// public async onRemoveClick(): Promise<void> {
|
public async onRemoveClick(): Promise<void> {
|
||||||
// try {
|
try {
|
||||||
// await this.$store.dispatch(REMOVE_CARD, this.cardId);
|
await this.$store.dispatch(REMOVE_CARD, this.cardId);
|
||||||
// } catch (error) {
|
} catch (error) {
|
||||||
// await this.$store.dispatch(NOTIFICATION_ACTIONS.ERROR, error.message);
|
await this.$store.dispatch(NOTIFICATION_ACTIONS.ERROR, error.message);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
width="123px"
|
width="123px"
|
||||||
height="48px"
|
height="48px"
|
||||||
:on-press="onAddCard"
|
:on-press="onAddCard"
|
||||||
:is-disabled="true"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="payment-methods-area__button-area__cancel" v-if="!isDefaultState" @click="onCancel">
|
<div class="payment-methods-area__button-area__cancel" v-if="!isDefaultState" @click="onCancel">
|
||||||
@ -100,7 +99,7 @@ export default class PaymentMethods extends Vue {
|
|||||||
|
|
||||||
public mounted() {
|
public mounted() {
|
||||||
try {
|
try {
|
||||||
// this.$store.dispatch(GET_CREDIT_CARDS);
|
this.$store.dispatch(GET_CREDIT_CARDS);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.$store.dispatch(NOTIFICATION_ACTIONS.ERROR, error.message);
|
this.$store.dispatch(NOTIFICATION_ACTIONS.ERROR, error.message);
|
||||||
}
|
}
|
||||||
@ -156,7 +155,7 @@ export default class PaymentMethods extends Vue {
|
|||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// await this.$store.dispatch(ADD_CREDIT_CARD, token);
|
await this.$store.dispatch(ADD_CREDIT_CARD, token);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await this.$store.dispatch(NOTIFICATION_ACTIONS.ERROR, error.message);
|
await this.$store.dispatch(NOTIFICATION_ACTIONS.ERROR, error.message);
|
||||||
|
|
||||||
@ -167,7 +166,7 @@ export default class PaymentMethods extends Vue {
|
|||||||
|
|
||||||
await this.$store.dispatch(NOTIFICATION_ACTIONS.SUCCESS, 'Card successfully added');
|
await this.$store.dispatch(NOTIFICATION_ACTIONS.SUCCESS, 'Card successfully added');
|
||||||
try {
|
try {
|
||||||
// await this.$store.dispatch(GET_CREDIT_CARDS);
|
await this.$store.dispatch(GET_CREDIT_CARDS);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await this.$store.dispatch(NOTIFICATION_ACTIONS.ERROR, error.message);
|
await this.$store.dispatch(NOTIFICATION_ACTIONS.ERROR, error.message);
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
|
@ -67,21 +67,21 @@ export default class DashboardArea extends Vue {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// try {
|
try {
|
||||||
// await this.$store.dispatch(SETUP_ACCOUNT);
|
await this.$store.dispatch(SETUP_ACCOUNT);
|
||||||
// await this.$store.dispatch(GET_BALANCE);
|
await this.$store.dispatch(GET_BALANCE);
|
||||||
// await this.$store.dispatch(GET_CREDIT_CARDS);
|
await this.$store.dispatch(GET_CREDIT_CARDS);
|
||||||
// await this.$store.dispatch(GET_BILLING_HISTORY);
|
await this.$store.dispatch(GET_BILLING_HISTORY);
|
||||||
// } catch (error) {
|
} catch (error) {
|
||||||
// if (error instanceof ErrorUnauthorized) {
|
if (error instanceof ErrorUnauthorized) {
|
||||||
// AuthToken.remove();
|
AuthToken.remove();
|
||||||
// await this.$router.push(RouteConfig.Login.path);
|
await this.$router.push(RouteConfig.Login.path);
|
||||||
//
|
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// await this.$notify.error(error.message);
|
await this.$notify.error(error.message);
|
||||||
// }
|
}
|
||||||
|
|
||||||
let projects: Project[] = [];
|
let projects: Project[] = [];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user