Created
February 28, 2024 13:04
-
-
Save abdus/4ff734ec196c645e66d32e4df63a757c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getPayPageUrl(marchentUserId, amount) { | |
try { | |
const txnId = randomUUID(); | |
const muId = marchentUserId || randomUUID(); | |
const merchantTransactionId = txnId; | |
const data = { | |
merchantId: PHONEPE_MARCHENT_ID, | |
merchantTransactionId: txnId, | |
merchantUserId: muId, | |
// name: req.body.name, | |
amount: amount * 100, | |
// mobileNumber: req.body.number, | |
paymentInstrument: { type: "PAY_PAGE" }, | |
redirectUrl: "https://www.jarurat.care", | |
redirectMode: "REDIRECT", | |
callbackUrl: "https://www.jarurat.care", | |
}; | |
const payload = JSON.stringify(data); | |
const payloadMain = Buffer.from(payload).toString("base64"); | |
const keyIndex = 1; | |
const string = payloadMain + "/pg/v1/pay" + SALT_KEY; | |
const sha256 = createHash("sha256").update(string).digest("hex"); | |
const checksum = sha256 + "###" + SALY_INDEX; | |
const prodURL = "https://api.phonepe.com/apis/hermes/pg/v1/pay"; | |
const options = { | |
method: "POST", | |
url: prodURL, | |
headers: { | |
accept: "application/json", | |
"Content-Type": "application/json", | |
"X-VERIFY": checksum, | |
}, | |
data: { | |
request: payloadMain, | |
}, | |
}; | |
const resp = await fetch(prodURL, { | |
method: "POST", | |
headers: { | |
accept: "application/json", | |
"Content-Type": "application/json", | |
"X-VERIFY": checksum, | |
"X-VERIFY": checksum, | |
"X-VERIFY": checksum, | |
}, | |
body: JSON.stringify({ request: payloadMain }), | |
}); | |
const json = await resp.json(); | |
return json; | |
} catch (err) { | |
console.log(err); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment