Skip to content

Conversation

@pbennett1-godaddy
Copy link
Contributor

@pbennett1-godaddy pbennett1-godaddy commented Nov 10, 2025

Summary

refactor: standardize currency handling with formatCurrency utility

Replace all manual currency conversions (/ 100, * 100, .toFixed(), Intl.NumberFormat)
with the centralized formatCurrency utility to ensure consistent precision handling
across different currencies (USD, VND, etc.) and eliminate hardcoded "USD" references.

All values from the API now remain in minor units (cents) throughout the application,
with formatCurrency handling display conversions based on currency-specific precision.

BREAKING CHANGE: checkout-transformers now keeps originalPrice/price in minor units
instead of major units. All currency display must use formatCurrency.


Files Changed (11 files)

Core Utilities

  • src/components/checkout/utils/checkout-transformers.ts
    • Removed /100 conversions from originalPrice and price calculations
    • Values now stay in minor units consistently

Form Components

  • src/components/checkout/form/checkout-form.tsx
    • Added formatCurrency import
    • Removed all / 100 conversions, keep values in minor units
    • Replaced Intl.NumberFormat with formatCurrency
    • Updated tracking event properties to use minor units
  • src/components/checkout/tips/tips-form.tsx
    • Added formatCurrency import
    • Removed inline formatCurrency function (now uses util)
    • Updated tip percentage calculation to work with minor units
    • Added comments documenting user input conversion (* 100)
    • Updated custom tip input to use formatCurrency with returnRaw: true

Display Components

  • src/components/checkout/line-items/line-items.tsx
    • Added formatCurrency import
    • Replaced Intl.NumberFormat with formatCurrency
    • Removed unnecessary * 100 (now handled in transformers)
  • src/components/checkout/totals/totals.tsx
    • Added formatCurrency import
    • Updated TotalLineItem to use formatCurrency instead of Intl.NumberFormat
    • Updated total display to use formatCurrency
  • src/components/checkout/shipping/shipping-method.tsx
    • Added formatCurrency import
    • Replaced Intl.NumberFormat with formatCurrency (2 locations)

Payment Components

  • src/components/checkout/payment/payment-form.tsx
    • Added formatCurrency import
    • Replaced Intl.NumberFormat with formatCurrency in order summary
  • src/components/checkout/payment/utils/use-build-payment-request.ts
    • Added formatCurrency import
    • Removed all / 100 conversions throughout
    • Extracted minor unit values at the top for reuse
    • Replaced all Intl.NumberFormat with formatCurrency
    • Used returnRaw: true for PayPal/Poynt API string values
    • Updated all .toFixed(2) calls to use formatCurrency

Express Checkout

  • src/components/checkout/payment/checkout-buttons/express/godaddy.tsx
    • Added formatCurrency import
    • Moved currencyCode calculation higher in component
    • Replaced all hardcoded 'USD' with currencyCode variable (6 locations)
    • Replaced all Intl.NumberFormat with formatCurrency
    • Removed all .toFixed(2) calls, replaced with formatCurrency
    • Updated getSortedShippingMethods to include amountInMinorUnits
    • Updated convertAddressToShippingLines to accept minor units
    • Eliminated unnecessary roundtrip conversions
    • Added comments documenting necessary wallet API conversions

How to Test

  1. Visual Regression Testing

All currency displays should look identical to before:

Test with USD (2 decimals)

  • Product prices: $10.99
  • Line items: $21.98
  • Taxes: $2.20
  • Shipping: $5.00
  • Totals: $29.18

Test with other currencies if available

  • VND (0 decimals): ₫100,000
  • JPY (0 decimals): ¥1,000
  • EUR (2 decimals): €10,99
  1. Functional Testing

Checkout Flow

  1. Add items to cart
  2. Go through checkout
  3. Verify all prices display correctly:
    ✓ Line item prices
    ✓ Subtotal
    ✓ Taxes (if enabled)
    ✓ Shipping options
    ✓ Discount codes
    ✓ Tips (if enabled)
    ✓ Final total

Tips Feature

  1. Navigate to tips section
  2. Click percentage buttons (10%, 15%, 20%)
    ✓ Tip amounts calculate correctly
    ✓ Display format is correct
  3. Enter custom tip (e.g., "12.50")
    ✓ Value displays correctly
    ✓ Converts to minor units correctly

Express Checkout (Apple Pay, Google Pay, PayPal)

  1. Test express checkout buttons
  2. Select shipping method
    ✓ Shipping costs display correctly
    ✓ Tax calculation works
  3. Apply discount code
    ✓ Discount displays correctly
    ✓ Total updates correctly
  4. Complete payment
    ✓ Payment processes with correct amounts

Changeset

  • Changeset added (docs)

Test Plan

PAZE:

CleanShot 2025-11-13 at 10 02 58@2x

GPay

CleanShot 2025-11-13 at 10 03 46@2x CleanShot 2025-11-13 at 10 04 09@2x

PayPal:

CleanShot 2025-11-13 at 10 07 47@2x

Order:

CleanShot 2025-11-13 at 10 04 40@2x

Shipping:

CleanShot 2025-11-13 at 10 04 56@2x

@pbennett1-godaddy pbennett1-godaddy self-assigned this Nov 10, 2025
@pbennett1-godaddy pbennett1-godaddy requested a review from a team as a code owner November 10, 2025 18:51
@changeset-bot
Copy link

changeset-bot bot commented Nov 10, 2025

🦋 Changeset detected

Latest commit: 485586e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@godaddy/react Patch
nextjs Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pbennett1-godaddy pbennett1-godaddy changed the title keep currency in minor units and concert using new currency util keep currency in minor units and convert using new currency util Nov 10, 2025
Copy link
Contributor

@wcole1-godaddy wcole1-godaddy left a comment

Choose a reason for hiding this comment

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

LGTM!

@wcole1-godaddy wcole1-godaddy merged commit 4058d97 into main Nov 13, 2025
3 checks passed
@wcole1-godaddy wcole1-godaddy deleted the currency-internationalization branch November 13, 2025 16:17
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