Skip to content

fix(react): convert MercadoPago amount from minor to major units#1323

Open
nlaverde-godaddy wants to merge 2 commits intogodaddy:mainfrom
nlaverde-godaddy:vnext-76779
Open

fix(react): convert MercadoPago amount from minor to major units#1323
nlaverde-godaddy wants to merge 2 commits intogodaddy:mainfrom
nlaverde-godaddy:vnext-76779

Conversation

@nlaverde-godaddy
Copy link

Summary

Fix incorrect amount being sent to MercadoPago SDK. The SDK expects amounts in major units (e.g., 90.00 BRL) but we were sending minor units (e.g., 9000 cents).

Problem

When initializing the MercadoPago payment brick, we were passing totals.total.value directly, which is stored in minor units (cents). This caused MercadoPago to display and process incorrect amounts (100x higher than expected).

For example:

  • Order total: R$90.00
  • Value in API: 9000 (minor units)
  • Sent to MercadoPago: 9000 ❌ (should be 90)

Solution

Use the existing formatCurrency utility with returnRaw: true to properly convert from minor units to major units based on each currency's precision:

  • BRL, USD, EUR, etc. (precision 2): divide by 100
  • CLP, JPY, KRW (precision 0): divide by 1
  • KWD, BHD (precision 3): divide by 1000

Changes

  • Import formatCurrency from @/components/checkout/utils/format-currency
  • Convert amount before passing to MercadoPago brick initialization

Testing

Tested with multiple currencies:

  • BRL (Brazil) - R$90.00 → 90
  • CLP (Chile) - $9000 → 9000

Screenshot 2026-03-20 at 17 42 08

@nlaverde-godaddy nlaverde-godaddy requested a review from a team as a code owner March 20, 2026 22:42
@changeset-bot
Copy link

changeset-bot bot commented Mar 20, 2026

🦋 Changeset detected

Latest commit: a53ff45

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

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.

2 participants