From f276845a68d31098587a1fd1897340f7b92e60df Mon Sep 17 00:00:00 2001 From: Srishty Mangutte Date: Sun, 3 Nov 2024 15:58:33 +0530 Subject: [PATCH 1/4] fix: added req headers --- src/app/payment/payButton.jsx | 29 +++++++++++++++++++++++++++-- src/pages/api/phonepePayment.js | 8 ++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/app/payment/payButton.jsx b/src/app/payment/payButton.jsx index 91965bd..3358f5f 100644 --- a/src/app/payment/payButton.jsx +++ b/src/app/payment/payButton.jsx @@ -1,4 +1,6 @@ 'use client'; + +import crypto from 'crypto'; import { useState } from 'react'; import { SecondaryButton } from '@/components/shared/Typography/Buttons'; @@ -8,8 +10,8 @@ const PayButton = () => { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ - amount: 100, - orderId: 'unique_order_id_12345', + amount: 200, + orderId: Date.now().toString(), callbackUrl: `${window.location.origin}`, }), }); @@ -23,6 +25,29 @@ const PayButton = () => { } }; + // const payload = { + // merchantId: process.env.NEXT_PUBLIC_PHONEPE_MERCHANT_ID, + // amount: 200, + // merchantTransactionId: '45fghrewvty786hjdf', + // redirectUrl: 'http://localhost:3000', + // redirectMode: 'REDIRECT', + // callbackUrl: `http://localhost:3000`, + // paymentInstrument: { + // type: 'PAY_PAGE', + // }, + // }; + + // const payloadString = JSON.stringify(payload); + // const base64Payload = Buffer.from(payloadString).toString('base64'); + + // const checksum = crypto + // .createHmac('sha256', process.env.NEXT_PUBLIC_PHONEPE_API_KEY) + // .update(base64Payload + '/pg/v1/pay' + process.env.NEXT_PUBLIC_PHONEPE_API_KEY) + // .digest('base64'); + + // const x_veri = `${checksum}###${process.env.NEXT_PUBLIC_PHONEPE_API_KEY_INDEX}`; + // console.log(x_veri); + return ; }; diff --git a/src/pages/api/phonepePayment.js b/src/pages/api/phonepePayment.js index 284996e..4552fcd 100644 --- a/src/pages/api/phonepePayment.js +++ b/src/pages/api/phonepePayment.js @@ -6,10 +6,14 @@ export default async function handler(req, res) { const payload = { merchantId: process.env.NEXT_PUBLIC_PHONEPE_MERCHANT_ID, - transactionId: orderId, amount: amount, merchantTransactionId: orderId, redirectUrl: callbackUrl, + redirectMode: 'REDIRECT', + callbackUrl: callbackUrl, + paymentInstrument: { + type: 'PAY_PAGE', + }, }; const payloadString = JSON.stringify(payload); @@ -33,7 +37,7 @@ export default async function handler(req, res) { const data = await response.json(); res.status(200).json(data); } catch (error) { - console.error(error); + console.error('Payment initiation failed:', error); res.status(500).json({ error: 'Payment initiation failed' }); } } else { From 53968d6133959947fe46b629fa6dc0d6a69a1841 Mon Sep 17 00:00:00 2001 From: Srishty Mangutte Date: Mon, 4 Nov 2024 17:51:38 +0530 Subject: [PATCH 2/4] fix: footer links --- src/components/Marginals/Footer/Footer.jsx | 2 +- src/config/content/Footer.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Marginals/Footer/Footer.jsx b/src/components/Marginals/Footer/Footer.jsx index f73f093..2cb6fba 100644 --- a/src/components/Marginals/Footer/Footer.jsx +++ b/src/components/Marginals/Footer/Footer.jsx @@ -87,7 +87,7 @@ export const Footer = () => { {socials.map((item) => (
  • - + Date: Mon, 4 Nov 2024 17:57:43 +0530 Subject: [PATCH 3/4] fix: pay button --- src/app/payment/payButton.jsx | 3 ++- src/app/payment/payment.styles.jsx | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/app/payment/payButton.jsx b/src/app/payment/payButton.jsx index 3358f5f..175821f 100644 --- a/src/app/payment/payButton.jsx +++ b/src/app/payment/payButton.jsx @@ -3,6 +3,7 @@ import crypto from 'crypto'; import { useState } from 'react'; import { SecondaryButton } from '@/components/shared/Typography/Buttons'; +import { PayButtonWrap } from './payment.styles'; const PayButton = () => { const handlePayment = async () => { @@ -48,7 +49,7 @@ const PayButton = () => { // const x_veri = `${checksum}###${process.env.NEXT_PUBLIC_PHONEPE_API_KEY_INDEX}`; // console.log(x_veri); - return ; + return Pay with PhonePe; }; export default PayButton; diff --git a/src/app/payment/payment.styles.jsx b/src/app/payment/payment.styles.jsx index f4a4225..19c0f34 100644 --- a/src/app/payment/payment.styles.jsx +++ b/src/app/payment/payment.styles.jsx @@ -5,3 +5,7 @@ export const PayContainer = styled.div` background-image: url('https://res.cloudinary.com/dhv234qct/image/upload/v1728888341/Inno2k24/yupqoznoucyhxwchhbv7.png'); ${tw`w-full flex flex-col items-center justify-center bg-cover pt-36 `} `; + +export const PayButtonWrap = styled.div` + ${tw`w-full bg-teal-600 px-4 py-3 rounded mx-3 hover:cursor-pointer my-5 flex flex-col items-center justify-center`} +`; From b6b26d495b87bad1e471887f5e955293a7e3d43c Mon Sep 17 00:00:00 2001 From: Srishty Mangutte Date: Tue, 5 Nov 2024 10:17:24 +0530 Subject: [PATCH 4/4] fix: pay button --- src/app/payment/payButton.jsx | 1 + src/app/payment/payment.styles.jsx | 2 +- src/pages/api/phonepePayment.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/payment/payButton.jsx b/src/app/payment/payButton.jsx index 175821f..09d2833 100644 --- a/src/app/payment/payButton.jsx +++ b/src/app/payment/payButton.jsx @@ -23,6 +23,7 @@ const PayButton = () => { window.location.href = data.paymentUrl; } else { alert('Payment failed. Please try again.'); + console.log(data); } }; diff --git a/src/app/payment/payment.styles.jsx b/src/app/payment/payment.styles.jsx index 19c0f34..63f4ba3 100644 --- a/src/app/payment/payment.styles.jsx +++ b/src/app/payment/payment.styles.jsx @@ -7,5 +7,5 @@ export const PayContainer = styled.div` `; export const PayButtonWrap = styled.div` - ${tw`w-full bg-teal-600 px-4 py-3 rounded mx-3 hover:cursor-pointer my-5 flex flex-col items-center justify-center`} + ${tw`w-full bg-teal-600 px-4 py-3 rounded mx-3 hover:cursor-pointer hover:bg-teal-700 my-5 flex flex-col items-center justify-center`} `; diff --git a/src/pages/api/phonepePayment.js b/src/pages/api/phonepePayment.js index 4552fcd..212d6fe 100644 --- a/src/pages/api/phonepePayment.js +++ b/src/pages/api/phonepePayment.js @@ -38,7 +38,7 @@ export default async function handler(req, res) { res.status(200).json(data); } catch (error) { console.error('Payment initiation failed:', error); - res.status(500).json({ error: 'Payment initiation failed' }); + res.status(500).json({ error }); } } else { res.status(405).json({ error: 'Method not allowed' });