@zuplo/zudoku-plugin-monetization 0.0.30 → 0.0.31

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.
Files changed (2) hide show
  1. package/dist/index.mjs +19 -10
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -156,12 +156,21 @@ const formatPrice = (amount, currency) => new Intl.NumberFormat("en-US", {
156
156
  maximumFractionDigits: 6,
157
157
  trailingZeroDisplay: "stripIfInteger"
158
158
  }).format(amount);
159
- const formatPriceTwoDecimals = (amount, currency) => new Intl.NumberFormat("en-US", {
160
- style: "currency",
161
- currency: currency ?? "USD",
162
- minimumFractionDigits: 2,
163
- maximumFractionDigits: 2
164
- }).format(amount);
159
+ /** Amount is in the smallest currency unit (e.g. Stripe); divisor from `Intl` / ISO 4217. */
160
+ const formatMinorCurrencyAmount = (amountInMinorUnits, currency) => {
161
+ const code = (currency ?? "USD").toUpperCase();
162
+ const fractionDigits = new Intl.NumberFormat("en-US", {
163
+ style: "currency",
164
+ currency: code
165
+ }).resolvedOptions().maximumFractionDigits ?? 2;
166
+ const divisor = 10 ** fractionDigits;
167
+ return new Intl.NumberFormat("en-US", {
168
+ style: "currency",
169
+ currency: code,
170
+ minimumFractionDigits: fractionDigits,
171
+ maximumFractionDigits: fractionDigits
172
+ }).format(amountInMinorUnits / divisor);
173
+ };
165
174
 
166
175
  //#endregion
167
176
  //#region src/utils/categorizeRateCards.ts
@@ -418,8 +427,8 @@ const CheckoutConfirmPage = () => {
418
427
  children: formatPrice(price.monthly, selectedPlan?.currency)
419
428
  }),
420
429
  taxAmount != null && /* @__PURE__ */ jsx("div", {
421
- className: "text-xs font-normal mt-1",
422
- children: taxInclusive ? `${formatPriceTwoDecimals(taxAmount, selectedPlan?.currency)} ${taxLabel} included` : `+ ${formatPriceTwoDecimals(taxAmount, selectedPlan?.currency)} ${taxLabel}`
430
+ className: "text-sm font-normal mt-1",
431
+ children: taxInclusive ? `${formatMinorCurrencyAmount(taxAmount, selectedPlan?.currency)} ${taxLabel} included` : `+ ${formatMinorCurrencyAmount(taxAmount, selectedPlan?.currency)} ${taxLabel}`
423
432
  }),
424
433
  billingCycle && /* @__PURE__ */ jsxs("div", {
425
434
  className: "text-sm text-muted-foreground font-normal",
@@ -944,8 +953,8 @@ const SubscriptionChangeConfirmPage = () => {
944
953
  children: formatPrice(price.monthly, selectedPlan?.currency)
945
954
  }),
946
955
  taxAmount != null && /* @__PURE__ */ jsx("div", {
947
- className: "text-xs font-normal mt-1",
948
- children: taxInclusive ? `${formatPriceTwoDecimals(taxAmount, selectedPlan?.currency)} ${taxLabel} included` : `+ ${formatPriceTwoDecimals(taxAmount, selectedPlan?.currency)} ${taxLabel}`
956
+ className: "text-sm font-normal mt-1",
957
+ children: taxInclusive ? `${formatMinorCurrencyAmount(taxAmount, selectedPlan?.currency)} ${taxLabel} included` : `+ ${formatMinorCurrencyAmount(taxAmount, selectedPlan?.currency)} ${taxLabel}`
949
958
  }),
950
959
  billingCycle && /* @__PURE__ */ jsxs("div", {
951
960
  className: "text-sm text-muted-foreground font-normal",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuplo/zudoku-plugin-monetization",
3
- "version": "0.0.30",
3
+ "version": "0.0.31",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/zuplo/zudoku",