fix: currency conversion error for paypal (#16917)

* fix: currency conversion error for paypal

* type-error
This commit is contained in:
Anik Dhabal Babu
2024-10-05 01:11:09 +05:30
committed by GitHub
parent babb1a3bf7
commit dfa92f5cb6
4 changed files with 10 additions and 9 deletions
@@ -1,6 +1,3 @@
/**
* Docs: https://stripe.com/docs/currencies#zero-decimal
* */
const zeroDecimalCurrencies = [
"BIF",
"CLP",
@@ -9,6 +9,10 @@ import type { EventTypeAppSettingsComponent } from "@calcom/app-store/types";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Alert, Select, TextField } from "@calcom/ui";
import {
convertToSmallestCurrencyUnit,
convertFromSmallestToPresentableCurrencyUnit,
} from "../../_utils/payments/currencyConversions";
import { PaypalPaymentOptions as paymentOptions } from "../zod";
type Option = { value: string; label: string };
@@ -20,7 +24,7 @@ const EventTypeAppSettingsInterface: EventTypeAppSettingsComponent = ({
}) => {
const price = getAppData("price");
const currency = getAppData("currency");
const currency = getAppData("currency") || currencyOptions[0].value;
const [selectedCurrency, setSelectedCurrency] = useState(currencyOptions.find((c) => c.value === currency));
const [currencySymbol, setCurrencySymbol] = useState(
isAcceptedCurrencyCode(currency) ? currencySymbols[currency] : ""
@@ -71,12 +75,12 @@ const EventTypeAppSettingsInterface: EventTypeAppSettingsComponent = ({
placeholder="Price"
data-testid="paypal-price-input"
onChange={(e) => {
setAppData("price", Number(e.target.value) * 100);
setAppData("price", convertToSmallestCurrencyUnit(Number(e.target.value), currency));
if (selectedCurrency) {
setAppData("currency", selectedCurrency.value);
}
}}
value={price > 0 ? price / 100 : undefined}
value={price > 0 ? convertFromSmallestToPresentableCurrencyUnit(price, currency) : undefined}
/>
</div>
<div className="mt-5 w-60">
@@ -4,11 +4,11 @@ import type { EventTypeAppSettingsComponent } from "@calcom/app-store/types";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Alert, Select, TextField } from "@calcom/ui";
import { paymentOptions } from "../lib/constants";
import {
convertToSmallestCurrencyUnit,
convertFromSmallestToPresentableCurrencyUnit,
} from "../lib/currencyConversions";
} from "../../_utils/payments/currencyConversions";
import { paymentOptions } from "../lib/constants";
import { currencyOptions } from "../lib/currencyOptions";
type Option = { value: string; label: string };
+1 -1
View File
@@ -1,4 +1,4 @@
import { convertFromSmallestToPresentableCurrencyUnit } from "@calcom/app-store/stripepayment/lib/currencyConversions";
import { convertFromSmallestToPresentableCurrencyUnit } from "@calcom/app-store/_utils/payments/currencyConversions";
export const formatPrice = (price: number, currency: string | undefined, locale = "en") => {
switch (currency) {