From 1b5eb33859e8ec42728adc881af40cb6bdf6096c Mon Sep 17 00:00:00 2001 From: Benoy Bose Date: Mon, 14 Apr 2025 19:01:14 +0530 Subject: [PATCH] Update index.ts --- functions/src/index.ts | 52 ++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/functions/src/index.ts b/functions/src/index.ts index c6a27de..e0fd7ab 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -534,32 +534,34 @@ export const createCashfreeLink = onRequest({ const linkId = uuidv4(); try { - const options = { - method: 'POST', - headers: { - 'x-client-id': `${clientId}`, - 'x-client-secret': `${clientSecret}`, - 'x-api-version': '2025-01-01', - 'Content-Type': 'application/json' - }, - body: `{ - "link_id": "${linkId}", - "link_amount": ${amount}, - "link_currency": "INR", - "link_purpose": "${productInfo}", - "customer_details": { - "customer_phone": "${customerPhone}", - "customer_email": "${customerEmail}", - "customer_name": "${customerName}"}, - "link_partial_payments": false, - "link_notify": { - "send_sms": true, - "send_email": true - } - }` + const requestHeqaders = { + 'x-client-id': clientId, + 'x-client-secret': clientSecret, + 'x-api-version': '2025-01-01', + 'Content-Type': 'application/json' }; - console.log(`Options ${JSON.stringify(options)}`); - const cashfreeResponse = await axios.post(apiUrl!, options); + console.log(`Header: ${JSON.stringify(requestHeqaders)}`); + const requestBody = { + "link_id": linkId, + "link_amount": amount, + "link_currency": "INR", + "link_purpose": productInfo, + "customer_details": { + "customer_phone": customerPhone, + "customer_email": customerEmail, + "customer_name": customerName, + }, + "link_partial_payments": false, + "link_notify": { + "send_sms": true, + "send_email": true + } + }; + console.log(`Body: ${JSON.stringify(requestBody)}`); + const cashfreeResponse = await axios.post(apiUrl!, requestBody, { + headers: requestHeqaders + }); + try { await admin.firestore().collection('payment_links').doc(orderId).set({ requestUserId: uid,