2019-10-31 16:56:54 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package stripecoinpayments
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/skyrings/skyring-common/tools/uuid"
|
|
|
|
"github.com/stripe/stripe-go"
|
|
|
|
|
|
|
|
"storj.io/storj/satellite/payments"
|
|
|
|
)
|
|
|
|
|
|
|
|
// invoices is an implementation of payments.Invoices.
|
2019-11-05 13:16:02 +00:00
|
|
|
//
|
2020-01-29 00:57:15 +00:00
|
|
|
// architecture: Service
|
2019-10-31 16:56:54 +00:00
|
|
|
type invoices struct {
|
|
|
|
service *Service
|
|
|
|
}
|
|
|
|
|
|
|
|
// List returns a list of invoices for a given payment account.
|
|
|
|
func (invoices *invoices) List(ctx context.Context, userID uuid.UUID) (invoicesList []payments.Invoice, err error) {
|
|
|
|
defer mon.Task()(&ctx, userID)(&err)
|
|
|
|
|
2019-11-05 13:16:02 +00:00
|
|
|
customerID, err := invoices.service.db.Customers().GetCustomerID(ctx, userID)
|
2019-10-31 16:56:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, Error.Wrap(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
params := &stripe.InvoiceListParams{
|
|
|
|
Customer: &customerID,
|
|
|
|
}
|
|
|
|
|
|
|
|
invoicesIterator := invoices.service.stripeClient.Invoices.List(params)
|
|
|
|
for invoicesIterator.Next() {
|
|
|
|
stripeInvoice := invoicesIterator.Invoice()
|
|
|
|
|
|
|
|
invoicesList = append(invoicesList, payments.Invoice{
|
|
|
|
ID: stripeInvoice.ID,
|
|
|
|
Description: stripeInvoice.Description,
|
|
|
|
Amount: stripeInvoice.AmountDue,
|
|
|
|
Status: string(stripeInvoice.Status),
|
|
|
|
Link: stripeInvoice.InvoicePDF,
|
|
|
|
End: time.Unix(stripeInvoice.PeriodEnd, 0),
|
|
|
|
Start: time.Unix(stripeInvoice.PeriodStart, 0),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = invoicesIterator.Err(); err != nil {
|
|
|
|
return nil, Error.Wrap(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return invoicesList, nil
|
|
|
|
}
|