raystack / raystack/frontier

GetUpcomingInvoice returns empty invoice object instead of 404 for offline billing accounts

Open
#1,315 0 comments 0 reactions 0 assignees View on GitHub

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:

  1. An empty response body {}, or
  2. A 404 Not Found status 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 missing
  • internal/api/v1beta1connect/billing_invoice.go - Update handler to return appropriate response
  • sdks/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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.