Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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