Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions packages/donations/src/components/MultiGatewayDonationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export const MultiGatewayDonationForm: React.FC<Props> = (props) => {
interval: "month"
},
funds: [],
gatewayId: props?.paymentMethods?.length > 0 ? props.paymentMethods[0].gatewayId : selectedGatewayObj?.id
gatewayId: props?.paymentMethods?.length > 0 ? props.paymentMethods[0].gatewayId : selectedGatewayObj?.id,
currency: selectedGatewayObj?.currency || "usd"
});

const loadFunds = useCallback(async () => {
Expand Down Expand Up @@ -144,6 +145,7 @@ export const MultiGatewayDonationForm: React.FC<Props> = (props) => {
d.provider = value as "stripe" | "paypal";
const matchedGateway = props.paymentGateways.find(g => DonationHelper.normalizeProvider(g.provider) === value);
d.gatewayId = matchedGateway?.id;
d.currency = matchedGateway?.currency || "usd";
// Reset payment method when changing gateways
const availableMethods = props.paymentMethods.filter(pm => DonationHelper.normalizeProvider(pm.provider) === value);
if (availableMethods.length > 0) {
Expand Down Expand Up @@ -272,7 +274,7 @@ export const MultiGatewayDonationForm: React.FC<Props> = (props) => {
try {
const response = await ApiHelper.post(
"/donate/fee?churchId=" + (props?.church?.id || ""),
{ amount, provider, gatewayId: activeGatewayId },
{ amount, provider, gatewayId: activeGatewayId, currency: gateway?.currency || "USD" },
"GivingApi"
);
return response.calculatedFee;
Expand Down Expand Up @@ -346,9 +348,9 @@ export const MultiGatewayDonationForm: React.FC<Props> = (props) => {
const nextProvider = prev.provider || (selectedGateway as "stripe" | "paypal");
const nextGatewayId = selectedGatewayObj?.id || prev.gatewayId;
if (nextProvider === prev.provider && nextGatewayId === prev.gatewayId) return prev;
return { ...prev, provider: nextProvider, gatewayId: nextGatewayId };
return { ...prev, provider: nextProvider, gatewayId: nextGatewayId, currency: selectedGatewayObj?.currency || "usd" };
});
}, [selectedGateway, selectedGatewayObj?.id]);
}, [selectedGateway, selectedGatewayObj?.id, selectedGatewayObj?.currency]);

// Cleanup timeout on unmount
useEffect(() => {
Expand Down Expand Up @@ -566,26 +568,26 @@ export const MultiGatewayDonationForm: React.FC<Props> = (props) => {
{funds && fundDonations && (
<>
<h4>{Locale.label("donation.donationForm.fund")}</h4>
<FundDonations fundDonations={fundDonations} funds={funds} updatedFunction={handleFundDonationsChange} />
<FundDonations fundDonations={fundDonations} funds={funds} updatedFunction={handleFundDonationsChange} currency={gateway?.currency} />
</>
)}
{fundsTotal > 0 && (
<>
{(gateway?.payFees === true) ? (
<Typography fontSize={14} fontStyle="italic">
*{Locale.label("donation.donationForm.fees").replace("{}", CurrencyHelper.formatCurrency(transactionFee))}
*{Locale.label("donation.donationForm.fees").replace("{}", CurrencyHelper.formatCurrencyWithLocale(transactionFee, gateway?.currency || "USD"))}
</Typography>
) : (
<FormGroup>
<FormControlLabel
control={<Checkbox />}
name="transaction-fee"
label={Locale.label("donation.donationForm.cover").replace("{}", CurrencyHelper.formatCurrency(transactionFee))}
label={Locale.label("donation.donationForm.cover").replace("{}", CurrencyHelper.formatCurrencyWithLocale(transactionFee, gateway?.currency || "USD"))}
onChange={handleCheckChange}
/>
</FormGroup>
)}
<p>{Locale.label("donation.donationForm.total")}: ${total}</p>
<p>{Locale.label("donation.donationForm.total")}: {CurrencyHelper.formatCurrencyWithLocale(total, gateway?.currency || "USD")}</p>
</>
)}
<TextField
Expand Down
4 changes: 3 additions & 1 deletion packages/donations/src/components/NonAuthDonation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export const NonAuthDonation: React.FC<Props> = ({ mainContainerCssProps, showHe

const renderPaymentTypeSelector = () => {
// Only show if Stripe is available (ACH requires Stripe)
// Only show ACH if the currency is USD
const stripeGateway = DonationHelper.findGatewayByProvider(availableGateways, "stripe");
const currency = stripeGateway?.currency || "usd";
if (!stripeGateway || selectedGateway !== "stripe") return null;

return (
Expand All @@ -98,7 +100,7 @@ export const NonAuthDonation: React.FC<Props> = ({ mainContainerCssProps, showHe
size="small"
>
<ToggleButton value="card">Credit/Debit Card</ToggleButton>
<ToggleButton value="bank">Bank Account (ACH)</ToggleButton>
{currency === "usd" && <ToggleButton value="bank">Bank Account (ACH)</ToggleButton>}
</ToggleButtonGroup>
</Box>
);
Expand Down
1 change: 1 addition & 0 deletions packages/donations/src/helpers/DonationInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export interface MultiGatewayDonationInterface {
};
funds?: FundDonationInterface[];
notes?: string;
currency?: string;
}
6 changes: 3 additions & 3 deletions packages/donations/src/modals/DonationPreviewModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export const DonationPreviewModal: React.FC<Props> = (props) => {
<TableRow><TableCell>{Locale.label("donation.preview.every")}:</TableCell><TableCell className="capitalize">{formatInterval()}</TableCell></TableRow>
</>
}
<TableRow><TableCell>{Locale.label("donation.preview.funds")}:</TableCell><TableCell>{props.donation.funds?.map((fund: any) => <p key={fund.id || fund.name}>{CurrencyHelper.formatCurrency(fund.amount)} - {fund.name}</p>)}</TableCell></TableRow>
{props.payFee > 0 && <TableRow><TableCell>{Locale.label("donation.preview.fee")}:</TableCell><TableCell>{CurrencyHelper.formatCurrency(props.payFee)}</TableCell></TableRow>}
<TableRow><TableCell>{Locale.label("donation.preview.total")}:</TableCell><TableCell><h4>{CurrencyHelper.formatCurrency(props.donation.amount || 0)}</h4></TableCell></TableRow>
<TableRow><TableCell>{Locale.label("donation.preview.funds")}:</TableCell><TableCell>{props.donation.funds?.map((fund: any) => <p key={fund.id || fund.name}>{CurrencyHelper.formatCurrencyWithLocale(fund.amount, props.donation?.currency || "usd")} - {fund.name}</p>)}</TableCell></TableRow>
{props.payFee > 0 && <TableRow><TableCell>{Locale.label("donation.preview.fee")}:</TableCell><TableCell>{CurrencyHelper.formatCurrencyWithLocale(props.payFee, props.donation?.currency || "usd")}</TableCell></TableRow>}
<TableRow><TableCell>{Locale.label("donation.preview.total")}:</TableCell><TableCell><h4>{CurrencyHelper.formatCurrencyWithLocale(props.donation.amount || 0, props.donation?.currency || "usd")}</h4></TableCell></TableRow>
</TableBody>
</Table>
</DialogContent>
Expand Down
1 change: 1 addition & 0 deletions playground/src/pages/DonationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default function DonationPage() {
provider: g.provider,
publicKey: g.publicKey,
enabled: g.enabled !== false,
currency: g?.currency || "usd",
}));
setPaymentGateways(pg);

Expand Down