Once the reference_id is received:
โ
Store it in your database to track the payment.
โ
Retrieve the payment URL and redirect the customer to complete the payment.
๐ก Example Backend Code (Node.js - Express.js):
const express = require("express");
const axios = require("axios");
const app = express();
app.use(express.json());
const PAYRAM_API_URL = "<http://yourpayramserver.com:8080/api/v1/payment>";
const API_KEY = "ad9db0a5e2e720eaa07a573b4142b51b"; //use your respective api key
app.post("/initiate-payment", async (req, res) => {
try {
const { customerEmail, customerId, amountInUSD } = req.body;
const response = await axios.post(PAYRAM_API_URL, {
customerEmail,
customerId,
amountInUSD
}, {
headers: { "API-Key": API_KEY, "Content-Type": "application/json" }
});
const { reference_id, url } = response.data;
// Store reference_id in database for tracking
console.log("Payment Reference ID:", reference_id);
res.json({ reference_id, url }); // Send payment URL back to the frontend
} catch (error) {
console.error("Error initiating payment:", error);
res.status(500).json({ error: "Failed to generate payment link" });
}
});
app.listen(3000, () => console.log("Server running on port 3000"));