From 78e68cdca25b5f650392b6d57634b245358f6b65 Mon Sep 17 00:00:00 2001 From: Cameron Date: Sat, 11 Feb 2023 11:01:28 -0500 Subject: [PATCH] satellite/payments: add constants for invoice status Change-Id: Iaf94d57d99caff3d435a44c56bd47c7b715ff4c0 --- satellite/payments/invoices.go | 13 +++++++++++ .../payments/stripecoinpayments/invoices.go | 23 +++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/satellite/payments/invoices.go b/satellite/payments/invoices.go index f4b468e1a..f68309add 100644 --- a/satellite/payments/invoices.go +++ b/satellite/payments/invoices.go @@ -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 diff --git a/satellite/payments/stripecoinpayments/invoices.go b/satellite/payments/stripecoinpayments/invoices.go index 37effd1ab..e4e232e41 100644 --- a/satellite/payments/stripecoinpayments/invoices.go +++ b/satellite/payments/stripecoinpayments/invoices.go @@ -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 +}