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/stripe/stripe-go"
|
|
|
|
|
2020-03-30 10:08:50 +01:00
|
|
|
"storj.io/common/uuid"
|
2019-10-31 16:56:54 +00:00
|
|
|
"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,
|
2020-03-13 16:07:39 +00:00
|
|
|
Amount: stripeInvoice.Total,
|
2019-10-31 16:56:54 +00:00
|
|
|
Status: string(stripeInvoice.Status),
|
|
|
|
Link: stripeInvoice.InvoicePDF,
|
|
|
|
Start: time.Unix(stripeInvoice.PeriodStart, 0),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = invoicesIterator.Err(); err != nil {
|
|
|
|
return nil, Error.Wrap(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return invoicesList, nil
|
|
|
|
}
|