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 {