Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed razorpay currency issues. #234

Merged
merged 2 commits into from
May 22, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public String createOrderRequest(RazorpayClient razorpayClient, RazorPayInput in
JSONObject orderRequest = new JSONObject();
String[] parts =input.getUniqueEventId().split("-");
String cityId = parts[0];
String currency = eventBuilder.getCurrencyForCity(cityId);
String currency = input.getCurrency();
orderRequest.put("amount", amount);
orderRequest.put("currency", currency);
Order order = razorpayClient.orders.create(orderRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public class RazorPayInput {

String uniqueEventId;
List<PlayerInput> playerInputList;
String currency;
}
1 change: 1 addition & 0 deletions platform/src/main/resources/graphql/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ input CreateUserInput {
input RazorPayInput {
uniqueEventId: ID!
playerInputList: [PlayerInput!]!
currency: String!
}

type User {
Expand Down
3 changes: 3 additions & 0 deletions react-fm/src/pages/matchQueues/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const dummyData = {
cityName: 'Hyderabad',
countryCode: 'IN',
dummyData: false,
currency: 'INR',
events: [
{
uniqueEventId: '07-28-1-1-6',
Expand Down Expand Up @@ -150,6 +151,7 @@ const dummyData = {
cityId: '1',
cityName: 'Gurgaon',
countryCode: 'IN',
currency: 'INR',
dummyData: false,
events: [
{
Expand Down Expand Up @@ -324,6 +326,7 @@ const dummyData = {
cityId: '4',
cityName: 'San Jose',
countryCode: 'US',
currency: 'USD',
dummyData: false,
events: [
{
Expand Down
29 changes: 26 additions & 3 deletions react-fm/src/pages/matchQueues/eventsComponents/JoinNow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import useOrientation from '@/hooks/useOrientation';
import useNotifications from '@/store/notifications';

import { apiUrl } from '../constants';
import mapCityData from '../map';
import type { EventDetails } from '../types/Events.types';
import styles from './Events.module.scss';
import { createOrder, displayRazorpay } from './RazorPay';
Expand All @@ -36,6 +37,7 @@ export const JoinNow: FC<EventDetails> = ({
waitListPlayersCount,
venueName,
uniqueEventId,
eventId,
}) => {
const [, notificationsActions] = useNotifications();
const isPortrait = useOrientation();
Expand Down Expand Up @@ -84,6 +86,19 @@ export const JoinNow: FC<EventDetails> = ({
});
}

const getCurrency = () => {
let currency = 'INR';
mapCityData.forEach((cityData) => {
// console.log(cityData.currency);
if (cityData.city === eventId) {
currency = cityData.currency;
}
});
return currency;
};

const currency = getCurrency();

const handleEmail = (e: { target: { value: string } }) => {
setUserData({ ...userData, email: e.target.value });
};
Expand Down Expand Up @@ -190,8 +205,8 @@ export const JoinNow: FC<EventDetails> = ({

generateUrl();
} else {
// createOrder('2-2024-04-20-1', objectArray, setAmount) // to be changed after local testing
createOrder(uniqueEventId, objectArray, setAmount) // to be changed after local testing
// createOrder('2-2024-04-20-1', objectArray, setAmount, currency || 'INR') // to be changed after local testing
createOrder(uniqueEventId, objectArray, setAmount, currency || 'INR') // to be changed after local testing
.then((orderId) => {
setOrderId(orderId);
setOpen(false);
Expand Down Expand Up @@ -220,7 +235,15 @@ export const JoinNow: FC<EventDetails> = ({
};

if (orderId) {
displayRazorpay(amount, orderId, userData.email, userData.name, userData.phoneNumber);
displayRazorpay(
amount,
orderId,
userData.email,
userData.name,
userData.phoneNumber,
setOrderId,
setRazorPay,
);
}

return (
Expand Down
28 changes: 27 additions & 1 deletion react-fm/src/pages/matchQueues/eventsComponents/RazorPay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
uniqueEventId: string,
objectArray: { waNumber: string; name: string }[],
setAmount: React.Dispatch<React.SetStateAction<number>>,
currency: string,
): Promise<string> =>
// fetch('http://localhost:8080/graphql', {
fetch('https://service.flickmatch.in/platform-0.0.1-SNAPSHOT/graphql', {
Expand All @@ -16,7 +17,8 @@
uniqueEventId: "${uniqueEventId}"
playerInputList: [${objectArray
.map((obj) => `{ waNumber: "${obj.waNumber}", name: "${obj.name}" }`)
.join(',')}]
.join(',')}],
currency : "${currency}"
}
) {
orderId
Expand Down Expand Up @@ -55,12 +57,23 @@
});
}

function removeRazorPayScript() {
const script = document.querySelector(
'script[src="https://checkout.razorpay.com/v1/checkout.js"]',
);
if (script) {
document.body.removeChild(script);
}
}

const displayRazorpay = (
amount: number,
orderId: string,
email: string,
name: string,
phoneNumber: string,
setOrderId: React.Dispatch<React.SetStateAction<string>>,
setRazorPay: React.Dispatch<React.SetStateAction<boolean>>,
) => {
async function displayRazorPay() {
const res = await loadRazorPay();
Expand All @@ -69,6 +82,7 @@
}

const options = {
// key: 'rzp_live_ba3UQjRIBXdeXt', // to be fixed for production
key: 'rzp_live_ba3UQjRIBXdeXt', // to be fixed for production
amount: amount,
currency: 'INR',
Expand All @@ -78,6 +92,7 @@
'https://firebasestorage.googleapis.com/v0/b/flickmatch-374a2.appspot.com/o/fm_rainbow.png?alt=media&token=1b06ae27-bf10-4974-9100-6bb5f2308314',
order_id: orderId,
callback_url: 'https://service.flickmatch.in/platform-0.0.1-SNAPSHOT/processRazorPayment',
// callback_url: 'http://localhost:5173',
redirect: true,
prefill: {
name,
Expand All @@ -88,12 +103,23 @@
address:
'Tower 8 - Flat 1501, Nirvana Country Rd, The Close South, Sector 50, Gurugram, Haryana 122018',
},
modal: {
ondismiss: function () {
// Handle the scenario when the user closes the payment window
// console.log('Payment popup closed');
// Additional cleanup actions can be added here
setRazorPay(false);
setOrderId('');
removeRazorPayScript(); // Clean up Razorpay script
delete _window.Razorpay; // Clean up Razorpay object
},
},
theme: {
color: '#4ce95a',
},
};

const _window = window as any;

Check warning on line 122 in react-fm/src/pages/matchQueues/eventsComponents/RazorPay.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected any. Specify a different type
const paymentObject = new _window.Razorpay(options);
paymentObject.open();
}
Expand Down
Loading