storj/satellite/payments/creditcards.go
Wilfred Asomani f7a95e0077 satellite/{payment,console}: add endpoint to add card by pmID
This change introduces a new endpoint that allows adding credit cards
by payment method ID (pmID). The payment method would've already been
created by the frontend using the stripe payment element for example.

Issue: #6436

Change-Id: If9a3f4c98171e36623607968d1a12f29fa7627e9
2023-10-30 13:58:55 +00:00

48 lines
1.7 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package payments
import (
"context"
"storj.io/common/uuid"
)
// CreditCards exposes all needed functionality to manage account credit cards.
//
// architecture: Service
type CreditCards interface {
// List returns a list of credit cards for a given payment account.
List(ctx context.Context, userID uuid.UUID) ([]CreditCard, error)
// Add is used to save new credit card and attach it to payment account.
Add(ctx context.Context, userID uuid.UUID, cardToken string) (CreditCard, error)
// AddByPaymentMethodID is used to save new credit card, attach it to payment account and make it default
// using the payment method id instead of the token. In this case, the payment method should already be
// created by the frontend using stripe elements for example.
AddByPaymentMethodID(ctx context.Context, userID uuid.UUID, pmID string) (CreditCard, error)
// Remove is used to detach a credit card from payment account.
Remove(ctx context.Context, userID uuid.UUID, cardID string) error
// RemoveAll is used to detach all credit cards from payment account.
// It should only be used in case of a user deletion.
RemoveAll(ctx context.Context, userID uuid.UUID) error
// MakeDefault makes a credit card default payment method.
// this credit card should be attached to account before make it default.
MakeDefault(ctx context.Context, userID uuid.UUID, cardID string) error
}
// CreditCard holds all public information about credit card.
type CreditCard struct {
ID string `json:"id"`
ExpMonth int `json:"expMonth"`
ExpYear int `json:"expYear"`
Brand string `json:"brand"`
Last4 string `json:"last4"`
IsDefault bool `json:"isDefault"`
}