phonepe (#26)
All checks were successful
Deploy FitLien services to Dev / Deploy to Dev (push) Successful in 3m44s

Co-authored-by: AllenTJ7 <163137620+AllenTJ7@users.noreply.github.com>
Reviewed-on: #26
This commit is contained in:
Allen T J 2025-05-14 13:09:09 +00:00
parent 5f89a5cda4
commit aee28a6050
2 changed files with 8 additions and 3 deletions

View File

@ -82,7 +82,7 @@ export const registerClient = onRequest({
phoneNumber: formattedPhoneNumber, phoneNumber: formattedPhoneNumber,
}; };
await admin.firestore().collection('client_profile').doc(clientUid).set(clientData); await admin.firestore().collection('client_profiles').doc(clientUid).set(clientData);
return res.status(201).json({ return res.status(201).json({
success: true, success: true,

View File

@ -10,6 +10,13 @@ export const phonePeWebhook = onRequest({
region: '#{SERVICES_RGN}#' region: '#{SERVICES_RGN}#'
}, async (request: Request, response) => { }, async (request: Request, response) => {
try { try {
logger.info('Received webhook request', {
headers: request.headers,
body: request.body,
method: request.method
});
const authHeader = request.headers['authorization'] as string; const authHeader = request.headers['authorization'] as string;
const username = process.env.PHONEPE_WEBHOOK_USERNAME; const username = process.env.PHONEPE_WEBHOOK_USERNAME;
const password = process.env.PHONEPE_WEBHOOK_PASSWORD; const password = process.env.PHONEPE_WEBHOOK_PASSWORD;
@ -20,14 +27,12 @@ export const phonePeWebhook = onRequest({
return; return;
} }
// Calculate expected authorization value
const credentialString = `${username}:${password}`; const credentialString = `${username}:${password}`;
const expectedAuth = crypto const expectedAuth = crypto
.createHash('sha256') .createHash('sha256')
.update(credentialString) .update(credentialString)
.digest('hex'); .digest('hex');
// PhonePe may send the header with a prefix like "SHA256 " or just the hash
const receivedAuth = authHeader.replace(/^SHA256\s+/i, ''); const receivedAuth = authHeader.replace(/^SHA256\s+/i, '');
if (receivedAuth.toLowerCase() !== expectedAuth.toLowerCase()) { if (receivedAuth.toLowerCase() !== expectedAuth.toLowerCase()) {