Skip to content

Commit

Permalink
Merge pull request #28 from Chimoney/bug/donate-with-chimoney
Browse files Browse the repository at this point in the history
fix iframe issue on donate page
  • Loading branch information
uchibeke authored Oct 19, 2024
2 parents 3c6094a + eeac6be commit d1f7b0a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 25 additions & 1 deletion open-giving/src/components/DonationForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,37 @@ import {
TextField,
Typography,
} from '@mui/material';
import React, { useCallback } from 'react';
import React, { useEffect } from 'react';

import useDonation from '../hooks/useDonation';
import { formatPaymentMethodName } from '../utils/paymentMethods';

const dev = process.env.NODE_ENV == 'development';
const DonationForm = React.memo(
({ method, index, setSnackbarMessage, setSnackbarOpen }) => {
useEffect(() => {
const handleMessage = (event) => {
const isApprovedOrigin = dev
? event.origin === 'http://localhost:4000' ||
event.origin?.includes('sandbox')
: event.origin?.includes('chimoney');

if (event.data.type === 'openUrl' && isApprovedOrigin) {
const newWindow =
event.data.url && window.open(event.data.url, '_blank');
if (newWindow) {
newWindow.focus();
}
}
};

window.addEventListener('message', handleMessage);

// Clean up the event listener when the component unmounts
return () => {
window.removeEventListener('message', handleMessage);
};
}, []);
const {
donationAmount,
setDonationAmount,
Expand Down
2 changes: 0 additions & 2 deletions open-giving/src/pages/api/chimoney-donate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export default async function handler(req, res) {
const dev = process.env.NODE_ENV == 'development';

if (req.method === 'POST') {
console.log({ body: req.body });
const {
amount,
currency = 'USD',
Expand Down Expand Up @@ -61,7 +60,6 @@ export default async function handler(req, res) {
},
}),
};

const response = await fetch(`${server}/payment/initiate`, config);

const data = await response.json();
Expand Down

0 comments on commit d1f7b0a

Please sign in to comment.