Skip to content

Commit 97214f1

Browse files
committed
fix rz[p amount issue
1 parent 11c7dc6 commit 97214f1

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

src/components/CrowdFund/donors.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import AutoSizer from 'react-virtualized-auto-sizer';
55

66
import { AwardIcon } from '../../components/Icons/common';
77
import { CampaignWithFundings } from '../../services/airtable';
8+
import { truncateString } from '../../utils';
89

910
interface Props {
1011
campaign: CampaignWithFundings;
@@ -43,7 +44,9 @@ export const DonorsList: FunctionComponent<Props> = ({ campaign }) => {
4344
<AwardIcon />
4445
</div>
4546
<div className="flex-1">
46-
<h6 className="font-medium text-gray-800">{item.name}</h6>
47+
<h6 className="font-medium text-gray-800" title={item.name}>
48+
{truncateString(item.name, 15)}
49+
</h6>
4750
<p className="text-xs text-gray-600">
4851
{fromnow(new Date(item.created_at), { max: 2, suffix: true })}
4952
</p>

src/components/common/PaymentForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const PaymentForm: FunctionComponent<Props> = ({ campaign, inlineForm = f
7474
setIsSubmitting(true);
7575
await openRzp({
7676
...form,
77-
amount: Number(finalAmount.toFixed(1)),
77+
amount,
7878
campaign: campaign ? campaign.slug : undefined,
7979
});
8080
setIsSubmitting(false);

src/pages/api/rzp.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import cuid from 'cuid';
33
import { NextApiRequest, NextApiResponse } from 'next';
44

55
import { donationsBase, PaymentStatus, fundingsBase } from '../../services/airtable';
6+
import { getFinalAmount } from '../../utils';
67

78
const RZP_KEY = process.env.NODE_ENV === 'development' ? process.env.RZP_TEST_KEY : process.env.RZP_LIVE_KEY;
89

@@ -20,7 +21,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
2021
const { email, name, amount, phone, paymentMethod = 'Razorpay', campaign } = req.body;
2122
const id = cuid();
2223
const data: { id: string; status: PaymentStatus } = await razorpay.orders.create({
23-
amount: amount * 100, // in paise
24+
amount: getFinalAmount(Number(amount)) * 100, // in paise
2425
currency: 'INR',
2526
receipt: id,
2627
payment_capture: true,

src/services/rzp.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { RZP_KEY, DEFAULT_TITLE, DEFAULT_DESCRIPTION, CODERPLEX_LOGO, THEME_COLOR } from '../constants';
22
import { RzpResponse } from '../../types/rzp';
3+
import { getFinalAmount } from '../utils';
34

45
interface RzpData {
56
name: string;
@@ -40,7 +41,7 @@ export async function openRzp(data: RzpData) {
4041
const order = await getOrderId(data);
4142
const options = {
4243
key: RZP_KEY,
43-
amount: amount * 100, // in paisa
44+
amount: getFinalAmount(amount) * 100, // in paisa
4445
order_id: order.id,
4546
name: DEFAULT_TITLE,
4647
description: DEFAULT_DESCRIPTION,

src/utils/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import Router from 'next/router';
33
import { NextPageContext } from 'next';
44

55
export function getFinalAmount(amount: number) {
6-
return Number(amount) * (1 + PROCESSING_CHARGE_PERCENT / 100);
6+
const finalAmount = Number(amount) * (1 + PROCESSING_CHARGE_PERCENT / 100);
7+
return Math.round(finalAmount * 100) / 100;
78
}
89

910
export const redirect = (ctx: NextPageContext, to = '/') => {
@@ -14,3 +15,7 @@ export const redirect = (ctx: NextPageContext, to = '/') => {
1415
}
1516
Router.push(to);
1617
};
18+
19+
export function truncateString(str: string, num: number) {
20+
return str.length > num ? str.slice(0, num) + '...' : str;
21+
}

0 commit comments

Comments
 (0)