Skip to content

fix(billing): show the credit purchase amount as a formatted price - #1948

Merged
rohanchkrabrty merged 4 commits into
mainfrom
fix-credit-purchase-description
Sep 25, 2026
Merged

rohanchkrabrty merged 4 commits into
mainfrom
fix-credit-purchase-description

Conversation

@rohanchkrabrty

@rohanchkrabrty rohanchkrabrty commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Credit purchase descriptions showed a malformed amount, e.g. addition of 10 credits for Tokens at %!d(float64=1000)[usd].
  • Checkout metadata is stored as JSON, so the synced Stripe amount_total reads back as a float64, and formatting it with %d fails. It is now converted with cast.ToInt64, the same way the product quantity is read.
  • Stripe reports the amount in the currency's minor unit, so the description now shows it in the major unit with the ISO code, using golang.org/x/text/currency for the number of decimals: at 10.00 USD instead of at 1000[usd], and 1000 JPY for a zero-decimal currency. An unknown currency code keeps the old 1000[xyz] format.
  • golang.org/x/text moves from an indirect to a direct dependency.
  • Descriptions of credits that were already added are not changed.

Checkout metadata is stored as JSON, so the synced Stripe amount total
reads back as a float64. Formatting it with %d wrote descriptions like
"at %!d(float64=1000)[usd]". Convert it to int64 first, the same way
the product quantity is read.
@vercel

vercel Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
frontier Ready Ready Preview Sep 25, 2026 7:46am UTC

@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: raystack/frontier/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 927b3679-632f-45df-85cb-1d15882e8f47

📥 Commits

Reviewing files that changed from the base of the PR and between a777b3a and 56fa544.

📒 Files selected for processing (1)
  • billing/checkout/service.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • billing/checkout/service.go

Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.


📝 Summary

Summary by CodeRabbit

  • Improvements
    • Credit descriptions now display Stripe totals in major currency units with the ISO currency code and standard decimal precision. When a currency code cannot be parsed, the amount is shown in minor units with the original code.

Walkthrough

Checkout credit descriptions now use formatted amounts with parsed ISO currency codes and currency-specific decimal scales. Invalid currency codes retain the minor-unit amount and original code in brackets.

Changes

Checkout credit descriptions

Layer / File(s) Summary
Format checkout credit amounts
billing/checkout/service.go, go.mod
When the total and currency are present, the checkout uses formatAmount in the credit description. The helper formats valid ISO currency codes as scaled amounts followed by the parsed code. Invalid codes use the minor-unit amount and original code in brackets. golang.org/x/text is declared as a direct dependency.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Merge Risk: 🟡 Moderate · up to 56fa5

Credit purchase descriptions can show an incorrect amount for ISK purchases. Correct the conversion before merging unless this limitation is explicitly accepted.

Architecture Summary

Architecture risk: 🔵 Low · up to a777b

The change affects 2 systems.

Changed systems: billing, go.mod

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — billing (service) was modified; 1 changed file maps to changed impact.
  • observed — go.mod (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in billing/checkout/service.go: Added math and the currency, language, and message imports required for currency-aware amount formatting.
  • observed — Modified behavior in billing/checkout/service.go: When both the total amount and a string currency are present, the credit description now uses formatAmount instead of displaying the raw amount followed by the currency code.
  • observed — Modified behavior in billing/checkout/service.go: Added formatAmount, which parses the uppercased ISO currency code and returns the raw minor-unit amount with the original code in brackets if parsing fails. Otherwise, it uses the currency’s standard rounding scale to convert minor units, renders the amount with an English-locale narrow currency symbol, and removes the first space.
  • observed — Modified behavior in go.mod: golang.org/x/text remains at v0.40.0 but is no longer marked as indirect.
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

… unit

Stripe reports the amount total in the currency's minor unit, so a
$10.00 purchase read "at 1000[usd]". Format it with the currency's
symbol and decimals instead, so it reads "at $10.00" (and "¥1,000" for
a zero-decimal currency). An unknown currency code keeps the old format.
@rohanchkrabrty rohanchkrabrty changed the title fix(billing): print the credit purchase amount as a whole number fix(billing): show the credit purchase amount as a formatted price Sep 25, 2026
@coveralls

coveralls commented Sep 25, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 36109356300

Coverage decreased (-0.009%) to 51.745%

Details

  • Coverage decreased (-0.009%) from the base build.
  • Patch coverage: 9 uncovered changes across 1 file (0 of 9 lines covered, 0.0%).
  • 1 coverage regression across 1 file.

Uncovered Changes

File Changed Covered %
billing/checkout/service.go 9 0 0.0%

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
billing/checkout/service.go 1 10.13%

Coverage Stats

Coverage Status
Relevant Lines: 41140
Covered Lines: 21288
Line Coverage: 51.75%
Coverage Strength: 16.87 hits per line

💛 - Coveralls

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: raystack/frontier/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: a8044daf-a918-446a-8ae8-fc6a8dedc057

📥 Commits

Reviewing files that changed from the base of the PR and between 057a60c and a777b3a.

📒 Files selected for processing (2)
  • billing/checkout/service.go
  • go.mod

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.

Comment thread billing/checkout/service.go Resolved
Comment thread billing/checkout/service.go Resolved
A narrow symbol rendered every dollar currency as a bare $, so CAD, AUD
and USD purchases read the same. Print the amount in the major unit with
the ISO code instead, e.g. "10.00 USD", and drop the symbol printer.
@rohanchkrabrty
rohanchkrabrty merged commit f789863 into main Sep 25, 2026
8 checks passed
@rohanchkrabrty
rohanchkrabrty deleted the fix-credit-purchase-description branch September 25, 2026 08:08

This branch was successfully deployed

1 active deployment
Preview — 56fa544e Deployed Sep 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants