-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
When we send money via Pix to another user, we get the following response from Mercado Pago:
"results": [
{
"accessibility_text": "-10 reais com 0 centavos",
"actions": [],
"additionalInfo": null,
"amount": {
"cents": "00",
"cents_text": "",
"currency_id": "BRL",
"decimal_separator": ",",
"fraction": "-10",
"strike_through": false,
"symbol": "R$",
"symbol_text": "Real"
},
"category": "transfers",
"creationDate": "2025-05-07T23:43:44.000Z",
"date": "20h43",
"description": "Transferência via Pix",
"email": null,
"entity": "payout",
"grouperDate": {
"key": "Hoje",
"value": "20h43"
},
"icon": "ic_transfer_fiat",
"id": "pix_transfer_mo_payout_movement-78711072109fcc0e6bccfa366e35357cf30e4f8d",
"image": null,
"initials": null,
"lastModified": "2025-05-07T23:44:13.833Z",
"link": "/activities/detail/pix_transfer_mo_payout_movement-78711072109fcc0e6bccfa366e35357cf30e4f8d?from=mp-home",
"moneyReleaseDate": null,
"paymentMethod": {
"altText": "Entidade: Mercado Pago",
"fallback": "https://http2.mlstatic.com/storage/activities-middle-end/activities-assets/rowfeed/logos-pm/svg/ic_default_bank.svg",
"image": "https://http2.mlstatic.com/storage/activities-middle-end/activities-assets/rowfeed/logos-pm/svg/ic_common_account_money_v2.svg",
"text": "Saldo em conta"
},
"status": {
"code": "",
"color": "",
"text": ""
},
"subCategory": "pix",
"title": "Icaro Pereira Hoff",
"type": "pix_transfer_mo_payout_movement",
"version": 2
},
]
Our data shows negative values for sent money, as well as different separator, so I guess we would need to adjust the code to match it:
* Parses the amount from the proof.
*
* @param _amount The amount to parse (fraction part).
* @param _amountCents The cents amount to parse.
* @param _decimals The decimals of the token.
* @param _decimalSeparator The decimal separator character (comma for BRL).
*/
function _parseAmount(
string memory _amount,
string memory _amountCents,
uint8 _decimals,
string memory _decimalSeparator
) internal pure returns(int256) {
// For BRL, we use 0x2C (comma) as the decimal separator
uint8 separatorChar = bytes(_decimalSeparator)[0] == 0x2C ? 0x2C : 0x2E; // comma or period
// Handle negative amounts
bool isNegative = bytes(_amount).length > 0 && bytes(_amount)[0] == 0x2D; // '-' character
string memory absAmount = isNegative ? _amount.substring(1) : _amount;
uint256 baseAmount = absAmount.stringToUint(
separatorChar,
_decimals
);
uint256 centsAmount = _amountCents.stringToUint(_decimals - 2);
uint256 totalAmount = baseAmount + centsAmount;
// Apply negative sign if needed
return isNegative ? -int256(totalAmount) : int256(totalAmount);
}```
We need to add if clauses for this based on *BRL* or *ARS* as well.
Any inputs on this will be appreciated.
Metadata
Metadata
Assignees
Labels
No labels