Skip to content

Commit

Permalink
fix: added req headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Srish-ty committed Nov 3, 2024
1 parent 8df0c0c commit f276845
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
29 changes: 27 additions & 2 deletions src/app/payment/payButton.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use client';

import crypto from 'crypto';
import { useState } from 'react';
import { SecondaryButton } from '@/components/shared/Typography/Buttons';

Expand All @@ -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}`,
}),
});
Expand All @@ -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 <button onClick={handlePayment}>Pay with PhonePe</button>;
};

Expand Down
8 changes: 6 additions & 2 deletions src/pages/api/phonepePayment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down

0 comments on commit f276845

Please sign in to comment.