"$10.50"). */ public static function formatAmount( $amount ) { return '$' . self::formatAmountValue( $amount ); } /** Format a numeric amount to 2 decimal places (10.5 => "10.50"). */ public static function formatAmountValue( $amount ) { return number_format( (float) $amount, 2, '.', '' ); } /** * Format an amount with the merchant's currency symbol. * * formatCurrencyAmount( 40, 'Rs' ) // "Rs 40.00" * formatCurrencyAmount( 10.50, '$' ) // "$10.50" * formatCurrencyAmount( 10.50 ) // "$10.50" */ public static function formatCurrencyAmount( $amount, $currencySymbol = null ) { $symbol = $currencySymbol ? (string) $currencySymbol : '$'; $formatted = self::formatAmountValue( $amount ); return '$' === $symbol ? $symbol . $formatted : $symbol . ' ' . $formatted; } /** * Format the converted currency display line, e.g. "$0.14 STABLECOIN". * Returns an empty string when there is no conversion data. */ public static function formatConvertedCurrency( $convertedCurrency = null, $conversionCurrencySymbol = null, $stablecoinLabel = null ) { if ( null === $convertedCurrency || '' === $convertedCurrency ) { return ''; } $symbol = 'USD' === $conversionCurrencySymbol ? '$' : ( $conversionCurrencySymbol ? $conversionCurrencySymbol : '$' ); $label = $stablecoinLabel ? $stablecoinLabel : 'STABLECOIN'; return $symbol . $convertedCurrency . ' ' . $label; } }