@tagadapay/plugin-sdk 3.1.9 → 3.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build-cdn.js +28 -20
- package/dist/external-tracker.js +1 -1
- package/dist/external-tracker.min.js +2 -2
- package/dist/external-tracker.min.js.map +1 -1
- package/dist/tagada-sdk.js +34 -10
- package/dist/tagada-sdk.min.js +18 -13
- package/dist/tagada-sdk.min.js.map +3 -3
- package/dist/v2/core/utils/currency.d.ts +14 -0
- package/dist/v2/core/utils/currency.js +40 -0
- package/dist/v2/standalone/index.js +1 -1
- package/package.json +1 -1
|
@@ -8,6 +8,20 @@ export interface Currency {
|
|
|
8
8
|
name: string;
|
|
9
9
|
decimalPlaces: number;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Format money amount from minor units (cents) to a formatted string
|
|
13
|
+
*
|
|
14
|
+
* @param amountMinorUnits - Amount in minor units (e.g., 12345 for $123.45)
|
|
15
|
+
* @param currencyCode - ISO 4217 currency code (e.g., "USD", "EUR")
|
|
16
|
+
* @param locale - Locale for formatting (default: "en-US")
|
|
17
|
+
* @returns Formatted money string (e.g., "$123.45")
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* formatMoney(12345, 'USD') // "$123.45"
|
|
21
|
+
* formatMoney(10000, 'EUR', 'de-DE') // "100,00 €"
|
|
22
|
+
* formatMoney(1000, 'JPY') // "¥1,000"
|
|
23
|
+
*/
|
|
24
|
+
export declare function formatMoney(amountMinorUnits: number, currencyCode?: string, locale?: string): string;
|
|
11
25
|
export declare class CurrencyUtils {
|
|
12
26
|
/**
|
|
13
27
|
* Get currency from context or fallback to default
|
|
@@ -2,6 +2,46 @@
|
|
|
2
2
|
* Currency Utility Functions
|
|
3
3
|
* Pure functions for currency management
|
|
4
4
|
*/
|
|
5
|
+
/**
|
|
6
|
+
* Format money amount from minor units (cents) to a formatted string
|
|
7
|
+
*
|
|
8
|
+
* @param amountMinorUnits - Amount in minor units (e.g., 12345 for $123.45)
|
|
9
|
+
* @param currencyCode - ISO 4217 currency code (e.g., "USD", "EUR")
|
|
10
|
+
* @param locale - Locale for formatting (default: "en-US")
|
|
11
|
+
* @returns Formatted money string (e.g., "$123.45")
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* formatMoney(12345, 'USD') // "$123.45"
|
|
15
|
+
* formatMoney(10000, 'EUR', 'de-DE') // "100,00 €"
|
|
16
|
+
* formatMoney(1000, 'JPY') // "¥1,000"
|
|
17
|
+
*/
|
|
18
|
+
export function formatMoney(amountMinorUnits, currencyCode = 'USD', locale = 'en-US') {
|
|
19
|
+
const decimalPlaces = CurrencyUtils.getDecimalPlaces(currencyCode);
|
|
20
|
+
// Convert minor units to major units
|
|
21
|
+
// Backend stores amounts with 2 decimal places for all currencies
|
|
22
|
+
// For currencies with 0 decimal places (JPY, KRW, etc.), divide by 100
|
|
23
|
+
let value;
|
|
24
|
+
if (decimalPlaces === 0) {
|
|
25
|
+
// For zero-decimal currencies, backend still stores with 2 decimals
|
|
26
|
+
value = amountMinorUnits / 100;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
value = amountMinorUnits / Math.pow(10, decimalPlaces);
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
return new Intl.NumberFormat(locale, {
|
|
33
|
+
style: 'currency',
|
|
34
|
+
currency: currencyCode,
|
|
35
|
+
minimumFractionDigits: decimalPlaces,
|
|
36
|
+
maximumFractionDigits: decimalPlaces,
|
|
37
|
+
}).format(value);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// Fallback if Intl.NumberFormat fails
|
|
41
|
+
const symbol = CurrencyUtils.getCurrencySymbol(currencyCode);
|
|
42
|
+
return `${symbol}${value.toFixed(decimalPlaces)}`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
5
45
|
export class CurrencyUtils {
|
|
6
46
|
/**
|
|
7
47
|
* Get currency from context or fallback to default
|
|
@@ -19,7 +19,7 @@ export function createTagadaClient(config = {}) {
|
|
|
19
19
|
// Re-export Core Classes
|
|
20
20
|
export { TagadaClient, ApiClient, CheckoutResource };
|
|
21
21
|
export { FunnelActionType } from '../core/resources/funnel';
|
|
22
|
-
// Re-export Utilities
|
|
22
|
+
// Re-export Utilities (includes formatMoney from core/utils/currency)
|
|
23
23
|
export * from '../core/utils';
|
|
24
24
|
// ============================================================================
|
|
25
25
|
// EXTERNAL PAGE TRACKER
|