2019-10-31 16:56:54 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package payments
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2020-03-30 10:08:50 +01:00
|
|
|
"storj.io/common/uuid"
|
2019-10-31 16:56:54 +00:00
|
|
|
)
|
|
|
|
|
2023-02-11 16:01:28 +00:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2019-10-31 16:56:54 +00:00
|
|
|
// Invoices exposes all needed functionality to manage account invoices.
|
2020-01-29 00:57:15 +00:00
|
|
|
//
|
|
|
|
// architecture: Service
|
2019-10-31 16:56:54 +00:00
|
|
|
type Invoices interface {
|
2023-02-02 22:11:09 +00:00
|
|
|
// Create creates an invoice with price and description.
|
|
|
|
Create(ctx context.Context, userID uuid.UUID, price int64, desc string) (*Invoice, error)
|
2023-06-08 12:00:29 +01:00
|
|
|
// Get returns an invoice by invoiceID.
|
|
|
|
Get(ctx context.Context, invoiceID string) (*Invoice, error)
|
2023-02-02 22:11:09 +00:00
|
|
|
// Pay pays an invoice.
|
|
|
|
Pay(ctx context.Context, invoiceID, paymentMethodID string) (*Invoice, error)
|
2021-10-18 23:18:18 +01:00
|
|
|
// List returns a list of invoices for a given payment account.
|
|
|
|
List(ctx context.Context, userID uuid.UUID) ([]Invoice, error)
|
2023-02-13 17:32:39 +00:00
|
|
|
// ListFailed returns a list of failed invoices.
|
2023-07-25 15:08:57 +01:00
|
|
|
ListFailed(ctx context.Context, userID *uuid.UUID) ([]Invoice, error)
|
2021-10-18 23:18:18 +01:00
|
|
|
// ListWithDiscounts returns a list of invoices and coupon usages for a given payment account.
|
|
|
|
ListWithDiscounts(ctx context.Context, userID uuid.UUID) ([]Invoice, []CouponUsage, error)
|
2020-07-06 22:31:40 +01:00
|
|
|
// CheckPendingItems returns if pending invoice items for a given payment account exist.
|
|
|
|
CheckPendingItems(ctx context.Context, userID uuid.UUID) (existingItems bool, err error)
|
2022-12-21 20:27:29 +00:00
|
|
|
// AttemptPayOverdueInvoices attempts to pay a user's open, overdue invoices.
|
|
|
|
AttemptPayOverdueInvoices(ctx context.Context, userID uuid.UUID) (err error)
|
2023-02-11 16:36:21 +00:00
|
|
|
// Delete a draft invoice.
|
|
|
|
Delete(ctx context.Context, id string) (inv *Invoice, err error)
|
2019-10-31 16:56:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Invoice holds all public information about invoice.
|
|
|
|
type Invoice struct {
|
|
|
|
ID string `json:"id"`
|
2023-02-13 17:32:39 +00:00
|
|
|
CustomerID string `json:"-"`
|
2019-10-31 16:56:54 +00:00
|
|
|
Description string `json:"description"`
|
|
|
|
Amount int64 `json:"amount"`
|
|
|
|
Status string `json:"status"`
|
|
|
|
Link string `json:"link"`
|
|
|
|
Start time.Time `json:"start"`
|
|
|
|
End time.Time `json:"end"`
|
|
|
|
}
|
2021-08-27 01:51:26 +01:00
|
|
|
|
|
|
|
// CouponUsage describes the usage of a coupon on an invoice.
|
|
|
|
type CouponUsage struct {
|
|
|
|
Coupon Coupon
|
|
|
|
Amount int64
|
|
|
|
PeriodStart time.Time
|
|
|
|
PeriodEnd time.Time
|
|
|
|
}
|