Skip to content

Commit d41b131

Browse files
committed
[usage] Fix stripe invoice finalization
1 parent afb72f1 commit d41b131

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

components/usage/pkg/apiv1/billing.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,20 @@ func (s *BillingService) FinalizeInvoice(ctx context.Context, in *v1.FinalizeInv
6464
return nil, status.Errorf(codes.InvalidArgument, "Missing InvoiceID")
6565
}
6666

67-
invoice, err := s.stripeClient.GetInvoice(ctx, in.GetInvoiceId())
67+
invoice, err := s.stripeClient.GetInvoiceWithCustomer(ctx, in.GetInvoiceId())
6868
if err != nil {
6969
logger.WithError(err).Error("Failed to retrieve invoice from Stripe.")
7070
return nil, status.Errorf(codes.NotFound, "Failed to get invoice with ID %s: %s", in.GetInvoiceId(), err.Error())
7171
}
7272

73-
subscription := invoice.Subscription
74-
if subscription == nil {
75-
logger.Error("No subscription information available for invoice.")
76-
return nil, status.Errorf(codes.Internal, "Failed to retrieve subscription details from invoice.")
73+
customer := invoice.Customer
74+
if customer == nil {
75+
logger.Error("No customer information available for invoice.")
76+
return nil, status.Errorf(codes.Internal, "Failed to retrieve customer details from invoice.")
7777
}
78+
logger = logger.WithField("stripe_customer", customer.ID).WithField("stripe_customer_name", customer.Name)
7879

79-
teamID, found := subscription.Metadata[stripe.AttributionIDMetadataKey]
80+
teamID, found := customer.Metadata[stripe.AttributionIDMetadataKey]
8081
if !found {
8182
logger.Error("Failed to find teamID from subscription metadata.")
8283
return nil, status.Errorf(codes.Internal, "Failed to extra teamID from Stripe subscription.")

components/usage/pkg/stripe/stripe.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,15 @@ func (c *Client) GetUpcomingInvoice(ctx context.Context, customerID string) (*In
227227
}, nil
228228
}
229229

230-
func (c *Client) GetInvoice(ctx context.Context, invoiceID string) (*stripe.Invoice, error) {
230+
func (c *Client) GetInvoiceWithCustomer(ctx context.Context, invoiceID string) (*stripe.Invoice, error) {
231231
if invoiceID == "" {
232232
return nil, fmt.Errorf("no invoice ID specified")
233233
}
234234

235235
invoice, err := c.sc.Invoices.Get(invoiceID, &stripe.InvoiceParams{
236236
Params: stripe.Params{
237237
Context: ctx,
238-
Expand: []*string{stripe.String("data.subscriptions")},
238+
Expand: []*string{stripe.String("customer")},
239239
},
240240
})
241241
if err != nil {

0 commit comments

Comments
 (0)