Skip to content

Commit b3c0dad

Browse files
fix(react): convert MercadoPago amount from minor to major units (#1323)
* fix(react): convert MercadoPago amount from minor to major units * chore: add changeset
1 parent 389be9f commit b3c0dad

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@godaddy/react": patch
3+
---
4+
5+
Fix MercadoPago amount conversion from minor units to major units. The SDK expects amounts in major units (e.g., 90.00 BRL) but we were sending minor units (e.g., 9000 cents).

packages/react/src/components/checkout/payment/checkout-buttons/mercadopago/mercadopago.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, { useCallback, useLayoutEffect, useState } from 'react';
33
import { useFormContext } from 'react-hook-form';
44
import { useCheckoutContext } from '@/components/checkout/checkout';
55
import { useDraftOrderTotals } from '@/components/checkout/order/use-draft-order';
6+
import { formatCurrency } from '@/components/checkout/utils/format-currency';
67
import {
78
PaymentProvider,
89
useConfirmCheckout,
@@ -96,7 +97,15 @@ export function MercadoPagoCheckoutButton() {
9697
} else {
9798
// Create new brick
9899
const renderBrick = async () => {
99-
const total = totals?.total?.value || 0;
100+
// Convert from minor units (cents) to major units
101+
const total = parseFloat(
102+
formatCurrency({
103+
amount: totals?.total?.value || 0,
104+
currencyCode: totals?.total?.currencyCode || 'USD',
105+
inputInMinorUnits: true,
106+
returnRaw: true,
107+
})
108+
);
100109

101110
try {
102111
const container = document.getElementById(elementId);

0 commit comments

Comments
 (0)