Skip to content

Commit

Permalink
fix: return empty invoice if no upcoming invoice (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsbh authored Feb 1, 2024
1 parent bd5e815 commit 3ea625f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions billing/invoice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package invoice

import (
"context"
"errors"
"fmt"
"time"

grpczap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
"github.com/raystack/frontier/billing/customer"
"github.com/raystack/frontier/pkg/metadata"
"github.com/stripe/stripe-go/v75"
Expand Down Expand Up @@ -52,6 +54,7 @@ func (s *Service) List(ctx context.Context, filter Filter) ([]Invoice, error) {
}

func (s *Service) GetUpcoming(ctx context.Context, customerID string) (Invoice, error) {
logger := grpczap.Extract(ctx)
custmr, err := s.customerService.GetByID(ctx, customerID)
if err != nil {
return Invoice{}, fmt.Errorf("failed to find customer: %w", err)
Expand All @@ -64,6 +67,11 @@ func (s *Service) GetUpcoming(ctx context.Context, customerID string) (Invoice,
},
})
if err != nil {
var stripeErr *stripe.Error
if errors.As(err, &stripeErr) && stripeErr.Code == stripe.ErrorCodeInvoiceUpcomingNone {
logger.Debug(fmt.Sprintf("no upcoming invoice: %v", stripeErr))
return Invoice{}, nil
}
return Invoice{}, fmt.Errorf("failed to get upcoming invoice: %w", err)
}

Expand Down

0 comments on commit 3ea625f

Please sign in to comment.