satellite/payments: add constants for invoice status

Change-Id: Iaf94d57d99caff3d435a44c56bd47c7b715ff4c0
This commit is contained in:
Cameron 2023-02-11 11:01:28 -05:00 committed by Storj Robot
parent f905878ff9
commit 78e68cdca2
2 changed files with 34 additions and 2 deletions

View File

@ -10,6 +10,19 @@ import (
"storj.io/common/uuid"
)
const (
// InvoiceStatusDraft indicates the invoice is a draft.
InvoiceStatusDraft = "draft"
// InvoiceStatusOpen indicates the invoice is open.
InvoiceStatusOpen = "open"
// InvoiceStatusPaid indicates the invoice is paid.
InvoiceStatusPaid = "paid"
// InvoiceStatusUncollectible indicates the invoice is uncollectible.
InvoiceStatusUncollectible = "uncollectible"
// InvoiceStatusVoid indicates the invoice is void.
InvoiceStatusVoid = "void"
)
// Invoices exposes all needed functionality to manage account invoices.
//
// architecture: Service

View File

@ -90,7 +90,7 @@ func (invoices *invoices) List(ctx context.Context, userID uuid.UUID) (invoicesL
ID: stripeInvoice.ID,
Description: stripeInvoice.Description,
Amount: total,
Status: string(stripeInvoice.Status),
Status: convertStatus(stripeInvoice.Status),
Link: stripeInvoice.InvoicePDF,
Start: time.Unix(stripeInvoice.PeriodStart, 0),
})
@ -134,7 +134,7 @@ func (invoices *invoices) ListWithDiscounts(ctx context.Context, userID uuid.UUI
ID: stripeInvoice.ID,
Description: stripeInvoice.Description,
Amount: total,
Status: string(stripeInvoice.Status),
Status: convertStatus(stripeInvoice.Status),
Link: stripeInvoice.InvoicePDF,
Start: time.Unix(stripeInvoice.PeriodStart, 0),
})
@ -201,3 +201,22 @@ func (invoices *invoices) CheckPendingItems(ctx context.Context, userID uuid.UUI
return false, nil
}
func convertStatus(stripestatus stripe.InvoiceStatus) string {
var status string
switch stripestatus {
case stripe.InvoiceStatusDraft:
status = payments.InvoiceStatusDraft
case stripe.InvoiceStatusOpen:
status = payments.InvoiceStatusOpen
case stripe.InvoiceStatusPaid:
status = payments.InvoiceStatusPaid
case stripe.InvoiceStatusUncollectible:
status = payments.InvoiceStatusUncollectible
case stripe.InvoiceStatusVoid:
status = payments.InvoiceStatusVoid
default:
status = string(stripestatus)
}
return status
}