fix: 🐛 vite issues
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { Decimal as DecimalJS } from "decimal.js";
|
||||
import Stripe from "stripe";
|
||||
import type Stripe from "stripe";
|
||||
|
||||
type StripeDecimal = ReturnType<typeof Stripe.Decimal.from>;
|
||||
type DecimalLike = { toString(): string };
|
||||
type StripeDecimal = string & ReturnType<typeof Stripe.Decimal.from>;
|
||||
/**
|
||||
* Zero-decimal currencies that Stripe handles without decimal places.
|
||||
* These currencies don't require multiplying/dividing by 100.
|
||||
@@ -61,13 +62,12 @@ export const atmnToStripeAmountDecimal = ({
|
||||
const decimal = amount instanceof DecimalJS ? amount : new DecimalJS(amount);
|
||||
|
||||
if (ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase())) {
|
||||
return Stripe.Decimal.from(
|
||||
decimal.toDecimalPlaces(decimalPlaces).toString(),
|
||||
);
|
||||
return decimal.toDecimalPlaces(decimalPlaces).toString() as StripeDecimal;
|
||||
}
|
||||
return Stripe.Decimal.from(
|
||||
decimal.mul(100).toDecimalPlaces(decimalPlaces).toString(),
|
||||
);
|
||||
return decimal
|
||||
.mul(100)
|
||||
.toDecimalPlaces(decimalPlaces)
|
||||
.toString() as StripeDecimal;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -81,24 +81,26 @@ export const stripeToAtmnAmount = ({
|
||||
decimalPlaces = 10,
|
||||
round = true,
|
||||
}: {
|
||||
amount: number | StripeDecimal;
|
||||
amount: number | string | DecimalLike;
|
||||
currency?: string;
|
||||
decimalPlaces?: number;
|
||||
round?: boolean;
|
||||
}): number => {
|
||||
let finalAmount = typeof amount === "number" ? amount : amount.toNumber();
|
||||
let finalAmount = new DecimalJS(
|
||||
typeof amount === "number" ? amount : amount.toString(),
|
||||
);
|
||||
|
||||
if (!ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase())) {
|
||||
finalAmount = new DecimalJS(finalAmount).div(100).toNumber();
|
||||
finalAmount = finalAmount.div(100);
|
||||
}
|
||||
|
||||
if (round) {
|
||||
return new DecimalJS(finalAmount).toDecimalPlaces(decimalPlaces).toNumber();
|
||||
return finalAmount.toDecimalPlaces(decimalPlaces).toNumber();
|
||||
}
|
||||
|
||||
if (decimalPlaces) {
|
||||
return new DecimalJS(finalAmount).toDecimalPlaces(decimalPlaces).toNumber();
|
||||
return finalAmount.toDecimalPlaces(decimalPlaces).toNumber();
|
||||
}
|
||||
|
||||
return finalAmount;
|
||||
return finalAmount.toNumber();
|
||||
};
|
||||
|
||||
@@ -9,7 +9,9 @@ import {
|
||||
} from "@utils/productUtils/priceUtils/classifyPriceUtils";
|
||||
import { atmnToStripeAmountDecimal } from "@utils/productUtils/priceUtils/convertAmountUtils";
|
||||
import { Decimal } from "decimal.js";
|
||||
import Stripe from "stripe";
|
||||
import type Stripe from "stripe";
|
||||
|
||||
type StripeDecimal = string & ReturnType<typeof Stripe.Decimal.from>;
|
||||
|
||||
/**
|
||||
* Builds the Stripe tier array for a V2 prepaid price.
|
||||
@@ -42,7 +44,7 @@ export const priceToStripePrepaidV2Tiers = ({
|
||||
// allowance. Applies to both graduated and volume pricing.
|
||||
if (entitlement.allowance) {
|
||||
tiers.push({
|
||||
unit_amount_decimal: Stripe.Decimal.zero,
|
||||
unit_amount_decimal: "0" as StripeDecimal,
|
||||
up_to: entitlement.allowance,
|
||||
});
|
||||
}
|
||||
@@ -84,18 +86,16 @@ export const priceToStripePrepaidV2Tiers = ({
|
||||
|
||||
up_to:
|
||||
index === tiers.length - 1
|
||||
? "inf"
|
||||
? ("inf" as const)
|
||||
: new Decimal(tier.up_to ?? 0)
|
||||
.div(config.billing_units ?? 1)
|
||||
.ceil()
|
||||
.toNumber(),
|
||||
|
||||
unit_amount_decimal: Stripe.Decimal.from(
|
||||
new Decimal(tier.unit_amount_decimal?.toString() ?? "0")
|
||||
.mul(config.billing_units ?? 1)
|
||||
.toString(),
|
||||
),
|
||||
unit_amount_decimal: new Decimal(tier.unit_amount_decimal?.toString() ?? "0")
|
||||
.mul(config.billing_units ?? 1)
|
||||
.toString() as StripeDecimal,
|
||||
}));
|
||||
|
||||
return dividedTiers satisfies unknown as Stripe.PriceCreateParams.Tier[];
|
||||
return dividedTiers;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user