-
Notifications
You must be signed in to change notification settings - Fork 402
/
invoices.go
93 lines (83 loc) · 3.33 KB
/
invoices.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package payments
import (
"context"
"time"
"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
type Invoices interface {
// Create creates an invoice with price and description.
Create(ctx context.Context, userID uuid.UUID, price int64, desc string) (*Invoice, error)
// Get returns an invoice by invoiceID.
Get(ctx context.Context, invoiceID string) (*Invoice, error)
// Pay pays an invoice.
Pay(ctx context.Context, invoiceID, paymentMethodID string) (*Invoice, error)
// List returns a list of invoices for a given payment account.
List(ctx context.Context, userID uuid.UUID) ([]Invoice, error)
// ListPaged returns a paged list of invoices.
ListPaged(ctx context.Context, userID uuid.UUID, cursor InvoiceCursor) (*InvoicePage, error)
// ListFailed returns a list of failed invoices.
ListFailed(ctx context.Context, userID *uuid.UUID) ([]Invoice, error)
// ListWithDiscounts returns a list of invoices and coupon usages for a given payment account.
ListWithDiscounts(ctx context.Context, userID uuid.UUID) ([]Invoice, []CouponUsage, error)
// CheckPendingItems returns if pending invoice items for a given payment account exist.
CheckPendingItems(ctx context.Context, userID uuid.UUID) (existingItems bool, err error)
// AttemptPayOverdueInvoices attempts to pay a user's open, overdue invoices.
AttemptPayOverdueInvoices(ctx context.Context, userID uuid.UUID) (err error)
// AttemptPayOverdueInvoicesWithTokens attempts to pay a user's open, overdue invoices with token only.
AttemptPayOverdueInvoicesWithTokens(ctx context.Context, userID uuid.UUID) (err error)
// Delete a draft invoice.
Delete(ctx context.Context, id string) (inv *Invoice, err error)
}
// Invoice holds all public information about invoice.
type Invoice struct {
ID string `json:"id"`
CustomerID string `json:"-"`
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"`
}
// InvoiceCursor holds info for invoices
// cursor pagination.
type InvoiceCursor struct {
Limit int
// StartingAfter is the last invoice ID of the previous page.
// The next page will start after this ID.
StartingAfter string
// EndingBefore is the id before which a page should end.
EndingBefore string
}
// InvoicePage returns paginated invoices.
type InvoicePage struct {
Invoices []Invoice
// Next indicates whether there are more events to retrieve.
Next bool
// Previous indicates whether there are previous items.
Previous bool
}
// CouponUsage describes the usage of a coupon on an invoice.
type CouponUsage struct {
Coupon Coupon
Amount int64
PeriodStart time.Time
PeriodEnd time.Time
}