I have created an ecommerce based application in MERN stack and backend hosted in AWS EC2 and frontend hosted in Vercel. So my problem is after hosting the backend in AWS EC2 i am seeing that i am unable to make open the payment gateway. What I have guessed that maybe AWS itself is blocking the payment url to access. In my network tab of chrome browser it is showing the 504 gateway timeout
error with strict-origin-when-cross-origin
. But before AWS hosting I also tried the OnRender platform for hosting there it was working fine.
Things I have done in getting the timeout error ---- In AWS I set up the outbound rules in security group to http and https and also there is inbound rules ssh, https, and http. But still i am not able to access the payment gateway. I am using Eazebuzz payment getway.
I am sharing the route and controller
my route is in local perspective http://localhost:5000/api/schemes/:id/initiate_payment
export const initiatePaymentWithEazebuzz = expressAsyncHandler(async (req, res) => {
const response = await GenSchema.findById({ _id: process.env.GEN_CONFIG_CONFIGURATION_ID });
const scheme = await Scheme.findOne({ "schemeData._id": req.params.id }, { "schemeData.$": 1, status: 1, user: 1 });
if (scheme.status !== "active") {
return res.status(400).json({ error: "This Scheme isn't active anymore. You can't make a payment." });
}
const user = await User.findById(scheme.user);
const amount = scheme.schemeData[0].amount.toFixed(2);
const phone = user.mobile_number.slice(3);
const firstname = user.name.split(" ")[0];
const productinfo = scheme.schemeData[0].month_name;
const email = user.email;
const key = response.eazebuzz_merchant_key;
const salt = response.eazebuzz_salt;
// const key = process.env.EASEBUZZ_KEY;
// const salt = process.env.EAZEBUZZ_SALT;
const txnid = crypto.randomBytes(10).toString("hex");
const hashSequence = generateHashForEazeBuzz({ key, txnid, amount, productinfo, firstname, email, salt });
const url = `${process.env.BASE_URL}/payment_result`;
const formData = {
key,
txnid,
amount,
email,
phone,
firstname,
hash: hashSequence,
productinfo,
furl: url,
surl: url,
};
const eazebuzz_env = process.env.EAZEBUZZ_ENV;
const geturl = (env) => {
let url_link;
if (env === "test") {
url_link = "https://testpay.easebuzz.in/";
} else if (env === "prod") {
url_link = "https://pay.easebuzz.in/";
} else {
url_link = "https://testpay.easebuzz.in/";
}
return url_link;
};
let payment_url = geturl(eazebuzz_env);
let call_url = payment_url + "payment/initiateLink";
const options = {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Accept: "application/json",
},
};
try {
const { data } = await axios.post(call_url, formData, options);
if (data.status === 1) {
await Scheme.findOneAndUpdate(
{ "schemeData._id": req.params.id },
{
$set: {
"schemeData.$.txnid": txnid,
},
}
);
return res.json({ access_url: data.data, key, env: eazebuzz_env });
}
} catch (error) {
return res.json({ message: error.message });
}
});
and here is the NGINX sites-availablity config I did if any thing chnage needed to initiate the payment.
server {
listen 80 default_server;
listen [::]:80 default_server;
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name jewellerymine.jewellerskart.in;
ssl_certificate /etc/nginx/ssl/client-certificate.crt;
ssl_certificate_key /etc/nginx/ssl/private-ssl.key;
location /api {
rewrite ^\/api\/(.*)$ /api/$1 break;
proxy_pass http://localhost:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
I have found the solution after some research I found that there are some parameters are required to active the eazebuzz payment gateway which is in my environment variables unfortunately I forgot to send the particular variable to production and I also saw the error coming from cors origin so I added the eazebuzz payment URLs in my cors setup allowed origins and hence the problem solved.