Skip to content

Commit

Permalink
fix: missing invoice due date (#473)
Browse files Browse the repository at this point in the history
Signed-off-by: Kush Sharma <[email protected]>
  • Loading branch information
kushsharma authored Jan 25, 2024
1 parent 5419eb7 commit 97558fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
22 changes: 7 additions & 15 deletions billing/invoice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,7 @@ func (s *Service) List(ctx context.Context, filter Filter) ([]Invoice, error) {
var invoices []Invoice
for stripeInvoiceItr.Next() {
invoice := stripeInvoiceItr.Invoice()
invoices = append(invoices, Invoice{
ID: "", // TODO: should we persist this?
ProviderID: invoice.ID,
CustomerID: custmr.ID,
State: string(invoice.Status),
Currency: string(invoice.Currency),
Amount: invoice.Total,
HostedURL: invoice.HostedInvoiceURL,
Metadata: metadata.FromString(invoice.Metadata),
EffectiveAt: time.Unix(invoice.EffectiveAt, 0),
DueDate: time.Unix(invoice.DueDate, 0),
CreatedAt: time.Unix(invoice.Created, 0),
})
invoices = append(invoices, stripeInvoiceToInvoice(custmr.ID, invoice))
}
if err := stripeInvoiceItr.Err(); err != nil {
return nil, fmt.Errorf("failed to list invoices: %w", err)
Expand All @@ -79,6 +67,10 @@ func (s *Service) GetUpcoming(ctx context.Context, customerID string) (Invoice,
return Invoice{}, fmt.Errorf("failed to get upcoming invoice: %w", err)
}

return stripeInvoiceToInvoice(customerID, stripeInvoice), nil
}

func stripeInvoiceToInvoice(customerID string, stripeInvoice *stripe.Invoice) Invoice {
var effectiveAt time.Time
if stripeInvoice.EffectiveAt != 0 {
effectiveAt = time.Unix(stripeInvoice.EffectiveAt, 0)
Expand All @@ -97,7 +89,7 @@ func (s *Service) GetUpcoming(ctx context.Context, customerID string) (Invoice,
return Invoice{
ID: "", // TODO: should we persist this?
ProviderID: stripeInvoice.ID,
CustomerID: custmr.ID,
CustomerID: customerID,
State: string(stripeInvoice.Status),
Currency: string(stripeInvoice.Currency),
Amount: stripeInvoice.Total,
Expand All @@ -106,5 +98,5 @@ func (s *Service) GetUpcoming(ctx context.Context, customerID string) (Invoice,
EffectiveAt: effectiveAt,
DueDate: dueDate,
CreatedAt: createdAt,
}, nil
}
}
3 changes: 2 additions & 1 deletion billing/subscription/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ func (s State) String() string {
}

const (
StateActive State = "active"
StateActive State = "active"
StatePastDue State = "past_due"
)

type Phase struct {
Expand Down

0 comments on commit 97558fb

Please sign in to comment.