From 07bb77824483e1ea2a749a611df928505170897f Mon Sep 17 00:00:00 2001 From: Benoy Bose Date: Mon, 14 Apr 2025 18:27:16 +0530 Subject: [PATCH 1/5] Added logs --- functions/src/index.ts | 49 ++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/functions/src/index.ts b/functions/src/index.ts index 21f92ae..c6a27de 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -524,6 +524,7 @@ export const createCashfreeLink = onRequest({ const clientId = process.env.CASHFREE_CLIENT_ID; const clientSecret = process.env.CASHFREE_CLIENT_SECRET; let apiUrl = process.env.CASHFREE_LINK_URL; + console.log(`API URL: ${apiUrl}`); if (!clientId || !clientSecret) { logger.error('Cashfree credentials not configured'); @@ -536,42 +537,28 @@ export const createCashfreeLink = onRequest({ const options = { method: 'POST', headers: { + 'x-client-id': `${clientId}`, + 'x-client-secret': `${clientSecret}`, 'x-api-version': '2025-01-01', - 'x-client-id': `${process.env.CASHFREE_CLIENT_ID}`, - 'x-client-secret': `${process.env.CASHFREE_CLIENT_SECRET}`, 'Content-Type': 'application/json' }, body: `{ - "customer_details": { - "customer_email": "${customerEmail}", - "customer_name": "${customerName}", - "customer_phone": "${customerPhone}" - }, - "link_amount": ${amount}, - "link_auto_reminders": true, - "link_currency": "INR", - "link_expiry_time": "${expirationString}", - "link_id": "${linkId}", - "link_meta": { - "notify_url": "https://ee08e626ecd88c61c85f5c69c0418cb5.m.pipedream.net", - "return_url": "https://www.cashfree.com/devstudio/thankyou", - "upi_intent": false - }, - "link_notes": { - "userId": "${userId}", - "gymId": "${gymId}", - "orderId": "${orderId}", - "requestUserId": "${uid}" - }, - "link_notify": { - "send_email": true, - "send_sms": true - }, - "link_partial_payments": false, - "link_purpose": "${productInfo}", - "order_splits": [] - }` + "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(`Options ${JSON.stringify(options)}`); const cashfreeResponse = await axios.post(apiUrl!, options); try { await admin.firestore().collection('payment_links').doc(orderId).set({ From 1b5eb33859e8ec42728adc881af40cb6bdf6096c Mon Sep 17 00:00:00 2001 From: Benoy Bose Date: Mon, 14 Apr 2025 19:01:14 +0530 Subject: [PATCH 2/5] 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, From e2d87fa09593634086a12b049afbcea83803f96a Mon Sep 17 00:00:00 2001 From: Benoy Bose Date: Mon, 14 Apr 2025 23:20:30 +0530 Subject: [PATCH 3/5] Update index.ts --- functions/src/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/functions/src/index.ts b/functions/src/index.ts index e0fd7ab..1eaa594 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -555,6 +555,12 @@ export const createCashfreeLink = onRequest({ "link_notify": { "send_sms": true, "send_email": true + }, + "link_expiry_time": expirationString, + "link_notes": { + "order_id": orderId, + "gym_id": gymId, + "user_id": userId } }; console.log(`Body: ${JSON.stringify(requestBody)}`); From e8cec7e0f4751473be4fd2ab13ba6883b0cad715 Mon Sep 17 00:00:00 2001 From: Benoy Bose Date: Tue, 15 Apr 2025 16:23:15 +0530 Subject: [PATCH 4/5] Added linkQRCode on response --- functions/src/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/functions/src/index.ts b/functions/src/index.ts index 1eaa594..78a31d9 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -589,7 +589,8 @@ export const createCashfreeLink = onRequest({ linkId: linkId, linkUrl: cashfreeResponse.data.link_url, linkExpiryTime: cashfreeResponse.data.link_expiry_time, - linkStatus: cashfreeResponse.data.link_status + linkStatus: cashfreeResponse.data.link_status, + linkQRCode: cashfreeResponse.data.link_qrcode }); } catch (axiosError: any) { From 66ba3b88abdbd5b66496710919dbe1383ecd9056 Mon Sep 17 00:00:00 2001 From: Benoy Bose Date: Tue, 15 Apr 2025 20:04:50 +0530 Subject: [PATCH 5/5] Adding notify_url --- .DS_Store | Bin 0 -> 6148 bytes functions/.env.example | 1 + functions/src/index.ts | 3 +++ 3 files changed, 4 insertions(+) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0