GetUpcomingInvoice returns empty invoice object instead of 404 for offline billing accounts
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 344
- Forks
- 47
- Avg merge
- 4d 4h
- Merged PRs (30d)
- 26
Description
Problem
The GetUpcomingInvoice API handler currently returns a nil/empty invoice object when no billing customer provider is found or the account is offline. This results in an unhelpful response with all fields set to empty values:
{
"invoice": {
"id": "",
"customer_id": "",
"provider_id": "",
"state": "",
"currency": "",
"amount": "0",
"hosted_url": "",
"due_date": null,
"effective_at": null,
"period_start_at": null,
"period_end_at": null,
"metadata": {},
"created_at": null,
"customer": null
}
}
Expected Behavior
The API should return either:
- An empty response body
{}, or - A
404 Not Foundstatus when the billing customer is not created or offline
Root Cause
In billing/invoice/service.go:322-325, when there's no provider ID, the service returns an empty Invoice{} instead of an error:
if custmr.ProviderID == "" {
logger.Debug(fmt.Sprintf("no customer provider id found"))
return Invoice{}, nil
}
This empty invoice is then transformed and returned by the handler, creating the confusing response.
Impact
This forces the UI to implement workarounds. For example, in sdks/js/packages/core/react/components/organization/billing/upcoming-billing-cycle.tsx:126, the code has to check for !!billingAccount?.providerId to prevent fetching the upcoming invoice for offline billing accounts:
enabled:
!!activeOrganization?.id &&
// This is to prevent fetching the upcoming invoice for offline billing accounts
!!billingAccount?.providerId,
Once this is fixed, this UI workaround can be removed.
Files to Modify
billing/invoice/service.go:322-325- Handle the case where provider ID is missinginternal/api/v1beta1connect/billing_invoice.go- Update handler to return appropriate responsesdks/js/packages/core/react/components/organization/billing/upcoming-billing-cycle.tsx:126- Remove workaround check after API is fixed
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read billing/invoice/service.go around lines 322-325, then trace the response handling in internal/api/v1beta1connect/billing_invoice.go and the workaround in sdks/js/packages/core/react/components/organization/billing/upcoming-billing-cycle.tsx around line 126. Done means offline or uncreated billing customers receive an empty response or 404, and the UI workaround can be removed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, react, typescript
- Domain
- api, backend, frontend, payments
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100